...

Source file src/github.com/letsencrypt/boulder/ctpolicy/ctconfig/ctconfig_test.go

Documentation: github.com/letsencrypt/boulder/ctpolicy/ctconfig

     1  package ctconfig
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/jmhodges/clock"
     8  	"github.com/letsencrypt/boulder/test"
     9  )
    10  
    11  func TestTemporalSetup(t *testing.T) {
    12  	for _, tc := range []struct {
    13  		ts  TemporalSet
    14  		err string
    15  	}{
    16  		{
    17  			ts:  TemporalSet{},
    18  			err: "Name cannot be empty",
    19  		},
    20  		{
    21  			ts: TemporalSet{
    22  				Name: "temporal set",
    23  			},
    24  			err: "temporal set contains no shards",
    25  		},
    26  		{
    27  			ts: TemporalSet{
    28  				Name: "temporal set",
    29  				Shards: []LogShard{
    30  					{
    31  						WindowStart: time.Time{},
    32  						WindowEnd:   time.Time{},
    33  					},
    34  				},
    35  			},
    36  			err: "WindowStart must be before WindowEnd",
    37  		},
    38  		{
    39  			ts: TemporalSet{
    40  				Name: "temporal set",
    41  				Shards: []LogShard{
    42  					{
    43  						WindowStart: time.Time{}.Add(time.Hour),
    44  						WindowEnd:   time.Time{},
    45  					},
    46  				},
    47  			},
    48  			err: "WindowStart must be before WindowEnd",
    49  		},
    50  		{
    51  			ts: TemporalSet{
    52  				Name: "temporal set",
    53  				Shards: []LogShard{
    54  					{
    55  						WindowStart: time.Time{},
    56  						WindowEnd:   time.Time{}.Add(time.Hour),
    57  					},
    58  				},
    59  			},
    60  			err: "",
    61  		},
    62  	} {
    63  		err := tc.ts.Setup()
    64  		if err != nil && tc.err != err.Error() {
    65  			t.Errorf("got error %q, wanted %q", err, tc.err)
    66  		} else if err == nil && tc.err != "" {
    67  			t.Errorf("unexpected error %q", err)
    68  		}
    69  	}
    70  }
    71  
    72  func TestLogInfo(t *testing.T) {
    73  	ld := LogDescription{
    74  		URI: "basic-uri",
    75  		Key: "basic-key",
    76  	}
    77  	uri, key, err := ld.Info(time.Time{})
    78  	test.AssertNotError(t, err, "Info failed")
    79  	test.AssertEquals(t, uri, ld.URI)
    80  	test.AssertEquals(t, key, ld.Key)
    81  
    82  	fc := clock.NewFake()
    83  	ld.TemporalSet = &TemporalSet{}
    84  	_, _, err = ld.Info(fc.Now())
    85  	test.AssertError(t, err, "Info should fail with a TemporalSet with no viable shards")
    86  	ld.TemporalSet.Shards = []LogShard{{WindowStart: fc.Now().Add(time.Hour), WindowEnd: fc.Now().Add(time.Hour * 2)}}
    87  	_, _, err = ld.Info(fc.Now())
    88  	test.AssertError(t, err, "Info should fail with a TemporalSet with no viable shards")
    89  
    90  	fc.Add(time.Hour * 4)
    91  	now := fc.Now()
    92  	ld.TemporalSet.Shards = []LogShard{
    93  		{
    94  			WindowStart: now.Add(time.Hour * -4),
    95  			WindowEnd:   now.Add(time.Hour * -2),
    96  			URI:         "a",
    97  			Key:         "a",
    98  		},
    99  		{
   100  			WindowStart: now.Add(time.Hour * -2),
   101  			WindowEnd:   now.Add(time.Hour * 2),
   102  			URI:         "b",
   103  			Key:         "b",
   104  		},
   105  		{
   106  			WindowStart: now.Add(time.Hour * 2),
   107  			WindowEnd:   now.Add(time.Hour * 4),
   108  			URI:         "c",
   109  			Key:         "c",
   110  		},
   111  	}
   112  	uri, key, err = ld.Info(now)
   113  	test.AssertNotError(t, err, "Info failed")
   114  	test.AssertEquals(t, uri, "b")
   115  	test.AssertEquals(t, key, "b")
   116  }
   117  

View as plain text