|
| 1 | +/* |
| 2 | +Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +contributor license agreements. See the NOTICE file distributed with |
| 4 | +this work for additional information regarding copyright ownership. |
| 5 | +The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +(the "License"); you may not use this file except in compliance with |
| 7 | +the License. You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +*/ |
| 17 | + |
| 18 | +package tasks |
| 19 | + |
| 20 | +import ( |
| 21 | + "testing" |
| 22 | + "time" |
| 23 | +) |
| 24 | + |
| 25 | +func Test_buildJQL(t *testing.T) { |
| 26 | + base := time.Date(2021, 2, 3, 4, 5, 6, 7, time.UTC) |
| 27 | + timeAfter := base |
| 28 | + add48 := base.Add(48 * time.Hour) |
| 29 | + minus48 := base.Add(-48 * time.Hour) |
| 30 | + type args struct { |
| 31 | + timeAfter *time.Time |
| 32 | + latestSuccessStart *time.Time |
| 33 | + isIncremental bool |
| 34 | + } |
| 35 | + tests := []struct { |
| 36 | + name string |
| 37 | + args args |
| 38 | + want string |
| 39 | + }{ |
| 40 | + { |
| 41 | + name: "test incremental", |
| 42 | + args: args{ |
| 43 | + timeAfter: nil, |
| 44 | + latestSuccessStart: nil, |
| 45 | + isIncremental: false, |
| 46 | + }, |
| 47 | + want: "ORDER BY created ASC"}, |
| 48 | + { |
| 49 | + name: "test incremental", |
| 50 | + args: args{ |
| 51 | + timeAfter: nil, |
| 52 | + latestSuccessStart: &add48, |
| 53 | + isIncremental: true, |
| 54 | + }, |
| 55 | + want: "updated >= '2021/02/04 04:05' ORDER BY created ASC", |
| 56 | + }, |
| 57 | + { |
| 58 | + name: "test incremental", |
| 59 | + args: args{ |
| 60 | + timeAfter: &base, |
| 61 | + latestSuccessStart: nil, |
| 62 | + isIncremental: false, |
| 63 | + }, |
| 64 | + want: "updated >= '2021/02/03 04:05' ORDER BY created ASC", |
| 65 | + }, |
| 66 | + { |
| 67 | + name: "test incremental", |
| 68 | + args: args{ |
| 69 | + timeAfter: &timeAfter, |
| 70 | + latestSuccessStart: &add48, |
| 71 | + isIncremental: true, |
| 72 | + }, |
| 73 | + want: "updated >= '2021/02/04 04:05' ORDER BY created ASC", |
| 74 | + }, |
| 75 | + { |
| 76 | + name: "test incremental", |
| 77 | + args: args{ |
| 78 | + timeAfter: &timeAfter, |
| 79 | + latestSuccessStart: &minus48, |
| 80 | + isIncremental: true, |
| 81 | + }, |
| 82 | + want: "updated >= '2021/02/03 04:05' ORDER BY created ASC", |
| 83 | + }, |
| 84 | + } |
| 85 | + |
| 86 | + for _, tt := range tests { |
| 87 | + t.Run(tt.name, func(t *testing.T) { |
| 88 | + if got := buildJQL(tt.args.timeAfter, tt.args.latestSuccessStart, tt.args.isIncremental); got != tt.want { |
| 89 | + t.Errorf("buildJQL() = %v, want %v", got, tt.want) |
| 90 | + } |
| 91 | + }) |
| 92 | + } |
| 93 | +} |
0 commit comments