This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb7370b
commit d1864ef
Showing
7 changed files
with
185 additions
and
2 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 |
---|---|---|
|
@@ -25,3 +25,5 @@ cmd/ship/overlays | |
|
||
# local circle builds | ||
altconfig.yaml | ||
logs/ | ||
pacts/ |
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,6 @@ | ||
FROM golang:1.12 | ||
|
||
RUN cd /opt && curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/v1.66.0/install.sh | bash | ||
ENV PATH="/opt/pact/bin:${PATH}" | ||
|
||
WORKDIR /go/src/github.com/replicatedhq/ship |
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,104 @@ | ||
package replicatedapp | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/pact-foundation/pact-go/dsl" | ||
replapp "github.com/replicatedhq/ship/pkg/specs/replicatedapp" | ||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_GetReleaseFromSemver(t *testing.T) { | ||
customerID := "ship-fetch-release-customer-0" | ||
installationID := "ship-fetch-release-installation-0" | ||
semver := "1.0.2" | ||
spec := `assets: | ||
v1: | ||
- inline: | ||
contents: | | ||
#!/bin/bash | ||
echo "installing nothing" | ||
echo "config option: {{repl ConfigOption "test_option" }}" | ||
dest: ./scripts/install.sh | ||
mode: 0777 | ||
- inline: | ||
contents: | | ||
#!/bin/bash | ||
echo "tested nothing" | ||
echo "customer {{repl Installation "customer_id" }}" | ||
echo "install {{repl Installation "installation_id" }}" | ||
dest: ./scripts/test.sh | ||
mode: 0777 | ||
config: | ||
v1: | ||
- name: test_options | ||
title: Test Options | ||
description: testing testing 123 | ||
items: | ||
- name: test_option | ||
title: Test Option | ||
default: abc123_test-option-value | ||
type: text | ||
lifecycle: | ||
v1: | ||
- render: {}` | ||
var test = func() (err error) { | ||
req := require.New(t) | ||
|
||
v := viper.New() | ||
v.Set("customer-endpoint", fmt.Sprintf("http://localhost:%d/graphql", pact.Server.Port)) | ||
|
||
gqlClient, err := replapp.NewGraphqlClient(v, http.DefaultClient) | ||
req.NoError(err) | ||
|
||
selector := replapp.Selector{ | ||
CustomerID: customerID, | ||
InstallationID: installationID, | ||
ReleaseSemver: semver, | ||
} | ||
|
||
_, err = gqlClient.GetRelease(&selector) | ||
req.NoError(err) | ||
|
||
return nil | ||
} | ||
|
||
pact.AddInteraction(). | ||
Given("A request to get a single app release"). | ||
UponReceiving("A request to get the amn app release from a semver and customer id"). | ||
WithRequest(dsl.Request{ | ||
Method: "POST", | ||
Path: dsl.String("/graphql"), | ||
Headers: dsl.MapMatcher{ | ||
"Authorization": dsl.String(fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", customerID, installationID))))), | ||
"Content-Type": dsl.String("application/json"), | ||
}, | ||
Body: map[string]interface{}{ | ||
"operationName": "", | ||
"query": replapp.GetAppspecQuery, | ||
"variables": map[string]interface{}{ | ||
"semver": semver, | ||
}, | ||
}, | ||
}). | ||
WillRespondWith(dsl.Response{ | ||
Status: 200, | ||
Body: map[string]interface{}{ | ||
"data": map[string]interface{}{ | ||
"shipRelease": map[string]interface{}{ | ||
"id": dsl.Like(dsl.String("generated")), | ||
"spec": dsl.Like(dsl.String(spec)), | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package replicatedapp | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/pact-foundation/pact-go/dsl" | ||
) | ||
|
||
var ( | ||
pact dsl.Pact | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
pact = createPact() | ||
|
||
pact.Setup(true) | ||
|
||
code := m.Run() | ||
|
||
pact.WritePact() | ||
pact.Teardown() | ||
|
||
os.Exit(code) | ||
} | ||
|
||
func createPact() dsl.Pact { | ||
dir, _ := os.Getwd() | ||
|
||
pactDir := path.Join(dir, "..", "..", "..", "pacts") | ||
logDir := path.Join(dir, "..", "..", "..", "logs") | ||
|
||
return dsl.Pact{ | ||
Consumer: "ship", | ||
Provider: "prem-graphql-api", | ||
LogDir: logDir, | ||
PactDir: pactDir, | ||
LogLevel: "debug", | ||
Host: "0.0.0.0", | ||
} | ||
} |
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