github.com/teknogeek/dnscontrol/v2@v2.10.1-0.20200227202244-ae299b55ba42/providers/bind/serial_test.go (about) 1 package bind 2 3 import ( 4 "testing" 5 "time" 6 ) 7 8 func Test_generate_serial_1(t *testing.T) { 9 d1, _ := time.Parse("20060102", "20150108") 10 d4, _ := time.Parse("20060102", "40150108") 11 d12, _ := time.Parse("20060102", "20151231") 12 var tests = []struct { 13 Given uint32 14 Today time.Time 15 Expected uint32 16 }{ 17 {0, d1, 2015010800}, 18 {1, d1, 2015010800}, 19 {123, d1, 2015010800}, 20 {2015010800, d1, 2015010801}, 21 {2015010801, d1, 2015010802}, 22 {2015010802, d1, 2015010803}, 23 {2015010898, d1, 2015010899}, 24 {2015010899, d1, 2015010900}, 25 {2015090401, d1, 2015090402}, 26 {201509040, d1, 2015010800}, 27 {20150904, d1, 2015010800}, 28 {2015090, d1, 2015010800}, 29 // If the number is very large, just increment: 30 {2099000000, d1, 2099000001}, 31 // Verify 32-bits is enough to carry us 200 years in the future: 32 {4015090401, d4, 4015090402}, 33 // Verify Dec 31 edge-case: 34 {2015123099, d12, 2015123100}, 35 {2015123100, d12, 2015123101}, 36 {2015123101, d12, 2015123102}, 37 {2015123102, d12, 2015123103}, 38 {2015123198, d12, 2015123199}, 39 {2015123199, d12, 2015123200}, 40 {2015123200, d12, 2015123201}, 41 {201512310, d12, 2015123100}, 42 } 43 44 for i, tst := range tests { 45 expected := tst.Expected 46 nowFunc = func() time.Time { 47 return tst.Today 48 } 49 found := generateSerial(tst.Given) 50 if expected != found { 51 t.Fatalf("Test:%d/%v: Expected (%d) got (%d)\n", i, tst.Given, expected, found) 52 } 53 } 54 }