Skip to content

Commit

Permalink
Add unit test for header provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ssmith-pc committed Mar 27, 2024
1 parent 491e12d commit 0150639
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions internal/provider/header_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package provider

import (
"context"
"net/http"
"testing"
)

func TestCustomHeaderIntercept(t *testing.T) {
expectedName := "X-Custom-Header"
expectedValue := "Custom-Value"
header := NewHeaderProvider(expectedName, expectedValue)

req, err := http.NewRequest("GET", "https://example.com", nil)
if err != nil {
t.Fatalf("Failed to create HTTP request: %v", err)
}

ctx := context.Background()

// Call the Intercept method (method being tested)
err = header.Intercept(ctx, req)
if err != nil {
t.Errorf("Intercept failed: %v", err)
}

// Verify that the custom header is set correctly
if req.Header.Get(expectedName) != expectedValue {
t.Errorf("Expected header '%s' to have value '%s', got '%s'", expectedName, expectedValue,
req.Header.Get(expectedName))
}
}

0 comments on commit 0150639

Please sign in to comment.