|
| 1 | +package replicatedapp |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/base64" |
| 5 | + "fmt" |
| 6 | + "net/http" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/pact-foundation/pact-go/dsl" |
| 10 | + "github.com/spf13/viper" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | + |
| 13 | + replapp "github.com/replicatedhq/ship/pkg/specs/replicatedapp" |
| 14 | +) |
| 15 | + |
| 16 | +func Test_RegisterInstall(t *testing.T) { |
| 17 | + customerID := "ship-register-customer-0" |
| 18 | + installationID := "ship-register-installation-0" |
| 19 | + channelID := "ship-register-channel-0" |
| 20 | + releaseID := "ship-register-release-0" |
| 21 | + var test = func() (err error) { |
| 22 | + req := require.New(t) |
| 23 | + |
| 24 | + v := viper.New() |
| 25 | + v.Set("customer-endpoint", fmt.Sprintf("http://localhost:%d/graphql", pact.Server.Port)) |
| 26 | + |
| 27 | + gqlClient, err := replapp.NewGraphqlClient(v, http.DefaultClient) |
| 28 | + req.NoError(err) |
| 29 | + |
| 30 | + err = gqlClient.RegisterInstall(customerID, installationID, channelID, releaseID) |
| 31 | + req.NoError(err) |
| 32 | + |
| 33 | + return nil |
| 34 | + } |
| 35 | + |
| 36 | + pact.AddInteraction(). |
| 37 | + Given("A request to register an install"). |
| 38 | + UponReceiving("A request to register an install"). |
| 39 | + WithRequest(dsl.Request{ |
| 40 | + Method: "POST", |
| 41 | + Path: dsl.String("/graphql"), |
| 42 | + Headers: dsl.MapMatcher{ |
| 43 | + "Authorization": dsl.String(fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", customerID, installationID))))), |
| 44 | + "Content-Type": dsl.String("application/json"), |
| 45 | + }, |
| 46 | + Body: map[string]interface{}{ |
| 47 | + "operationName": "", |
| 48 | + "query": replapp.RegisterInstallQuery, |
| 49 | + "variables": map[string]interface{}{ |
| 50 | + "channelId": channelID, |
| 51 | + "releaseId": releaseID, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }). |
| 55 | + WillRespondWith(dsl.Response{ |
| 56 | + Status: 200, |
| 57 | + Body: map[string]interface{}{ |
| 58 | + "data": map[string]interface{}{ |
| 59 | + "shipRegisterInstall": dsl.Like(true), |
| 60 | + }, |
| 61 | + }, |
| 62 | + }) |
| 63 | + |
| 64 | + if err := pact.Verify(test); err != nil { |
| 65 | + t.Fatalf("Error on Verify: %v", err) |
| 66 | + } |
| 67 | +} |
0 commit comments