Skip to content

Commit

Permalink
Wrong status code but correct content should error (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
symm authored Jul 2, 2017
1 parent 9e8133f commit 464aab3
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
12 changes: 8 additions & 4 deletions vape.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ type SmokeTestResult struct {

// Passed determines if the SmokeTest passed successfully
func (result SmokeTestResult) Passed() bool {
if result.Test.Content != "" {
return !result.contentMatched()
if !result.statusCodeMatched() {
return false
}

return result.statusCodeMatched()
if result.Test.Content != "" && !result.contentMatched() {
return false
}

return true
}

func (result SmokeTestResult) statusCodeMatched() bool {
return (result.Test.ExpectedStatusCode == result.ActualStatusCode)
}

func (result SmokeTestResult) contentMatched() bool {
return (strings.Contains(string(result.ActualContent), result.Test.Content) == false)
return (strings.Contains(string(result.ActualContent), result.Test.Content) == true)
}

// SmokeTests is a slice of smoke tests to perform.
Expand Down
73 changes: 73 additions & 0 deletions vape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,79 @@ var test = SmokeTest{
ExpectedStatusCode: 200,
}

func TestSmokeTestResult(t *testing.T) {
t.Run("PassedWhenStatusCodeMatches", func(t *testing.T) {
result := SmokeTestResult{
Test: SmokeTest{
ExpectedStatusCode: 200,
},
ActualStatusCode: 200,
}

if result.Passed() != true {
t.Errorf("expected pass: true, got: %v", result.Passed())
}
})

t.Run("FailedWhenStatusCodeDifferent", func(t *testing.T) {
result := SmokeTestResult{
Test: SmokeTest{
ExpectedStatusCode: 200,
},
ActualStatusCode: 404,
}

if result.Passed() != false {
t.Errorf("expected pass: false, got: %v", result.Passed())
}
})

t.Run("PassedWhenStatusCodeAndContentMatches", func(t *testing.T) {
result := SmokeTestResult{
Test: SmokeTest{
ExpectedStatusCode: 200,
Content: "Hello",
},
ActualStatusCode: 200,
ActualContent: []byte("Hello"),
}

if result.Passed() != true {
t.Errorf("expected pass: true, got: %v", result.Passed())
}
})

t.Run("FailedWhenStatusCodeMatchesButContentDoesnt", func(t *testing.T) {
result := SmokeTestResult{
Test: SmokeTest{
ExpectedStatusCode: 200,
Content: "Hello",
},
ActualStatusCode: 200,
ActualContent: []byte("Goodbye"),
}

if result.Passed() != false {
t.Errorf("expected pass: false, got: %v", result.Passed())
}
})

t.Run("FailedWhenStatusCodeDifferentButContentMatches", func(t *testing.T) {
result := SmokeTestResult{
Test: SmokeTest{
ExpectedStatusCode: 200,
Content: "Hello",
},
ActualStatusCode: 404,
ActualContent: []byte("Hello"),
}

if result.Passed() != false {
t.Errorf("expected pass: false, got: %v", result.Passed())
}
})
}

func TestProcess(t *testing.T) {
resCh, errCh := make(chan SmokeTestResult, 1), make(chan error, 1)
baseURL, err := url.Parse("http://base.url")
Expand Down

0 comments on commit 464aab3

Please sign in to comment.