@@ -16,7 +16,11 @@ package tessera
1616
1717import (
1818 "context"
19+ "strings"
1920 "testing"
21+ "time"
22+
23+ "golang.org/x/mod/sumdb/note"
2024)
2125
2226func TestMemoize (t * testing.T ) {
@@ -54,3 +58,58 @@ func TestMemoize(t *testing.T) {
5458 t .Fatalf ("c(=%d) != d(=%d)" , c .Index , d .Index )
5559 }
5660}
61+
62+ const testSignerKey = "PRIVATE+KEY+example.com/log/testdata+33d7b496+AeymY/SZAX0jZcJ8enZ5FY1Dz+wTML2yWSkK+9DSF3eg"
63+
64+ func TestAppendOptionsValid (t * testing.T ) {
65+ for _ , test := range []struct {
66+ name string
67+ opts * AppendOptions
68+ wantErrContains string
69+ }{
70+ {
71+ name : "Valid" ,
72+ opts : NewAppendOptions ().WithCheckpointSigner (mustCreateSigner (t , testSignerKey )),
73+ }, {
74+ name : "Valid: CheckpointRepublishInterval == CheckpointInterval" ,
75+ opts : NewAppendOptions ().
76+ WithCheckpointSigner (mustCreateSigner (t , testSignerKey )).
77+ WithCheckpointInterval (10 * time .Second ).
78+ WithCheckpointRepublishInterval (10 * time .Second ),
79+ }, {
80+ name : "Error: CheckpointRepublishInterval < CheckpointInterval" ,
81+ opts : NewAppendOptions ().
82+ WithCheckpointSigner (mustCreateSigner (t , testSignerKey )).
83+ WithCheckpointInterval (10 * time .Second ).
84+ WithCheckpointRepublishInterval (9 * time .Second ),
85+ wantErrContains : "WithCheckpointRepublishInterval" ,
86+ }, {
87+ name : "Error: No CheckpointSigner" ,
88+ opts : NewAppendOptions (),
89+ wantErrContains : "WithCheckpointSigner" ,
90+ },
91+ } {
92+ t .Run (test .name , func (t * testing.T ) {
93+ err := test .opts .valid ()
94+ switch gotErr , wantErr := err != nil , test .wantErrContains != "" ; {
95+ case gotErr && ! wantErr :
96+ t .Fatalf ("Got unexpected error %q, want no error" , err )
97+ case ! gotErr && wantErr :
98+ t .Fatalf ("Got no error, expected error" )
99+ case gotErr :
100+ if ! strings .Contains (err .Error (), test .wantErrContains ) {
101+ t .Fatalf ("Got err %q, want error containing %q" , err .Error (), test .wantErrContains )
102+ }
103+ }
104+ })
105+ }
106+ }
107+
108+ func mustCreateSigner (t * testing.T , k string ) note.Signer {
109+ t .Helper ()
110+ s , err := note .NewSigner (k )
111+ if err != nil {
112+ t .Fatalf ("Failed to create signer: %v" , err )
113+ }
114+ return s
115+ }
0 commit comments