This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contract-tests: Update according to #2939 suggestions
- Loading branch information
Showing
6 changed files
with
80 additions
and
152 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
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
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
51 changes: 51 additions & 0 deletions
51
test/contracts/consumer/fabric8auth/verify_interactions.go
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,51 @@ | ||
package fabric8auth | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/pact-foundation/pact-go/dsl" | ||
) | ||
|
||
// SimpleGetInteraction executes a simple GET request against Pact Mock server | ||
// to verify the interaction | ||
func SimpleGetInteraction(pact *dsl.Pact, endpoint string) func() error { | ||
var test = func() error { | ||
u := fmt.Sprintf("http://localhost:%d%s", pact.Server.Port, endpoint) | ||
req, err := http.NewRequest("GET", u, nil) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
req.Header.Set("Content-Type", "application/json") | ||
|
||
_, err = http.DefaultClient.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
return err | ||
} | ||
return test | ||
} | ||
|
||
// SimpleGetInteractionWithToken executes a simple GET request (incl. the "Authorization: Bearer <token>" header) | ||
// against Pact Mock server to verify the interaction | ||
func SimpleGetInteractionWithToken(pact *dsl.Pact, endpoint string, authToken string) func() error { | ||
var test = func() error { | ||
u := fmt.Sprintf("http://localhost:%d%s", pact.Server.Port, endpoint) | ||
req, err := http.NewRequest("GET", u, nil) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
req.Header.Set("Content-Type", "application/json") | ||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", authToken)) | ||
|
||
_, err = http.DefaultClient.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
return err | ||
} | ||
return test | ||
} |