forked from grafana/cortex-tools
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charlie Le <[email protected]>
- Loading branch information
1 parent
12c679b
commit d2c6ed9
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package httpmiddleware | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestTenantIDRoundTripper_RoundTrip tests the RoundTrip method of TenantIDRoundTripper. | ||
// It creates a new TenantIDRoundTripper with a TenantName and the default http transport as Next. | ||
// It then sends a request and checks if the X-Scope-OrgID header of the request is correctly set to the TenantName. | ||
// It also checks if the status code of the response is OK (200). | ||
func TestTenantIDRoundTripper_RoundTrip(t *testing.T) { | ||
// Create a new TenantIDRoundTripper with a TenantName and the default http transport as Next. | ||
roundTripper := &TenantIDRoundTripper{ | ||
TenantName: "test-tenant", | ||
Next: http.DefaultTransport, | ||
} | ||
|
||
// Create a new request. | ||
req := httptest.NewRequest("GET", "https://example.com", nil) | ||
|
||
// Send the request using the RoundTrip method of the TenantIDRoundTripper. | ||
resp, err := roundTripper.RoundTrip(req) | ||
|
||
// Check if there was an error. | ||
require.NoError(t, err) | ||
|
||
// Check if the status code of the response is OK (200). | ||
require.Equal(t, http.StatusOK, resp.StatusCode) | ||
|
||
// Check if the X-Scope-OrgID header of the request is correctly set to the TenantName. | ||
require.Equal(t, "test-tenant", req.Header.Get("X-Scope-OrgID")) | ||
} |