Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
add public docker pull test
Browse files Browse the repository at this point in the history
use semver if supplied via cli when getting releases
  • Loading branch information
laverya committed Jun 15, 2018
1 parent 9391f67 commit f6bac2b
Show file tree
Hide file tree
Showing 24 changed files with 174 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
command: docker push replicated/ship:unstable
integration:
docker:
- image: circleci/golang:1.9
- image: circleci/golang:1.10
working_directory: /go/src/github.com/replicatedhq/ship
steps:
- checkout
Expand Down
Empty file removed integration/.gitignore
Empty file.
4 changes: 0 additions & 4 deletions integration/Makefile

This file was deleted.

6 changes: 3 additions & 3 deletions integration/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#Running the integration tests
#Running the integration tests (from the parent directory)

```shell
make integration
make integration-test
```

#Adding a new integration test

Each integration test is a folder containing a text file with the
desired customer ID, a folder 'testfiles' containing
desired customer ID, installation ID, release version, a folder 'testfiles' containing
`.ship/release.yml` and `.ship/state.yml`, and a folder 'expected'
containing the expected output of running ship with that state file, customer ID and release.yml.
1 change: 0 additions & 1 deletion integration/basic-stateless/channel_id

This file was deleted.

1 change: 0 additions & 1 deletion integration/basic/channel_id

This file was deleted.

1 change: 1 addition & 0 deletions integration/docker/customer_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3dEYiuammV8EB4fRq89JtDY18akpzbSC
60 changes: 60 additions & 0 deletions integration/docker/expected/.ship/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

---
# assets are everything an end customer needs to deploy your application, like
#
# - kubernetes or docker-compose manifests
# - installation scripts
# - modules for ansible/chef/puppet
# - private docker images
# - compiled artifacts and binaries
#
# assets will be templated using customer-supplied
# install info from the "config" section (below)
assets:
v1:
# "inline" can be used to supply assets directly in the spec
- 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"
dest: ./scripts/test.sh
mode: 0777
- docker:
image: alpine:3.5
source: public
dest: docker/alpine3-5.tar

# "docker" can be used to provide proxied access to private docker images
# - docker:
# image: postgres
# source: public
# dest: docker/postgres.tar

# Config defines the configuration options available to your application.
# Values supplied by the end customer will be used during asset generation.
config:
v1:
- name: test_options
title: Test Options
description: testing testing 123
items:
- name: test_option
title: Test Option
type: text

# Lifecycle allows you to customize the messaging and workflow for your end customer
# when they are generating assets. Currently the two support lifecycle steps are
#
# - message -- prints a message
# - render -- collects config and generates assets
lifecycle:
v1:
- render: {}

1 change: 1 addition & 0 deletions integration/docker/expected/.ship/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"test_option":"abc123_test-option-value"}
Binary file not shown.
3 changes: 3 additions & 0 deletions integration/docker/expected/installer/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "installing nothing"
echo "config option: abc123_test-option-value"
2 changes: 2 additions & 0 deletions integration/docker/expected/installer/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo "tested nothing"
60 changes: 60 additions & 0 deletions integration/docker/input/.ship/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

---
# assets are everything an end customer needs to deploy your application, like
#
# - kubernetes or docker-compose manifests
# - installation scripts
# - modules for ansible/chef/puppet
# - private docker images
# - compiled artifacts and binaries
#
# assets will be templated using customer-supplied
# install info from the "config" section (below)
assets:
v1:
# "inline" can be used to supply assets directly in the spec
- 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"
dest: ./scripts/test.sh
mode: 0777
- docker:
image: alpine:3.5
source: public
dest: docker/alpine3-5.tar

# "docker" can be used to provide proxied access to private docker images
# - docker:
# image: postgres
# source: public
# dest: docker/postgres.tar

# Config defines the configuration options available to your application.
# Values supplied by the end customer will be used during asset generation.
config:
v1:
- name: test_options
title: Test Options
description: testing testing 123
items:
- name: test_option
title: Test Option
type: text

# Lifecycle allows you to customize the messaging and workflow for your end customer
# when they are generating assets. Currently the two support lifecycle steps are
#
# - message -- prints a message
# - render -- collects config and generates assets
lifecycle:
v1:
- render: {}

