MCPcopy
hub / github.com/helm/helm / TestHTTPGetter

Function TestHTTPGetter

pkg/getter/httpgetter_test.go:36–152  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34)
35
36func TestHTTPGetter(t *testing.T) {
37 g, err := NewHTTPGetter(WithURL("http://example.com"))
38 if err != nil {
39 t.Fatal(err)
40 }
41
42 if _, ok := g.(*HTTPGetter); !ok {
43 t.Fatal("Expected NewHTTPGetter to produce an *HTTPGetter")
44 }
45
46 cd := "../../testdata"
47 join := filepath.Join
48 ca, pub, priv := join(cd, "rootca.crt"), join(cd, "crt.pem"), join(cd, "key.pem")
49 insecure := false
50 timeout := time.Second * 5
51 transport := &http.Transport{}
52
53 // Test with getterOptions
54 g, err = NewHTTPGetter(
55 WithBasicAuth("I", "Am"),
56 WithPassCredentialsAll(false),
57 WithUserAgent("Groot"),
58 WithTLSClientConfig(pub, priv, ca),
59 WithInsecureSkipVerifyTLS(insecure),
60 WithTimeout(timeout),
61 WithTransport(transport),
62 )
63 if err != nil {
64 t.Fatal(err)
65 }
66
67 hg, ok := g.(*HTTPGetter)
68 if !ok {
69 t.Fatal("expected NewHTTPGetter to produce an *HTTPGetter")
70 }
71
72 if hg.opts.username != "I" {
73 t.Errorf("Expected NewHTTPGetter to contain %q as the username, got %q", "I", hg.opts.username)
74 }
75
76 if hg.opts.password != "Am" {
77 t.Errorf("Expected NewHTTPGetter to contain %q as the password, got %q", "Am", hg.opts.password)
78 }
79
80 if hg.opts.passCredentialsAll != false {
81 t.Errorf("Expected NewHTTPGetter to contain %t as PassCredentialsAll, got %t", false, hg.opts.passCredentialsAll)
82 }
83
84 if hg.opts.userAgent != "Groot" {
85 t.Errorf("Expected NewHTTPGetter to contain %q as the user agent, got %q", "Groot", hg.opts.userAgent)
86 }
87
88 if hg.opts.certFile != pub {
89 t.Errorf("Expected NewHTTPGetter to contain %q as the public key file, got %q", pub, hg.opts.certFile)
90 }
91
92 if hg.opts.keyFile != priv {
93 t.Errorf("Expected NewHTTPGetter to contain %q as the private key file, got %q", priv, hg.opts.keyFile)

Callers

nothing calls this directly

Calls 10

NewHTTPGetterFunction · 0.85
WithURLFunction · 0.85
WithBasicAuthFunction · 0.85
WithUserAgentFunction · 0.85
WithTimeoutFunction · 0.85
WithTransportFunction · 0.85
FatalMethod · 0.80
WithPassCredentialsAllFunction · 0.70
WithTLSClientConfigFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…