(t *testing.T)
| 34 | ) |
| 35 | |
| 36 | func 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…