Skip to content

Commit

Permalink
wip: fix native package tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Mar 14, 2021
1 parent a223ae9 commit 3a53945
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion v3/internal/native/mockserver/mock_server_lib.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mockserver

/*
#cgo darwin,amd64 LDFLAGS: -v -L/tmp -L/opt/pact/lib -L/usr/local/lib -Wl,-rpath -Wl,/opt/pact/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_mock_server_ffi
#cgo darwin,amd64 LDFLAGS: -L/tmp -L/opt/pact/lib -L/usr/local/lib -Wl,-rpath -Wl,/opt/pact/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_mock_server_ffi
#cgo windows,amd64 LDFLAGS: -lpact_mock_server_ffi
#cgo linux,amd64 LDFLAGS: -L/tmp -L/opt/pact/lib -L/usr/local/lib -Wl,-rpath -Wl,/opt/pact/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_mock_server_ffi
Expand Down
43 changes: 25 additions & 18 deletions v3/internal/native/mockserver/mock_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,20 @@ var pactComplex = `{
}`

func TestMockServer_CreateAndCleanupMockServer(t *testing.T) {
Init()
port, _ := CreateMockServer(pactComplex, "0.0.0.0:0", false)
defer CleanupMockServer(port)
m := MockServer{}
m.Init()
port, _ := m.CreateMockServer(pactComplex, "0.0.0.0:0", false)
defer m.CleanupMockServer(port)

if port <= 0 {
t.Fatal("want port > 0, got", port)
}
}

func TestMockServer_MismatchesSuccess(t *testing.T) {
port, _ := CreateMockServer(pactSimple, "0.0.0.0:0", false)
defer CleanupMockServer(port)
m := MockServer{}
port, _ := m.CreateMockServer(pactSimple, "0.0.0.0:0", false)
defer m.CleanupMockServer(port)

res, err := http.Get(fmt.Sprintf("http://localhost:%d/foobar", port))
if err != nil {
Expand All @@ -100,32 +102,34 @@ func TestMockServer_MismatchesSuccess(t *testing.T) {
t.Fatalf("want '200', got '%d'", res.StatusCode)
}

mismatches := MockServerMismatchedRequests(port)
mismatches := m.MockServerMismatchedRequests(port)
if len(mismatches) != 0 {
t.Fatalf("want 0 mismatches, got '%d'", len(mismatches))
}
}

func TestMockServer_MismatchesFail(t *testing.T) {
port, _ := CreateMockServer(pactSimple, "0.0.0.0:0", false)
defer CleanupMockServer(port)
m := MockServer{}
port, _ := m.CreateMockServer(pactSimple, "0.0.0.0:0", false)
defer m.CleanupMockServer(port)

mismatches := MockServerMismatchedRequests(port)
mismatches := m.MockServerMismatchedRequests(port)
if len(mismatches) != 1 {
t.Fatalf("want 1 mismatch, got '%d'", len(mismatches))
}
}

func TestMockServer_VerifySuccess(t *testing.T) {
port, _ := CreateMockServer(pactSimple, "0.0.0.0:0", false)
defer CleanupMockServer(port)
m := MockServer{}
port, _ := m.CreateMockServer(pactSimple, "0.0.0.0:0", false)
defer m.CleanupMockServer(port)

_, err := http.Get(fmt.Sprintf("http://localhost:%d/foobar", port))
if err != nil {
t.Fatalf("Error sending request: %v", err)
}

success, mismatches := Verify(port, tmpPactFolder)
success, mismatches := m.Verify(port, tmpPactFolder)
if !success {
t.Fatalf("want 'true' but got '%v'", success)
}
Expand All @@ -136,9 +140,10 @@ func TestMockServer_VerifySuccess(t *testing.T) {
}

func TestMockServer_VerifyFail(t *testing.T) {
port, _ := CreateMockServer(pactSimple, "0.0.0.0:0", false)
m := MockServer{}
port, _ := m.CreateMockServer(pactSimple, "0.0.0.0:0", false)

success, mismatches := Verify(port, tmpPactFolder)
success, mismatches := m.Verify(port, tmpPactFolder)
if success {
t.Fatalf("want 'false' but got '%v'", success)
}
Expand All @@ -149,14 +154,15 @@ func TestMockServer_VerifyFail(t *testing.T) {
}

func TestMockServer_WritePactfile(t *testing.T) {
port, _ := CreateMockServer(pactSimple, "0.0.0.0:0", false)
defer CleanupMockServer(port)
m := MockServer{}
port, _ := m.CreateMockServer(pactSimple, "0.0.0.0:0", false)
defer m.CleanupMockServer(port)

_, err := http.Get(fmt.Sprintf("http://localhost:%d/foobar", port))
if err != nil {
t.Fatalf("Error sending request: %v", err)
}
err = WritePactFile(port, tmpPactFolder)
err = m.WritePactFile(port, tmpPactFolder)

if err != nil {
t.Fatal("error: ", err)
Expand All @@ -170,5 +176,6 @@ func TestMockServer_GetTLSConfig(t *testing.T) {
}

func TestVersion(t *testing.T) {
fmt.Println("version: ", Version())
m := MockServer{}
fmt.Println("version: ", m.Version())
}

0 comments on commit 3a53945

Please sign in to comment.