-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bootstrapping pact tests for replicated.app (#4882)
- Loading branch information
Showing
7 changed files
with
148 additions
and
0 deletions.
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
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 |
---|---|---|
|
@@ -15,6 +15,9 @@ bin/ | |
vendor | ||
.idea/ | ||
.vscode/ | ||
pact_logs/ | ||
pacts/ | ||
|
||
|
||
# goreleaser | ||
/dist | ||
|
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
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,37 @@ | ||
package replicated_app | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/pact-foundation/pact-go/dsl" | ||
) | ||
|
||
var ( | ||
pact dsl.Pact | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
dir, _ := os.Getwd() | ||
|
||
pactDir := path.Join(dir, "..", "..", "pacts", "consumer") | ||
logDir := path.Join(dir, "..", "..", "pact_logs") | ||
|
||
pact = dsl.Pact{ | ||
Consumer: "kots", | ||
Provider: "replicated-app", | ||
LogDir: logDir, | ||
PactDir: pactDir, | ||
LogLevel: "debug", | ||
} | ||
|
||
pact.Setup(true) | ||
|
||
code := m.Run() | ||
|
||
pact.WritePact() | ||
pact.Teardown() | ||
|
||
os.Exit(code) | ||
} |
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,41 @@ | ||
package replicated_app | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/pact-foundation/pact-go/dsl" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func Test_CheckConnectivity(t *testing.T) { | ||
var test = func() (err error) { | ||
req, err := http.NewRequest("GET", fmt.Sprintf("http://localhost:%d/", pact.Server.Port), nil) | ||
if err != nil { | ||
return errors.Wrap(err, "create request") | ||
} | ||
|
||
_, err = http.DefaultClient.Do(req) | ||
if err != nil { | ||
return errors.Wrap(err, "execute request") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
pact.AddInteraction(). | ||
Given("Empty state"). | ||
UponReceiving("Check connectivity"). | ||
WithRequest(dsl.Request{ | ||
Method: "GET", | ||
Path: dsl.String("/"), | ||
}). | ||
WillRespondWith(dsl.Response{ | ||
Status: 200, | ||
}) | ||
|
||
if err := pact.Verify(test); err != nil { | ||
t.Fatalf("Error on Verify: %v", err) | ||
} | ||
} |
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
Oops, something went wrong.