1 change: 1 addition & 0 deletions integration/docker/input/.ship/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"test_option":"abc123_test-option-value"}
1 change: 1 addition & 0 deletions integration/docker/installation_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jcmvgHoBCkKPfqM9Qp-iDJCMlDSgyT6L
1 change: 1 addition & 0 deletions integration/docker/release_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.5
60 changes: 23 additions & 37 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,64 +88,51 @@ var _ = Describe("basic", func() {

for _, file := range files {
if file.IsDir() {
Context(fmt.Sprintf("When the spec in %s is run", file.Name()), func() {
Context(fmt.Sprintf("When the spec in %q is run", file.Name()), func() {
testPath := path.Join(integrationDir, file.Name())
testOutputPath := path.Join(testPath, "tmp")
testInputPath := path.Join(testPath, "input")

custIdBytes, err := ioutil.ReadFile(path.Join(testPath, "customer_id"))
if err != nil {
panic(err)
}
customerId := string(custIdBytes)

installationIdBytes, err := ioutil.ReadFile(path.Join(testPath, "installation_id"))
if err != nil {
panic(err)
}
installationId := string(installationIdBytes)

channelIdBytes, err := ioutil.ReadFile(path.Join(testPath, "channel_id"))
if err != nil {
panic(err)
}
channelId := string(channelIdBytes)

releaseVersionBytes, err := ioutil.ReadFile(path.Join(testPath, "release_version"))
if err != nil {
panic(err)
}
releaseVersion := string(releaseVersionBytes)
var customerID, installationID, releaseVersion string

BeforeEach(func() {
//create a temporary directory within this directory to compare files with
// create a temporary directory within this directory to compare files with
os.RemoveAll(testOutputPath)
err := os.Mkdir(testOutputPath, os.ModeDir|os.ModePerm)
if err != nil {
panic(err)
}
Expect(err).NotTo(HaveOccurred())
os.Chdir(testOutputPath)

// read the customer ID, installation ID and release version for this test
custIDBytes, err := ioutil.ReadFile(path.Join(testPath, "customer_id"))
Expect(err).NotTo(HaveOccurred())
customerID = string(custIDBytes)

installationIDBytes, err := ioutil.ReadFile(path.Join(testPath, "installation_id"))
Expect(err).NotTo(HaveOccurred())
installationID = string(installationIDBytes)

releaseVersionBytes, err := ioutil.ReadFile(path.Join(testPath, "release_version"))
Expect(err).NotTo(HaveOccurred())
releaseVersion = string(releaseVersionBytes)
})

AfterEach(func() {
//remove the temporary directory
// remove the temporary directory
err := os.RemoveAll(testOutputPath)
if err != nil {
panic(err)
}
Expect(err).NotTo(HaveOccurred())
os.Chdir(integrationDir)
})

It("Should output files matching those expected when running in local mode", func() {
cmd := cli.RootCmd()
buf := new(bytes.Buffer)
cmd.SetOutput(buf)
cmd.SetArgs(append([]string{
cmd.SetArgs([]string{
"--headless",
fmt.Sprintf("--studio-file=%s", path.Join(testInputPath, ".ship/release.yml")),
fmt.Sprintf("--state-file=%s", path.Join(testInputPath, ".ship/state.json")),
"--log-level=off",
}))
})
err := cmd.Execute()
Expect(err).NotTo(HaveOccurred())

Expand All @@ -165,9 +152,8 @@ var _ = Describe("basic", func() {
fmt.Sprintf("--state-file=%s", path.Join(testInputPath, ".ship/state.json")),
"--customer-endpoint=https://pg.staging.replicated.com/graphql",
"--log-level=off",
fmt.Sprintf("--customer-id=%s", customerId),
fmt.Sprintf("--installation-id=%s", installationId),
fmt.Sprintf("--channel-id=%s", channelId),
fmt.Sprintf("--customer-id=%s", customerID),
fmt.Sprintf("--installation-id=%s", installationID),
fmt.Sprintf("--release-semver=%s", releaseVersion),
}))
err := cmd.Execute()
Expand Down
1 change: 1 addition & 0 deletions pkg/lifecycle/render/config/headless_daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ func TestHeadlessDaemon(t *testing.T) {
manager := &state.Manager{
Logger: testLogger,
FS: fakeFS,
V: viper.New(),
}

resolver := &APIConfigRenderer{
Expand Down
2 changes: 2 additions & 0 deletions pkg/lifecycle/render/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
mockplanner "github.com/replicatedhq/ship/pkg/test-mocks/planner"
ui "github.com/replicatedhq/ship/pkg/test-mocks/ui"
"github.com/spf13/afero"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -56,6 +57,7 @@ func TestRender(t *testing.T) {
renderer.StateManager = &state.Manager{
Logger: renderer.Logger,
FS: mockFS,
V: viper.New(),
}

prog := mockDaemon.EXPECT().SetProgress(ProgressLoad)
Expand Down
5 changes: 1 addition & 4 deletions pkg/lifecycle/render/state/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ func (s Manager) Serialize(assets []api.Asset, meta api.ReleaseMetadata, templat

// TryLoad will attempt to load a state file from disk, if present
func (s *Manager) TryLoad() (map[string]interface{}, error) {
statePath := ""
if s.V != nil {
statePath = s.V.GetString("state-file")
}
statePath := s.V.GetString("state-file")
if statePath == "" {
statePath = Path
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/lifecycle/render/state/serialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/go-kit/kit/log"
"github.com/replicatedhq/ship/pkg/api"
"github.com/spf13/afero"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)

Expand All @@ -29,6 +30,7 @@ func TestTryLoad(t *testing.T) {
state := Manager{
Logger: log.NewNopLogger(),
FS: afero.Afero{Fs: afero.NewMemMapFs()},
V: viper.New(),
}

req := require.New(t)
Expand Down
9 changes: 6 additions & 3 deletions pkg/specs/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
)

const getAppspecQuery = `
query {
shipRelease {
query($semver: String) {
shipRelease (semver: $semver) {
id
channelId
channelName
Expand Down Expand Up @@ -139,9 +139,12 @@ func NewGraphqlClient(v *viper.Viper) (*GraphQLClient, error) {
}

// GetRelease gets a payload from the graphql server
func (c *GraphQLClient) GetRelease(customerID, installationID string) (*ShipRelease, error) {
func (c *GraphQLClient) GetRelease(customerID, installationID, semver string) (*ShipRelease, error) {
requestObj := GraphQLRequest{
Query: getAppspecQuery,
Variables: map[string]string{
"semver": semver,
},
}

ci := callInfo{
Expand Down
6 changes: 3 additions & 3 deletions pkg/specs/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (r *Resolver) ResolveRelease(ctx context.Context, selector Selector) (*api.
return nil, errors.Wrapf(err, "resolve studio spec from %s", r.StudioFile)
}
} else {
release, err = r.resolveCloudRelease(selector.CustomerID, selector.InstallationID)
release, err = r.resolveCloudRelease(selector.CustomerID, selector.InstallationID, selector.ReleaseSemver)
debug.Log("spec.resolve", "spec", specYAML, "err", err)
if err != nil {
return nil, errors.Wrapf(err, "resolve gql spec for %s", selector.CustomerID)
Expand Down Expand Up @@ -116,12 +116,12 @@ func (r *Resolver) resolveStudioRelease() (*ShipRelease, error) {
}, nil
}

func (r *Resolver) resolveCloudRelease(customerID, installationID string) (*ShipRelease, error) {
func (r *Resolver) resolveCloudRelease(customerID, installationID, semver string) (*ShipRelease, error) {
debug := level.Debug(log.With(r.Logger, "method", "resolveCloudSpec"))

client := r.Client
debug.Log("phase", "load-specs", "from", "gql", "addr", client.GQLServer.String())
release, err := client.GetRelease(customerID, installationID)
release, err := client.GetRelease(customerID, installationID, semver)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/specs/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/go-kit/kit/log"
"github.com/replicatedhq/ship/pkg/lifecycle/render/state"
"github.com/spf13/afero"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)

Expand All @@ -16,6 +17,7 @@ func TestPersistSpec(t *testing.T) {
StateManager: &state.Manager{
Logger: log.NewNopLogger(),
FS: afero.Afero{Fs: afero.NewMemMapFs()},
V: viper.New(),
},
}

Expand Down

0 comments on commit f6bac2b

Please sign in to comment.