-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Look back an actual day instead of one snapshot, as there could be many snapshots from a single day and all of those could still be sync'ing. If there are no snapshots for a month, go back a month and try again Signed-off-by: Appu Goundan <[email protected]>
- Loading branch information
1 parent
1a8918f
commit d3d0b7e
Showing
2 changed files
with
88 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package deb | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestFindSnapshots_noError(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
snapshots [][]byte | ||
targetDate string | ||
want string | ||
}{ | ||
{"earlier than all picks earliest", [][]byte{[]byte("20200101T123456Z"), []byte("20200102T123456Z")}, "20190101T123456Z", "20200101T123456Z"}, | ||
{"exact match", [][]byte{[]byte("20200101T123456Z"), []byte("20200102T123456Z")}, "20200102T123456Z", "20200102T123456Z"}, | ||
{"later than all picks latest", [][]byte{[]byte("20200101T123456Z"), []byte("20200102T123456Z")}, "20200110T123456Z", "20200102T123456Z"}, | ||
{"match day, ignore seconds", [][]byte{[]byte("20200101T123456Z"), []byte("20200102T123456Z")}, "20200102T000000Z", "20200102T123456Z"}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(fmt.Sprintf("%q", tc.name), func(t *testing.T) { | ||
td, err := time.Parse(dateFormat, tc.targetDate) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
got, err := findSnapshot(tc.snapshots, td) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if got != tc.want { | ||
t.Fatalf("got:%v, want:%v", got, tc.want) | ||
} | ||
}) | ||
} | ||
} |