Commit 9be983c1 authored by Erin Krengel's avatar Erin Krengel
Browse files

Some clean up

parent b2a9ddf2
......@@ -17,37 +17,31 @@ image: rocore/base-image:master-7e293e09
test:
stage: test-and-build
image: golang:latest
image: golang:1.13
script:
- go test -race $(go list ./... | grep -v /vendor/)
build-service:
stage: test-and-build
image: docker:19.03.0
services:
- docker:19.03.0-dind
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
CI_REGISTRY_IMAGE: rocore/demo-app
script:
- docker build -t rocore/demo-app:$DOCKER_TAG .
- docker push rocore/demo-app:$DOCKER_TAG
- echo "{\"auths\":{\"https://index.docker.io/v1/\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$DOCKER_TAG
build-acceptance-test:
stage: test-and-build
image: docker:19.03.0
services:
- docker:19.03.0-dind
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
CI_REGISTRY_IMAGE: rocore/demo-app-acceptance
script:
- docker build -t rocore/demo-app-acceptance:${DOCKER_TAG} ./acceptance
- docker push rocore/demo-app-acceptance:${DOCKER_TAG}
- echo "{\"auths\":{\"https://index.docker.io/v1/\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/acceptance/Dockerfile --destination $CI_REGISTRY_IMAGE:$DOCKER_TAG
acceptance-test:
stage: acceptance-test
......@@ -95,16 +89,3 @@ prod-pulumi-up:
- pulumi stack select rocore/demo-app/prod
- pulumi config set DOCKER_TAG $DOCKER_TAG
- pulumi up
prod-pulumi-destroy:
when: manual
stage: prod-pulumi-destroy
only:
- master
before_script:
- gcloud auth activate-service-account $CI_SVC_ACCOUNT_EMAIL --key-file="$GOOGLE_APPLICATION_CREDENTIALS"
script:
- cd infrastructure
- npm install
- pulumi stack select rocore/demo-app/prod
- pulumi destroy
# Example Ephemeral Environment
# Demo App
This demo application illustrates using an ephemeral environment for acceptance testing.
## Application
A simple app that returns a message and sends the message on a PubSub topic. The entire application lives in the `main.go` file.
A simple app that accepts a message, stores it in a bucket and then sends the message on a PubSub topic.
## App Infrastructure
Infrastructure specific to the application that is contained in the `/infrastructure` directory.
Infrastructure specific to the application that is contained in the `/infrastructure` directory. [Pulumi](pulumi.com) is used to manage our infrastructure.
## Acceptance Tests
To run our acceptance tests, we spin up an ephemeral environment. The simple example test is written in Go and contained in the `/acceptance` directory. The test theat when we hit an endpoint we get back a 200 and that the same message is published to the appropriate PubSub topic. The acceptance tests are run as a Kubernetes Job that is defined the `/acceptance/infrastructure` directory.
To run our acceptance tests, we spin up an ephemeral environment. The simple example test is written in Go and contained in the `/acceptance` directory. The acceptance tests are run as a Kubernetes Job that is defined the `/infrastructure/acceptance.ts` file.
The tests check:
* When we hit the `/message` endpoint, we get back the expected status code that the same message is stored in the appropriate bucket as well as published to the appropriate PubSub topic.
* When we hit the `/message` endpoint with an incorrect payload, we get back a 400.
......@@ -21,7 +21,6 @@ import (
)
func TestSimpleHappyPath(t *testing.T) {
project := getConfigurationValue("PROJECT")
serviceIP := getConfigurationValue("SERVICE_IP")
bucketName := getConfigurationValue("BUCKET")
......@@ -100,6 +99,23 @@ func TestSimpleHappyPath(t *testing.T) {
})
}
func TestSimpleSadPath(t *testing.T) {
serviceIP := getConfigurationValue("SERVICE_IP")
bodyBytes, _ := json.Marshal("this wont unmarshal")
t.Run("posting a incorrect message returns 400", func(t *testing.T) {
url := fmt.Sprintf("http://%s/message", serviceIP)
resp, err := http.Post(url, "application/json", bytes.NewBuffer(bodyBytes))
if err != nil {
t.Fatalf("unable to hit endpoint: %v", err)
}
if resp.StatusCode != http.StatusBadRequest {
t.Fatalf("expected a 400 response code, received : %d", resp.StatusCode)
}
})
}
func getConfigurationValue(envVar string) string {
value := os.Getenv(envVar)
if value == "" {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment