...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package gcrane
16
17 import (
18 "context"
19 "net/http"
20 "testing"
21
22 "github.com/google/go-containerregistry/pkg/authn"
23 )
24
25 func TestOptions(t *testing.T) {
26 o := makeOptions()
27 if len(o.remote) != 1 {
28 t.Errorf("remote should default to Keychain")
29 }
30 if len(o.crane) != 1 {
31 t.Errorf("crane should default to Keychain")
32 }
33 if len(o.google) != 1 {
34 t.Errorf("google should default to Keychain")
35 }
36
37 o = makeOptions(WithAuth(authn.Anonymous), WithKeychain(authn.DefaultKeychain))
38 if len(o.remote) != 1 {
39 t.Errorf("WithKeychain should replace remote[0]")
40 }
41 if len(o.crane) != 1 {
42 t.Errorf("WithKeychain should replace crane[0]")
43 }
44 if len(o.google) != 1 {
45 t.Errorf("WithKeychain should replace google[0]")
46 }
47
48 o = makeOptions(WithTransport(http.DefaultTransport), WithUserAgent("hi"), WithContext(context.TODO()))
49 if len(o.remote) != 4 {
50 t.Errorf("wrong number of options: %d", len(o.remote))
51 }
52 if len(o.crane) != 4 {
53 t.Errorf("wrong number of options: %d", len(o.crane))
54 }
55 if len(o.google) != 4 {
56 t.Errorf("wrong number of options: %d", len(o.google))
57 }
58 }
59
View as plain text