-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Header().Has works properly for checking multiple values (#207)
- Loading branch information
Showing
3 changed files
with
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package check | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCheckHas(t *testing.T) { | ||
// Create a Check instance | ||
check := Has("value1", "value2", "value3") | ||
|
||
// Test data | ||
testData := []string{"value1", "value2", "value3"} | ||
|
||
// Call .Check on the instance | ||
checkOutput := check.Check(testData) | ||
|
||
assert.True(t, checkOutput.Success, checkOutput.Reason) | ||
} | ||
|
||
func TestCheckHasFailure(t *testing.T) { | ||
// Create a Check instance | ||
check := Has("value3") | ||
|
||
// Test data | ||
testData := []string{"value1", "value2"} | ||
|
||
// Call .Check on the instance | ||
checkOutput := check.Check(testData) | ||
|
||
assert.False(t, checkOutput.Success, checkOutput.Reason) | ||
} |
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,46 @@ | ||
package test | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHeader(t *testing.T) { | ||
// Manually create a response object with headers | ||
resp := &http.Response{ | ||
Header: http.Header{ | ||
"Access-Control-Allow-Headers": []string{"Content-Type, Range, User-Agent, X-Requested-With"}, | ||
}, | ||
} | ||
|
||
// Extract headers from the response | ||
headers := resp.Header["Access-Control-Allow-Headers"] | ||
|
||
// Test the HeaderBuilder function | ||
hb := Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With") | ||
|
||
checkOutput := hb.Check_.Check(headers) | ||
|
||
// Check if the headers satisfy the conditions | ||
assert.True(t, checkOutput.Success, checkOutput.Reason) | ||
} | ||
|
||
func TestHeaderFailure(t *testing.T) { | ||
resp := &http.Response{ | ||
Header: http.Header{ | ||
// missing X-Requested-With | ||
"Access-Control-Allow-Headers": []string{"Content-Type, Range, User-Agent"}, | ||
}, | ||
} | ||
// Extract headers from the response | ||
headers := resp.Header["Access-Control-Allow-Headers"] | ||
|
||
// Test the HeaderBuilder function | ||
hb := Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With") | ||
|
||
checkOutput := hb.Check_.Check(headers) | ||
|
||
assert.False(t, checkOutput.Success, checkOutput.Reason) | ||
} |
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