|
| 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 | + replapp "github.com/replicatedhq/ship/pkg/specs/replicatedapp" |
| 11 | + "github.com/spf13/viper" |
| 12 | + "github.com/stretchr/testify/require" |
| 13 | +) |
| 14 | + |
| 15 | +func Test_GetReleaseFromSemver(t *testing.T) { |
| 16 | + customerID := "ship-fetch-release-customer-0" |
| 17 | + installationID := "ship-fetch-release-installation-0" |
| 18 | + semver := "1.0.2" |
| 19 | + spec := `assets: |
| 20 | + v1: |
| 21 | + - inline: |
| 22 | + contents: | |
| 23 | + #!/bin/bash |
| 24 | + echo "installing nothing" |
| 25 | + echo "config option: {{repl ConfigOption "test_option" }}" |
| 26 | + dest: ./scripts/install.sh |
| 27 | + mode: 0777 |
| 28 | + - inline: |
| 29 | + contents: | |
| 30 | + #!/bin/bash |
| 31 | + echo "tested nothing" |
| 32 | + echo "customer {{repl Installation "customer_id" }}" |
| 33 | + echo "install {{repl Installation "installation_id" }}" |
| 34 | + dest: ./scripts/test.sh |
| 35 | + mode: 0777 |
| 36 | +config: |
| 37 | + v1: |
| 38 | + - name: test_options |
| 39 | + title: Test Options |
| 40 | + description: testing testing 123 |
| 41 | + items: |
| 42 | + - name: test_option |
| 43 | + title: Test Option |
| 44 | + default: abc123_test-option-value |
| 45 | + type: text |
| 46 | +
|
| 47 | +lifecycle: |
| 48 | + v1: |
| 49 | + - render: {}` |
| 50 | + var test = func() (err error) { |
| 51 | + req := require.New(t) |
| 52 | + |
| 53 | + v := viper.New() |
| 54 | + v.Set("customer-endpoint", fmt.Sprintf("http://localhost:%d/graphql", pact.Server.Port)) |
| 55 | + |
| 56 | + gqlClient, err := replapp.NewGraphqlClient(v, http.DefaultClient) |
| 57 | + req.NoError(err) |
| 58 | + |
| 59 | + selector := replapp.Selector{ |
| 60 | + CustomerID: customerID, |
| 61 | + InstallationID: installationID, |
| 62 | + ReleaseSemver: semver, |
| 63 | + } |
| 64 | + |
| 65 | + _, err = gqlClient.GetRelease(&selector) |
| 66 | + req.NoError(err) |
| 67 | + |
| 68 | + return nil |
| 69 | + } |
| 70 | + |
| 71 | + pact.AddInteraction(). |
| 72 | + Given("A request to get a single app release"). |
| 73 | + UponReceiving("A request to get the amn app release from a semver and customer id"). |
| 74 | + WithRequest(dsl.Request{ |
| 75 | + Method: "POST", |
| 76 | + Path: dsl.String("/graphql"), |
| 77 | + Headers: dsl.MapMatcher{ |
| 78 | + "Authorization": dsl.String(fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", customerID, installationID))))), |
| 79 | + "Content-Type": dsl.String("application/json"), |
| 80 | + }, |
| 81 | + Body: map[string]interface{}{ |
| 82 | + "operationName": "", |
| 83 | + "query": replapp.GetAppspecQuery, |
| 84 | + "variables": map[string]interface{}{ |
| 85 | + "semver": semver, |
| 86 | + }, |
| 87 | + }, |
| 88 | + }). |
| 89 | + WillRespondWith(dsl.Response{ |
| 90 | + Status: 200, |
| 91 | + Body: map[string]interface{}{ |
| 92 | + "data": map[string]interface{}{ |
| 93 | + "shipRelease": map[string]interface{}{ |
| 94 | + "id": dsl.Like(dsl.String("generated")), |
| 95 | + "spec": dsl.Like(dsl.String(spec)), |
| 96 | + }, |
| 97 | + }, |
| 98 | + }, |
| 99 | + }) |
| 100 | + |
| 101 | + if err := pact.Verify(test); err != nil { |
| 102 | + t.Fatalf("Error on Verify: %v", err) |
| 103 | + } |
| 104 | +} |
0 commit comments