Skip to content

Commit

Permalink
pkg/client/test: add basic auth test
Browse files Browse the repository at this point in the history
we test that previous behavior is not broke and new one works.

Signed-off-by: Mathieu Tortuyaux <[email protected]>
  • Loading branch information
tormath1 committed Oct 27, 2021
1 parent 604b6bc commit 25fecc7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,36 @@ func TestUnlockIfHeld(t *testing.T) {
if h.r.URL.String() != expURL {
t.Fatalf("should have %s for URL, got: %s", expURL, h.r.URL.String())
}

if _, _, ok := h.r.BasicAuth(); ok {
t.Fatalf("basic auth should not be set")
}
}
}

func TestBasicAuth(t *testing.T) {
var (
username = "flatcar"
password = "p4ssw0rd"
)

h := &httpClient{
resp: &http.Response{
StatusCode: 200,
},
}

opts := []client.Option{client.BasicAuth(username, password)}

c, _ := client.New("http://1.2.3.4", "default", "1234", h, opts...)

err := c.RecursiveLock()
if err != nil {
t.Fatalf("should have nil for err, got: %v", err)
}

u, p, ok := h.r.BasicAuth()
if u != username || p != password || !ok {
t.Fatalf("basic auth creds do not match")
}
}

0 comments on commit 25fecc7

Please sign in to comment.