├── tests ├── simple_volume │ ├── test_volume.txt │ └── compose.yaml ├── simple_configfile │ ├── test_config.txt │ └── compose.yaml ├── simple_secretfile │ ├── test_secret.txt │ └── compose.yaml ├── simple_lifecycle │ └── compose.yaml ├── scaling │ └── compose.yaml ├── udp_port │ └── compose.yaml ├── simple_network │ └── compose.yaml └── different_networks │ └── compose.yaml ├── .github ├── CODEOWNERS └── workflows │ └── main.yml ├── golangci.yml ├── commands ├── compose-ref.yml └── docker-compose.yml ├── go.mod ├── scripts └── validate │ ├── template │ ├── bash.txt │ ├── dockerfile.txt │ ├── go.txt │ └── makefile.txt │ └── fileheader ├── client ├── Dockerfile └── main.go ├── server ├── Dockerfile └── main.go ├── ci └── Dockerfile ├── README.md ├── Makefile ├── go.sum ├── CONTRIBUTING.md ├── compliance_test.go ├── CODE_OF_CONDUCT.md ├── tests_helper.go └── LICENSE /tests/simple_volume/test_volume.txt: -------------------------------------------------------------------------------- 1 | MYVOLUME -------------------------------------------------------------------------------- /tests/simple_configfile/test_config.txt: -------------------------------------------------------------------------------- 1 | MYCONFIG -------------------------------------------------------------------------------- /tests/simple_secretfile/test_secret.txt: -------------------------------------------------------------------------------- 1 | MYSECRET -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @ulyssessouza @ndeloof 2 | -------------------------------------------------------------------------------- /tests/simple_lifecycle/compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | test1: 5 | image: composespec/conformance-tests-server 6 | -------------------------------------------------------------------------------- /golangci.yml: -------------------------------------------------------------------------------- 1 | run: 2 | deadline: 2m 3 | 4 | linters: 5 | disable-all: true 6 | enable: 7 | - gofmt 8 | - goimports 9 | - golint 10 | - gosimple 11 | - ineffassign 12 | - misspell 13 | - govet 14 | -------------------------------------------------------------------------------- /commands/compose-ref.yml: -------------------------------------------------------------------------------- 1 | name: "compose-ref" 2 | command: "compose-ref" 3 | ps_command: "docker ps -aq" 4 | global_opts: 5 | - name: "-f" 6 | value: "compose.yaml" 7 | up: 8 | name: "up" 9 | down: 10 | name: "down" 11 | -------------------------------------------------------------------------------- /tests/simple_volume/compose.yaml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | services: 3 | entry: 4 | image: composespec/conformance-tests-server 5 | ports: 6 | - 8080:8080 7 | volumes: 8 | - ./test_volume.txt:/volumes/test_volume.txt 9 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/compose-spec/compatibility-test-suite 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/labstack/echo v3.3.10+incompatible 7 | github.com/labstack/gommon v0.3.0 // indirect 8 | gopkg.in/yaml.v2 v2.2.8 9 | gotest.tools/v3 v3.0.2 10 | ) 11 | -------------------------------------------------------------------------------- /tests/scaling/compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | server: 5 | image: composespec/conformance-tests-server 6 | ports: 7 | - 8080:8080 8 | client: 9 | image: composespec/conformance-tests-client 10 | deploy: 11 | replicas: 3 12 | -------------------------------------------------------------------------------- /tests/udp_port/compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | entry: 5 | image: composespec/conformance-tests-server 6 | ports: 7 | - 8080:8080/tcp 8 | - target: 10001 9 | published: 10001 10 | protocol: udp 11 | mode: host 12 | -------------------------------------------------------------------------------- /commands/docker-compose.yml: -------------------------------------------------------------------------------- 1 | name: "docker-composeV1" 2 | command: "docker-compose" 3 | ps_command: "docker ps -aq" 4 | global_opts: 5 | - name: "--compatibility" 6 | - name: "-f" 7 | value: "compose.yaml" 8 | up: 9 | name: "up" 10 | opts: 11 | - name: "-d" 12 | down: 13 | name: "down" 14 | -------------------------------------------------------------------------------- /tests/simple_configfile/compose.yaml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | services: 3 | entry: 4 | image: composespec/conformance-tests-server 5 | ports: 6 | - 8080:8080 7 | configs: 8 | - source: test_config 9 | target: /volumes/test_config.txt 10 | 11 | configs: 12 | test_config: 13 | file: ./test_config.txt 14 | -------------------------------------------------------------------------------- /tests/simple_secretfile/compose.yaml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | services: 3 | entry: 4 | image: composespec/conformance-tests-server 5 | ports: 6 | - 8080:8080 7 | secrets: 8 | - source: test_secret 9 | target: /volumes/test_secret.txt 10 | 11 | secrets: 12 | test_secret: 13 | file: ./test_secret.txt 14 | -------------------------------------------------------------------------------- /tests/simple_network/compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | entry: 5 | image: composespec/conformance-tests-server 6 | networks: 7 | - mynetwork 8 | ports: 9 | - 8080:8080 10 | target: 11 | image: composespec/conformance-tests-server 12 | networks: 13 | - mynetwork 14 | 15 | networks: 16 | mynetwork: 17 | -------------------------------------------------------------------------------- /tests/different_networks/compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | entry: 5 | image: composespec/conformance-tests-server 6 | networks: 7 | - entrynetwork 8 | ports: 9 | - 8080:8080 10 | target: 11 | image: composespec/conformance-tests-server 12 | networks: 13 | - targetnetwork 14 | 15 | networks: 16 | entrynetwork: 17 | targetnetwork: 18 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - '*' 9 | pull_request: 10 | 11 | jobs: 12 | validate: 13 | name: validate 14 | runs-on: ubuntu-latest 15 | timeout-minutes: 5 16 | steps: 17 | 18 | - name: Checkout 19 | uses: actions/checkout@v2 20 | 21 | - name: Lint code 22 | run: DOCKER_BUILDKIT=1 make lint 23 | 24 | - name: Check code licenses 25 | run: DOCKER_BUILDKIT=1 make check-license 26 | -------------------------------------------------------------------------------- /scripts/validate/template/bash.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Compose Specification Authors. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -------------------------------------------------------------------------------- /scripts/validate/template/dockerfile.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Compose Specification Authors. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -------------------------------------------------------------------------------- /scripts/validate/template/go.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Compose Specification Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | -------------------------------------------------------------------------------- /scripts/validate/template/makefile.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Compose Specification Authors. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -------------------------------------------------------------------------------- /client/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Compose Specification Authors. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | FROM golang:1.14 AS dev 16 | WORKDIR /go/src 17 | COPY . . 18 | RUN go mod init github.com/compose-spec/conformance-tests/client 19 | RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /client . 20 | 21 | FROM scratch AS run 22 | COPY --from=dev client / 23 | ENTRYPOINT ["/client"] 24 | -------------------------------------------------------------------------------- /server/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Compose Specification Authors. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | FROM golang:1.14 AS dev 16 | WORKDIR /go/src 17 | COPY . . 18 | RUN go mod init github.com/compose-spec/conformance-tests/server 19 | RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /server . 20 | 21 | FROM scratch AS run 22 | COPY --from=dev server / 23 | ENTRYPOINT ["/server"] 24 | -------------------------------------------------------------------------------- /scripts/validate/fileheader: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright The Compose Specification Authors. 4 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | set -eu -o pipefail 19 | 20 | if ! command -v ltag; then 21 | >&2 echo "ERROR: ltag not found. Install with:" 22 | >&2 echo " go get -u github.com/kunalkushwaha/ltag" 23 | exit 1 24 | fi 25 | 26 | BASEPATH="${1-}" 27 | 28 | ltag -t "${BASEPATH}scripts/validate/template" --excludes "validate" --check -v 29 | -------------------------------------------------------------------------------- /ci/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Compose Specification Authors. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | FROM golang:1.14 16 | 17 | WORKDIR /go/src 18 | RUN go mod init github.com/compose-spec/conformance-tests 19 | 20 | ARG GOLANGCILINT_VERSION=v1.23.8 21 | RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCILINT_VERSION} 22 | RUN go get -u github.com/kunalkushwaha/ltag 23 | 24 | COPY . /go/src 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Compose specification conformance test suite 2 | ![CI](https://github.com/compose-spec/conformance-tests/workflows/CI/badge.svg) 3 | 4 | This repository contains a test suite for testing Compose implementations to 5 | ensure that they correctly implement the Compose specification. The current 6 | state of the test suite is that it is a work in progress and contributions are 7 | welcome! 8 | 9 | ## Getting started 10 | 11 | By default, the test suite is run against the 12 | [Compose reference implementation](https://github.com/compose-spec/compose-ref) 13 | which uses the Docker Engine. 14 | 15 | ### Prerequisites 16 | 17 | * [Docker](https://docs.docker.com/install/) 18 | * [Go 1.13 or later](https://golang.org) 19 | * [compose-ref](https://github.com/compose-spec/compose-ref) in your PATH 20 | * Ensure that you have no running containers (see 21 | [issue](https://github.com/compose-spec/compatibility-test-suite/issues/5)) 22 | 23 | ### Running the tests 24 | 25 | Using the defaults, you can run the tests as follows: 26 | 27 | ```console 28 | $ make test 29 | ``` 30 | -------------------------------------------------------------------------------- /client/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Compose Specification Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "net/http" 21 | "os" 22 | "time" 23 | ) 24 | 25 | const targetHost = "server" 26 | 27 | func main() { 28 | time.Sleep(time.Second) 29 | value := os.Getenv("HOSTNAME") 30 | resp, err := http.Get("http://" + targetHost + ":8080/scalechecker?value=" + value) 31 | if err != nil { 32 | panic(err) 33 | } 34 | if resp.StatusCode != http.StatusOK { 35 | panic(resp.Status) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Compose Specification Authors. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | PACKAGE=github.com/compose-spec/conformance-tests 16 | IMAGE_PREFIX=composespec/conformance-tests- 17 | 18 | .DEFAULT_GOAL := help 19 | 20 | .PHONY: check 21 | check: ## Checks the environment before running any command 22 | @[[ $(shell docker ps -aq | wc -l) == 0 ]] || \ 23 | (echo "You have to remove any containers before running the tests! Please run 'docker rm -f \`docker ps -aq\`' to remove all the existing containers." && exit 1) 24 | 25 | .PHONY: images 26 | images: ## Build the test images 27 | docker build server -t $(IMAGE_PREFIX)server 28 | docker build client -t $(IMAGE_PREFIX)client 29 | 30 | .PHONY: test 31 | test: check images ## Run tests 32 | GOPRIVATE=$(PACKAGE) go test ./... -v 33 | 34 | .PHONY: fmt 35 | fmt: ## Format go files 36 | @goimports -e -w ./ 37 | 38 | .PHONY: build-validate-image 39 | build-validate-image: 40 | docker build . -f ci/Dockerfile -t $(IMAGE_PREFIX)validate 41 | 42 | .PHONY: lint 43 | lint: build-validate-image 44 | docker run --rm $(IMAGE_PREFIX)validate bash -c "golangci-lint run --config ./golangci.yml ./" 45 | 46 | .PHONY: check-license 47 | check-license: build-validate-image 48 | docker run --rm $(IMAGE_PREFIX)validate bash -c "./scripts/validate/fileheader" 49 | 50 | .PHONY: validate 51 | validate: lint check-license 52 | 53 | .PHONY: help 54 | help: 55 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' 56 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= 4 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 5 | github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg= 6 | github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= 7 | github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0= 8 | github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= 9 | github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= 10 | github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 11 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 12 | github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg= 13 | github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= 14 | github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= 15 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 16 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 17 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 18 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 19 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 20 | github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= 21 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 22 | github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= 23 | github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= 24 | github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8= 25 | github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= 26 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= 27 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 28 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 29 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 30 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 31 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 32 | golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= 33 | golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 34 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 35 | golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 36 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 37 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 38 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 39 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 40 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 41 | gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E= 42 | gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= 43 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions should be made via pull requests. Pull requests will be reviewed 4 | by one or more maintainers and merged when acceptable. 5 | 6 | The goal of the Compose conformance test suite is to exercise Compose 7 | implementations to ensure that they correctly implement the 8 | [specification](https://github.com/compose-spec/compose-spec). 9 | 10 | ## Commit Messages 11 | 12 | Commit messages should follow best practices and explain the context of the 13 | problem and how it was solved-- including any caveats or follow up changes 14 | required. They should tell the story of the change and provide readers an 15 | understanding of what led to it. 16 | 17 | [How to Write a Git Commit Message](http://chris.beams.io/posts/git-commit/) 18 | provides a good guide for how to do so. 19 | 20 | In practice, the best approach to maintaining a nice commit message is to 21 | leverage a `git add -p` and `git commit --amend` to formulate a solid 22 | change set. This allows one to piece together a change, as information becomes 23 | available. 24 | 25 | If you squash a series of commits, don't just submit that. Re-write the commit 26 | message, as if the series of commits was a single stroke of brilliance. 27 | 28 | That said, there is no requirement to have a single commit for a pull request, 29 | as long as each commit tells the story. For example, if there is a feature that 30 | requires a package, it might make sense to have the package in a separate commit 31 | then have a subsequent commit that uses it. 32 | 33 | Remember, you're telling part of the story with the commit message. Don't make 34 | your chapter weird. 35 | 36 | ## Sign your work 37 | 38 | The sign-off is a simple line at the end of the explanation for the patch. Your 39 | signature certifies that you wrote the patch or otherwise have the right to pass 40 | it on as an open-source patch. The rules are pretty simple: if you can certify 41 | the below (from [developercertificate.org](http://developercertificate.org/)): 42 | 43 | ``` 44 | Developer Certificate of Origin 45 | Version 1.1 46 | 47 | Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 48 | 660 York Street, Suite 102, 49 | San Francisco, CA 94110 USA 50 | 51 | Everyone is permitted to copy and distribute verbatim copies of this 52 | license document, but changing it is not allowed. 53 | 54 | Developer's Certificate of Origin 1.1 55 | 56 | By making a contribution to this project, I certify that: 57 | 58 | (a) The contribution was created in whole or in part by me and I 59 | have the right to submit it under the open source license 60 | indicated in the file; or 61 | 62 | (b) The contribution is based upon previous work that, to the best 63 | of my knowledge, is covered under an appropriate open source 64 | license and I have the right under that license to submit that 65 | work with modifications, whether created in whole or in part 66 | by me, under the same open source license (unless I am 67 | permitted to submit under a different license), as indicated 68 | in the file; or 69 | 70 | (c) The contribution was provided directly to me by some other 71 | person who certified (a), (b) or (c) and I have not modified 72 | it. 73 | 74 | (d) I understand and agree that this project and the contribution 75 | are public and that a record of the contribution (including all 76 | personal information I submit with it, including my sign-off) is 77 | maintained indefinitely and may be redistributed consistent with 78 | this project or the open source license(s) involved. 79 | ``` 80 | 81 | Then you just add a line to every git commit message: 82 | 83 | Signed-off-by: Joe Smith 84 | 85 | Use your real name (sorry, no pseudonyms or anonymous contributions.) 86 | 87 | If you set your `user.name` and `user.email` git configs, you can sign your 88 | commit automatically with `git commit -s`. 89 | 90 | -------------------------------------------------------------------------------- /server/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Compose Specification Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "io/ioutil" 23 | "net" 24 | "net/http" 25 | "os" 26 | "path/filepath" 27 | "strconv" 28 | "time" 29 | 30 | "github.com/labstack/echo" 31 | ) 32 | 33 | const ( 34 | defaultHttpPort = 8080 35 | defaultUdpPort = 10001 36 | ) 37 | 38 | func getMapResponse(response string) map[string]string { 39 | return map[string]string{ 40 | "response": response, 41 | } 42 | } 43 | 44 | type Ping struct { 45 | Address string `json:"address"` 46 | } 47 | 48 | func pingHandler(c echo.Context) error { 49 | p := new(Ping) 50 | if err := c.Bind(p); err != nil { 51 | c.Error(err) 52 | return err 53 | } 54 | if p.Address == "" { 55 | return c.JSON( 56 | http.StatusOK, 57 | getMapResponse("PONG FROM TARGET"), 58 | ) 59 | } 60 | resp, err := http.Get(fmt.Sprintf("http://%s", p.Address)) 61 | if err != nil { 62 | return c.JSON( 63 | http.StatusBadRequest, 64 | getMapResponse(fmt.Sprintf("Could not reach address: %s", p.Address)), 65 | ) 66 | } 67 | defer resp.Body.Close() 68 | body, err := ioutil.ReadAll(resp.Body) 69 | if err != nil { 70 | return c.JSON( 71 | http.StatusBadRequest, 72 | getMapResponse(fmt.Sprintf("Could not body from response: %s", err)), 73 | ) 74 | } 75 | return c.String(http.StatusOK, string(body)) 76 | } 77 | 78 | type GetFile struct { 79 | Filename string `json:"filename"` 80 | } 81 | 82 | func fileHandler(c echo.Context) error { 83 | g := new(GetFile) 84 | if err := c.Bind(g); err != nil { 85 | c.Error(err) 86 | return err 87 | } 88 | b, err := ioutil.ReadFile(filepath.Join("/volumes", g.Filename)) 89 | if err != nil { 90 | c.Error(err) 91 | return err 92 | } 93 | return c.JSON( 94 | http.StatusOK, 95 | getMapResponse(string(b)), 96 | ) 97 | } 98 | 99 | var udpValue string 100 | 101 | func udpServer() { 102 | fmt.Println("Running UDP server...") 103 | ServerAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", defaultUdpPort)) 104 | ServerConn, err := net.ListenUDP("udp", ServerAddr) 105 | checkError(err, true) 106 | defer ServerConn.Close() 107 | 108 | var objmap map[string]string 109 | buf := make([]byte, 1024) 110 | for { 111 | n, _, err := ServerConn.ReadFromUDP(buf) 112 | checkError(err, true) 113 | err = json.Unmarshal(buf[:n], &objmap) 114 | checkError(err, true) 115 | udpValue = objmap["request"] 116 | } 117 | } 118 | 119 | func udpHandler(c echo.Context) error { 120 | return c.JSON( 121 | http.StatusOK, 122 | getMapResponse(udpValue), 123 | ) 124 | } 125 | 126 | var scaleValues []string 127 | 128 | type ScaleValue struct { 129 | Value string `json:"value"` 130 | } 131 | 132 | func scaleCheckHandler(c echo.Context) error { 133 | s := new(ScaleValue) 134 | if err := c.Bind(s); err != nil { 135 | c.Error(err) 136 | return err 137 | } 138 | if s.Value != "" && !containsString(scaleValues, s.Value) { 139 | scaleValues = append(scaleValues, s.Value) 140 | } 141 | return c.JSON( 142 | http.StatusOK, 143 | getMapResponse(fmt.Sprintf("%d", len(scaleValues))), 144 | ) 145 | } 146 | 147 | func containsString(ss []string, s string) bool { 148 | for _, v := range ss { 149 | if v == s { 150 | return true 151 | } 152 | } 153 | return false 154 | } 155 | 156 | func checkError(err error, exitOnError bool) { 157 | if err != nil { 158 | fmt.Println("Error: ", err) 159 | if exitOnError { 160 | os.Exit(0) 161 | } 162 | } 163 | } 164 | 165 | func main() { 166 | go udpServer() 167 | 168 | port := defaultHttpPort 169 | httpPort := os.Getenv("HTTP_PORT") 170 | if httpPort != "" { 171 | port, _ = strconv.Atoi(httpPort) 172 | } 173 | e := echo.New() 174 | e.HideBanner = true 175 | s := &http.Server{ 176 | Addr: fmt.Sprintf(":%d", port), 177 | ReadTimeout: 60 * time.Second, 178 | WriteTimeout: 60 * time.Second, 179 | } 180 | e.GET("/ping", pingHandler) 181 | e.GET("/volumefile", fileHandler) 182 | e.GET("/udp", udpHandler) 183 | e.GET("/scalechecker", scaleCheckHandler) 184 | e.Logger.Fatal(e.StartServer(s)) 185 | } 186 | -------------------------------------------------------------------------------- /compliance_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Compose Specification Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "fmt" 21 | "net" 22 | "testing" 23 | "time" 24 | 25 | "gopkg.in/yaml.v2" 26 | ) 27 | 28 | const ( 29 | localhost = "127.0.0.1" 30 | pingEntrypoint = "http://" + localhost + ":8080/ping" 31 | pingTargetURL = "target:8080/ping" 32 | pingURL = pingEntrypoint + "?address=" + pingTargetURL 33 | 34 | volumefileEntrypoint = "http://" + localhost + ":8080/volumefile" 35 | volumeURL = volumefileEntrypoint + "?filename=" 36 | 37 | udpEntrypoint = "http://" + localhost + ":8080/udp" 38 | 39 | scaleEntrypoint = "http://" + localhost + ":8080/scalechecker" 40 | ) 41 | 42 | func TestSimpleLifecycle(t *testing.T) { 43 | h := TestHelper{ 44 | T: t, 45 | testDir: "simple_lifecycle", 46 | } 47 | h.TestUpDown(func() { 48 | time.Sleep(time.Second) 49 | }) 50 | } 51 | 52 | func TestSimpleNetwork(t *testing.T) { 53 | h := TestHelper{ 54 | T: t, 55 | testDir: "simple_network", 56 | specRef: "Networks-top-level-element", 57 | } 58 | h.TestUpDown(func() { 59 | actual := h.getHTTPBody(pingURL) 60 | expected := jsonResponse("PONG FROM TARGET") 61 | h.Check(expected, actual) 62 | }) 63 | } 64 | 65 | func TestSimpleNetworkFail(t *testing.T) { 66 | h := TestHelper{ 67 | T: t, 68 | testDir: "simple_network", 69 | specRef: "Networks-top-level-element", 70 | } 71 | h.TestUpDown(func() { 72 | actual := h.getHTTPBody(pingEntrypoint + "?address=notatarget:8080/ping") 73 | expected := jsonResponse("Could not reach address: notatarget:8080/ping") 74 | h.Check(expected, actual) 75 | }) 76 | } 77 | 78 | func TestDifferentNetworks(t *testing.T) { 79 | h := TestHelper{ 80 | T: t, 81 | testDir: "different_networks", 82 | specRef: "Networks-top-level-element", 83 | } 84 | h.TestUpDown(func() { 85 | actual := h.getHTTPBody(pingURL) 86 | expected := jsonResponse("Could not reach address: target:8080/ping") 87 | h.Check(expected, actual) 88 | }) 89 | } 90 | 91 | func TestVolumeFile(t *testing.T) { 92 | h := TestHelper{ 93 | T: t, 94 | testDir: "simple_volume", 95 | specRef: "volumes-top-level-element", 96 | } 97 | h.TestUpDown(func() { 98 | actual := h.getHTTPBody(volumeURL + "test_volume.txt") 99 | expected := jsonResponse("MYVOLUME") 100 | h.Check(expected, actual) 101 | 102 | }) 103 | } 104 | 105 | func TestSecretFile(t *testing.T) { 106 | h := TestHelper{ 107 | T: t, 108 | testDir: "simple_secretfile", 109 | specRef: "secrets-top-level-element", 110 | } 111 | h.TestUpDown(func() { 112 | actual := h.getHTTPBody(volumeURL + "test_secret.txt") 113 | expected := jsonResponse("MYSECRET") 114 | h.Check(expected, actual) 115 | }) 116 | } 117 | 118 | func TestConfigFile(t *testing.T) { 119 | h := TestHelper{ 120 | T: t, 121 | testDir: "simple_configfile", 122 | skipCommands: []string{"docker-composeV1"}, 123 | specRef: "configs-top-level-element", 124 | } 125 | h.TestUpDown(func() { 126 | actual := h.getHTTPBody(volumeURL + "test_config.txt") 127 | expected := jsonResponse("MYCONFIG") 128 | h.Check(expected, actual) 129 | }) 130 | } 131 | 132 | func TestUdpPort(t *testing.T) { 133 | h := TestHelper{ 134 | T: t, 135 | testDir: "udp_port", 136 | specRef: "Networks-top-level-element", 137 | } 138 | h.TestUpDown(func() { 139 | udpValue := "myUdpvalue" 140 | 141 | ServerAddr, err := net.ResolveUDPAddr("udp", localhost+":10001") 142 | h.NilError(err) 143 | LocalAddr, err := net.ResolveUDPAddr("udp", localhost+":0") 144 | h.NilError(err) 145 | Conn, err := net.DialUDP("udp", LocalAddr, ServerAddr) 146 | h.NilError(err) 147 | defer Conn.Close() 148 | buf := []byte(fmt.Sprintf("{\"request\":%q}", udpValue)) 149 | _, err = Conn.Write(buf) 150 | h.NilError(err) 151 | time.Sleep(time.Second) // Wait for the registration 152 | actual := h.getHTTPBody(udpEntrypoint) 153 | expected := jsonResponse(udpValue) 154 | h.Check(expected, actual) 155 | }) 156 | } 157 | 158 | func TestScaling(t *testing.T) { 159 | h := TestHelper{ 160 | T: t, 161 | testDir: "scaling", 162 | skipCommands: []string{"compose-ref"}, 163 | specRef: "Networks-top-level-element", 164 | } 165 | h.TestUpDown(func() { 166 | time.Sleep(2 * time.Second) // Wait so the clients can register 167 | actual := h.getHTTPBody(scaleEntrypoint) 168 | responseArray := Response{} 169 | err := yaml.Unmarshal([]byte(actual), &responseArray) 170 | h.NilError(err) 171 | h.Check("3", responseArray.Response) 172 | }) 173 | } 174 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders. 63 | All complaints will be reviewed and investigated promptly and fairly. 64 | 65 | All community leaders are obligated to respect the privacy and security of the 66 | reporter of any incident. 67 | 68 | ## Enforcement Guidelines 69 | 70 | Community leaders will follow these Community Impact Guidelines in determining 71 | the consequences for any action they deem in violation of this Code of Conduct: 72 | 73 | ### 1. Correction 74 | 75 | **Community Impact**: Use of inappropriate language or other behavior deemed 76 | unprofessional or unwelcome in the community. 77 | 78 | **Consequence**: A private, written warning from community leaders, providing 79 | clarity around the nature of the violation and an explanation of why the 80 | behavior was inappropriate. A public apology may be requested. 81 | 82 | ### 2. Warning 83 | 84 | **Community Impact**: A violation through a single incident or series 85 | of actions. 86 | 87 | **Consequence**: A warning with consequences for continued behavior. No 88 | interaction with the people involved, including unsolicited interaction with 89 | those enforcing the Code of Conduct, for a specified period of time. This 90 | includes avoiding interactions in community spaces as well as external channels 91 | like social media. Violating these terms may lead to a temporary or 92 | permanent ban. 93 | 94 | ### 3. Temporary Ban 95 | 96 | **Community Impact**: A serious violation of community standards, including 97 | sustained inappropriate behavior. 98 | 99 | **Consequence**: A temporary ban from any sort of interaction or public 100 | communication with the community for a specified period of time. No public or 101 | private interaction with the people involved, including unsolicited interaction 102 | with those enforcing the Code of Conduct, is allowed during this period. 103 | Violating these terms may lead to a permanent ban. 104 | 105 | ### 4. Permanent Ban 106 | 107 | **Community Impact**: Demonstrating a pattern of violation of community 108 | standards, including sustained inappropriate behavior, harassment of an 109 | individual, or aggression toward or disparagement of classes of individuals. 110 | 111 | **Consequence**: A permanent ban from any sort of public interaction within 112 | the community. 113 | 114 | ## Attribution 115 | 116 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 117 | version 2.0, available at 118 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 119 | 120 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 121 | enforcement ladder](https://github.com/mozilla/diversity). 122 | 123 | [homepage]: https://www.contributor-covenant.org 124 | 125 | For answers to common questions about this code of conduct, see the FAQ at 126 | https://www.contributor-covenant.org/faq. Translations are available at 127 | https://www.contributor-covenant.org/translations. 128 | -------------------------------------------------------------------------------- /tests_helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Compose Specification Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "fmt" 21 | "io/ioutil" 22 | "net/http" 23 | "os" 24 | "path/filepath" 25 | "strings" 26 | "testing" 27 | "time" 28 | 29 | "gopkg.in/yaml.v2" 30 | "gotest.tools/v3/assert" 31 | "gotest.tools/v3/icmd" 32 | ) 33 | 34 | const ( 35 | commandsDir = "commands" 36 | baseSpecReference = "https://github.com/compose-spec/compose-spec/blob/master/spec.md" 37 | defaultHealthCheckURL = "http://127.0.0.1:8080/ping" 38 | ) 39 | 40 | type Config struct { 41 | Name string `yaml:"name"` 42 | Command string `yaml:"command"` 43 | PsCommand string `yaml:"ps_command"` 44 | GlobalOpts []Opt `yaml:"global_opts,omitempty"` 45 | Up Verb `yaml:"up,omitempty"` 46 | Down Verb `yaml:"down,omitempty"` 47 | } 48 | 49 | type Verb struct { 50 | Name string `yaml:"name"` 51 | Opts []Opt `yaml:"opts,omitempty"` 52 | } 53 | 54 | type Opt struct { 55 | Name string `yaml:"name"` 56 | Value string `yaml:"value,omitempty"` 57 | } 58 | 59 | type TestHelper struct { 60 | *testing.T 61 | testDir string 62 | skipCommands []string 63 | specRef string 64 | } 65 | 66 | type Response struct { 67 | Response string `yaml:"response"` 68 | } 69 | 70 | func (h TestHelper) TestUpDown(fun func()) { 71 | assert.Assert(h, fun != nil, "Test function cannot be `nil`") 72 | for _, f := range h.listFiles(commandsDir) { 73 | h.Run(f, func(t *testing.T) { 74 | c, err := h.readConfig(filepath.Join(commandsDir, f)) 75 | assert.NilError(t, err) 76 | for _, v := range h.skipCommands { 77 | if v == c.Name { 78 | t.SkipNow() 79 | } 80 | } 81 | h.executeUp(c) 82 | h.waitHTTPReady(defaultHealthCheckURL, 5*time.Second) 83 | fun() 84 | h.executeDown(c) 85 | h.checkCleanUp(c) 86 | }) 87 | } 88 | } 89 | 90 | func (h TestHelper) waitHTTPReady(url string, timeout time.Duration) { 91 | limit := time.Now().Add(timeout) 92 | for limit.After(time.Now()) { 93 | resp, err := http.Get(url) 94 | if err == nil && resp.StatusCode == http.StatusOK { 95 | return 96 | } 97 | } 98 | } 99 | 100 | func (h TestHelper) Check(expected, actual string) { 101 | assert.Check(h.T, expected == actual, h.assertSpecReferenceMessage(expected, actual)) 102 | } 103 | 104 | func (h TestHelper) NilError(e error) { 105 | assert.Check(h.T, e == nil, h.assertSpecReferenceMessage("", fmt.Sprintf("%q", e))) 106 | } 107 | 108 | func (h TestHelper) assertSpecReferenceMessage(expected, actual string) string { 109 | return fmt.Sprintf("\n- expected: %q\n+ actual: %q\n%s", expected, actual, h.specReferenceMessage()) 110 | } 111 | 112 | func (h TestHelper) specReferenceMessage() string { 113 | return "Please refer to: " + h.getSpecReference() 114 | } 115 | 116 | func (h TestHelper) getSpecReference() string { 117 | if h.specRef != "" { 118 | return baseSpecReference + "#" + h.specRef 119 | } 120 | return baseSpecReference 121 | } 122 | 123 | func (h TestHelper) readConfig(configPath string) (*Config, error) { 124 | b, err := ioutil.ReadFile(configPath) 125 | h.NilError(err) 126 | c := Config{} 127 | err = yaml.Unmarshal(b, &c) 128 | h.NilError(err) 129 | return &c, nil 130 | } 131 | 132 | func verbWithOptions(c *Config, v Verb) []string { 133 | var gOpts []string 134 | for _, o := range c.GlobalOpts { 135 | gOpts = append(gOpts, o.Name) 136 | if o.Value != "" { 137 | gOpts = append(gOpts, o.Value) 138 | } 139 | } 140 | vOpts := append(gOpts, v.Name) 141 | for _, o := range v.Opts { 142 | vOpts = append(vOpts, o.Name) 143 | if o.Value != "" { 144 | vOpts = append(vOpts, o.Value) 145 | } 146 | } 147 | return vOpts 148 | } 149 | 150 | func (h TestHelper) executeUp(c *Config) { 151 | upOpts := verbWithOptions(c, c.Up) 152 | h.execCmd(c, upOpts) 153 | } 154 | 155 | func (h TestHelper) executeDown(c *Config) { 156 | downOpts := verbWithOptions(c, c.Down) 157 | h.execCmd(c, downOpts) 158 | } 159 | 160 | func (h TestHelper) execCmd(c *Config, opts []string) { 161 | cmd := icmd.Command(c.Command, opts...) 162 | cmd.Dir = filepath.Join("tests", h.testDir) 163 | icmd.RunCmd(cmd).Assert(h.T, icmd.Success) 164 | } 165 | 166 | func (h TestHelper) listDirs(testDir string) []string { 167 | currDir, err := os.Getwd() 168 | h.NilError(err) 169 | files, err := ioutil.ReadDir(filepath.Join(currDir, testDir)) 170 | h.NilError(err) 171 | var dirs []string 172 | for _, f := range files { 173 | if f.IsDir() && !strings.HasPrefix(f.Name(), ".") { 174 | dirs = append(dirs, f.Name()) 175 | } 176 | } 177 | return dirs 178 | } 179 | 180 | func (h TestHelper) listFiles(dir string) []string { 181 | currDir, err := os.Getwd() 182 | h.NilError(err) 183 | content, err := ioutil.ReadDir(filepath.Join(currDir, dir)) 184 | h.NilError(err) 185 | var configFiles []string 186 | for _, f := range content { 187 | if !f.IsDir() && strings.HasSuffix(f.Name(), ".yml") { 188 | configFiles = append(configFiles, f.Name()) 189 | } 190 | } 191 | return configFiles 192 | } 193 | 194 | func (h TestHelper) checkCleanUp(c *Config) { 195 | command := strings.Split(c.PsCommand, " ") 196 | cmd := icmd.Command(command[0], command[1:]...) 197 | ret := icmd.RunCmd(cmd).Assert(h.T, icmd.Success) 198 | out := strings.Trim(ret.Stdout(), "\n") 199 | nLines := len(strings.Split(out, "\n")) - 1 200 | assert.Check( 201 | h.T, 202 | 0 == nLines, 203 | "Problem checking containers' state. "+ 204 | "There shouldn't be any containers before or after a test.") 205 | } 206 | 207 | func (h TestHelper) getHTTPBody(address string) string { 208 | resp, err := http.Get(address) 209 | h.NilError(err) 210 | defer resp.Body.Close() 211 | body, err := ioutil.ReadAll(resp.Body) 212 | h.NilError(err) 213 | return string(body) 214 | } 215 | 216 | func jsonResponse(content string) string { 217 | return fmt.Sprintf("{\"response\":\"%s\"}\n", content) 218 | } 219 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | --------------------------------------------------------------------------------