...
1
15
16 package pusher
17
18 import (
19 "path/filepath"
20 "testing"
21
22 "helm.sh/helm/v3/pkg/registry"
23 )
24
25 func TestNewOCIPusher(t *testing.T) {
26 p, err := NewOCIPusher()
27 if err != nil {
28 t.Fatal(err)
29 }
30
31 if _, ok := p.(*OCIPusher); !ok {
32 t.Fatal("Expected NewOCIPusher to produce an *OCIPusher")
33 }
34
35 cd := "../../testdata"
36 join := filepath.Join
37 ca, pub, priv := join(cd, "rootca.crt"), join(cd, "crt.pem"), join(cd, "key.pem")
38 insecureSkipTLSverify := false
39 plainHTTP := false
40
41
42 p, err = NewOCIPusher(
43 WithTLSClientConfig(pub, priv, ca),
44 WithInsecureSkipTLSVerify(insecureSkipTLSverify),
45 WithPlainHTTP(plainHTTP),
46 )
47 if err != nil {
48 t.Fatal(err)
49 }
50
51 op, ok := p.(*OCIPusher)
52 if !ok {
53 t.Fatal("Expected NewOCIPusher to produce an *OCIPusher")
54 }
55
56 if op.opts.certFile != pub {
57 t.Errorf("Expected NewOCIPusher to contain %q as the public key file, got %q", pub, op.opts.certFile)
58 }
59
60 if op.opts.keyFile != priv {
61 t.Errorf("Expected NewOCIPusher to contain %q as the private key file, got %q", priv, op.opts.keyFile)
62 }
63
64 if op.opts.caFile != ca {
65 t.Errorf("Expected NewOCIPusher to contain %q as the CA file, got %q", ca, op.opts.caFile)
66 }
67
68 if op.opts.plainHTTP != plainHTTP {
69 t.Errorf("Expected NewOCIPusher to have plainHTTP as %t, got %t", plainHTTP, op.opts.plainHTTP)
70 }
71
72 if op.opts.insecureSkipTLSverify != insecureSkipTLSverify {
73 t.Errorf("Expected NewOCIPusher to have insecureSkipVerifyTLS as %t, got %t", insecureSkipTLSverify, op.opts.insecureSkipTLSverify)
74 }
75
76
77 registryClient, err := registry.NewClient()
78 if err != nil {
79 t.Fatal(err)
80 }
81
82 p, err = NewOCIPusher(
83 WithRegistryClient(registryClient),
84 )
85 if err != nil {
86 t.Fatal(err)
87 }
88 op, ok = p.(*OCIPusher)
89 if !ok {
90 t.Fatal("expected NewOCIPusher to produce an *OCIPusher")
91 }
92
93 if op.opts.registryClient != registryClient {
94 t.Errorf("Expected NewOCIPusher to contain %p as RegistryClient, got %p", registryClient, op.opts.registryClient)
95 }
96 }
97
View as plain text