Skip to content

Commit

Permalink
test: add expected failure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed May 16, 2024
1 parent b7c6255 commit d8b6767
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tooling/check/check_has_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ func TestCheckHas(t *testing.T) {

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)
}
18 changes: 18 additions & 0 deletions tooling/test/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,21 @@ func TestHeader(t *testing.T) {
// 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)
}

0 comments on commit d8b6767

Please sign in to comment.