github.com/philhug/dnscontrol@v0.2.4-0.20180625181521-921fa9849001/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, 2015010801},
    18  		{123, d1, 2015010801},
    19  		{2015010800, d1, 2015010801},
    20  		{2015010801, d1, 2015010802},
    21  		{2015010802, d1, 2015010803},
    22  		{2015010898, d1, 2015010899},
    23  		{2015010899, d1, 2015010900},
    24  		{2015090401, d1, 2015090402},
    25  		{201509040, d1, 2015010801},
    26  		{20150904, d1, 2015010801},
    27  		{2015090, d1, 2015010801},
    28  		// Verify 32-bits is enough to carry us 200 years in the future:
    29  		{4015090401, d4, 4015090402},
    30  		// Verify Dec 31 edge-case:
    31  		{2015123099, d12, 2015123101},
    32  		{2015123100, d12, 2015123101},
    33  		{2015123101, d12, 2015123102},
    34  		{2015123102, d12, 2015123103},
    35  		{2015123198, d12, 2015123199},
    36  		{2015123199, d12, 2015123200},
    37  		{2015123200, d12, 2015123201},
    38  		{201512310, d12, 2015123101},
    39  	}
    40  
    41  	for i, tst := range tests {
    42  		expected := tst.Expected
    43  		nowFunc = func() time.Time {
    44  			return tst.Today
    45  		}
    46  		found := generateSerial(tst.Given)
    47  		if expected != found {
    48  			t.Fatalf("Test:%d/%v: Expected (%d) got (%d)\n", i, tst.Given, expected, found)
    49  		}
    50  	}
    51  }