Skip to content

Commit 5712aff

Browse files
committed
test: add tests for token-exchanger, now functional
Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com>
1 parent 0737d5b commit 5712aff

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

internal/emlb/token-exchanger_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ import (
2727

2828
func TestTokenExchanger_Token(t *testing.T) {
2929
// Create a mock server to handle the token exchange request
30-
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
31-
// Return a sample token response
32-
response := `{"access_token": "sample_token", "expires_in": 3600}`
33-
w.WriteHeader(http.StatusOK)
34-
w.Write([]byte(response))
30+
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
31+
// Set content type
32+
w.Header().Set("Content-Type", "application/json")
33+
// Write out oauth2 json response
34+
_, err := w.Write([]byte(`{
35+
"access_token": "sample_token",
36+
"token_type": "Bearer",
37+
"expires_in": 3600
38+
}`))
39+
if err != nil {
40+
t.Fatalf("failed to write json response, err = %v", err)
41+
}
3542
}))
3643
defer mockServer.Close()
3744

0 commit comments

Comments
 (0)