-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aaron Parfitt
authored
Mar 12, 2023
1 parent
7b89e5f
commit 7a6a858
Showing
3 changed files
with
110 additions
and
54 deletions.
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 frontman | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
|
||
func TestCreateRedirectServer(t *testing.T) { | ||
redirectAddr := "0.0.0.0:8000" | ||
redirectServer := createRedirectServer("0.0.0.0:80", redirectAddr) | ||
|
||
// Create a test request to the redirect server | ||
req, err := http.NewRequest("GET", "http://example.com/foo", nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Create a test response recorder | ||
rr := httptest.NewRecorder() | ||
|
||
// Call the redirect server's handler function | ||
redirectServer.Handler.ServeHTTP(rr, req) | ||
|
||
// Check that the response has a 301 status code | ||
if status := rr.Code; status != http.StatusMovedPermanently { | ||
t.Errorf("Unexpected status code: got %v, expected %v", status, http.StatusMovedPermanently) | ||
} | ||
|
||
// Check that the response includes a "Location" header with the expected value | ||
expectedURL := "https://example.com/foo" | ||
if location := rr.Header().Get("Location"); location != expectedURL { | ||
t.Errorf("Unexpected Location header value: got %v, expected %v", location, expectedURL) | ||
} | ||
} |