Skip to content

Commit

Permalink
Http response matchers
Browse files Browse the repository at this point in the history
Change-Id: Ide526ab99ee362f52359c80e31fa3541ad4ae849
  • Loading branch information
Alexander Andryashin committed Jul 27, 2016
1 parent 052eb0d commit 4866c89
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions httpresp/httpresp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package httpresp

import (
"fmt"
"net/http"
)

type Code struct {
C int
}

func (m Code) Match(i interface{}) bool {
return i.(*http.Response).StatusCode == m.C
}

func (m Code) String() string {
return fmt.Sprintf("response code %v", m.C)
}
12 changes: 12 additions & 0 deletions httpresp/httpresp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package httpresp

import (
"net/http"
"testing"
. "github.com/aandryashin/matchers"
)

func TestTypeOf(t *testing.T) {
AssertThat(t, &http.Response{StatusCode: 200}, Code{http.StatusOK})
AssertThat(t, Expect{&http.Response{StatusCode: 500}, Code{http.StatusOK}}, Fails{})
}

0 comments on commit 4866c89

Please sign in to comment.