diff --git a/.dockerignore b/.dockerignore index f6906185ff..4a7598c925 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,4 @@ docker-machine* -.git +*.log +bin +cover \ No newline at end of file diff --git a/.gitignore b/.gitignore index dd625076a9..cd3ab170c1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ docker-machine* *.log *.iml .idea/ +bin +cover \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 170ebc1dc5..26659ef606 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,13 @@ language: go -sudo: false go: -- 1.4.2 - 1.5 install: -- export GOPATH=${TRAVIS_BUILD_DIR}/Godeps/_workspace:$GOPATH -- export PATH=${TRAVIS_BUILD_DIR}/Godeps/_workspace/bin:$PATH -- go get -t -v ./... -- go get golang.org/x/tools/cmd/cover +- go get github.com/mattn/goveralls script: -- script/validate-dco -- script/validate-gofmt -- go test -v -short ./... -- script/generate-coverage report +- make dco +- make fmt +# - make lint +# - make vet +- make test-short +- make test-long +- make coverage-send diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 49a323ba21..923be4286c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,6 +2,7 @@ [![GoDoc](https://godoc.org/github.com/docker/machine?status.png)](https://godoc.org/github.com/docker/machine) [![Build Status](https://travis-ci.org/docker/machine.svg?branch=master)](https://travis-ci.org/docker/machine) +[![Coverage Status](https://coveralls.io/repos/docker/machine/badge.svg?branch=upstream-master&service=github)](https://coveralls.io/github/docker/machine?branch=upstream-master) Want to hack on Machine? Awesome! Here are instructions to get you started. @@ -13,108 +14,139 @@ Docker does things, you'll feel right at home. Otherwise, please read [Docker's contributions guidelines](https://github.com/docker/docker/blob/master/CONTRIBUTING.md). -# Building +# Building using docker The requirements to build Machine are: -1. A running instance of Docker +1. A running instance of Docker (or alternatively a golang 1.5 development environment) 2. The `bash` shell 3. [Make](https://www.gnu.org/software/make/) -To build, run: +Call `export USE_CONTAINER=true` to instruct the build system to use containers to build. +If you want to build natively using golang instead, don't set this variable. + +## Building + +To build the docker-machine binary, simply run: $ make -From the Machine repository's root. Machine will run the build inside of a -Docker container and the compiled binaries will appear in the project directory -on the host. +From the Machine repository's root. You will now find a `docker-machine` +binary at the root of the project. -By default, Machine will run a build which cross-compiles binaries for a variety -of architectures and operating systems. If you know that you are only compiling -for a particular architecture and/or operating system, you can speed up the -compile by setting the standard `GOOS` and/or `GOARCH` environment variables to -deviate from the defaults. +You may call: -For instance, if you only want to compile for use on OS X with the x86_64 arch, -run: + $ make clean - $ GOOS=darwin GOARCH=amd64 make +to clean-up build results. -If you have any questions we're in #docker-machine on Freenode. +## Tests and validation -## Remote Build +To run basic validation (dco, fmt), and the project unit tests, call: -You can use Machine to build Machine: + $ make test - $ GOOS=darwin GOARCH=amd64 make remote +If you want more indepth validation (vet, lint), and all tests with race detection, call: -The difference is this works even if you don't have local docker daemon, but -instead a docker host that you [set up using Machine](https://github.com/docker/machine). - -## Unit Tests - -To run the unit tests for the whole project, using the following script: - - $ script/test - -This will run the unit tests inside of a container, so you don't have to worry -about configuring your environment properly before doing so. - -To run the unit tests for only a specific subdirectory of the project, you can -pass an argument to that script to specify which directory, e.g.: - - $ script/test ./drivers/amazonec2 + $ make validate If you make a pull request, it is highly encouraged that you submit tests for the code that you have added or modified in the same pull request. ## Code Coverage -Machine includes a script to check for missing `*_test.go` files and to generate -an [HTML-based representation of which code is covered by tests](http://blog.golang.org/cover#TOC_5.). +To generate an html code coverage report of the Machine codebase, run: -To run the code coverage script, execute: + make coverage-serve -```console -$ ./script/coverage serve -``` +And navigate to http://localhost:8000 (hit `CTRL+C` to stop the server). -You will see the results of the code coverage check as they come in. +Alternatively, if you are building natively, you can simply run: -This will also generate the code coverage website and serve it from a container -on port 8000. By default, `/` will show you the source files from the base -directory, and you can navigate to the coverage for any particular subdirectory -of the Docker Machine repo's root by going to that path. For instance, to see -the coverage for the VirtualBox driver's package, browse to `/drivers/virtualbox`. + make coverage-html + +This will generate and open the report file: ![](/docs/img/coverage.png) -You can hit `CTRL+C` to stop the server. +## List of all targets + +### High-level targets + + make clean + make build + make test + make validate + +### Build targets + +Build a single, native machine binary: + + make build-simple + +Build for all supported oses and architectures (binaries will be in the `bin` project subfolder): + + make build-x + +Build for a specific list of oses and architectures: + + TARGET_OS=linux TARGET_ARCH="amd64 arm" make build-x + +You can further control build options through the following environment variables: + + DEBUG=true # enable debug build + STATIC=true # build static (note: when cross-compiling, the build is always static) + VERBOSE=true # verbose output + PARALLEL=X # lets you control build parallelism when cross-compiling multiple builds + PREFIX=folder + +Scrub build results: + + make build-clean + +### Coverage targets + + make coverage-html + make coverage-serve + make coverage-send + make coverage-generate + make coverage-clean + +### Tests targets + + make test-short + make test-long + make test-integration + +### Validation targets + + make fmt + make vet + make lint + make dco ## Integration Tests ### Setup -We utilize [BATS](https://github.com/sstephenson/bats) for integration testing. -This runs tests against the generated binary. To use, first make sure to -[install BATS](https://github.com/sstephenson/bats). Then run `./script/build` -to generate the binary for your system. +We use [BATS](https://github.com/sstephenson/bats) for integration testing, so, +first make sure to [install it](https://github.com/sstephenson/bats#installing-bats-from-source). ### Basic Usage -Once you have the binary, the integration tests can be invoked using the -`test/integration/run-bats.sh` wrapper script. +Integration tests can be invoked calling `make test-integration`. -Using this wrapper script, you can invoke a test or subset of tests for a -particular driver. To set the driver, use the `DRIVER` environment variable. +:warn: you cannot run integration test inside a container for now. +Be sure to unset the `USE_CONTAINER` env variable if you set it earlier, or alternatively +call directly `./test/integration/run-bats.sh` instead of `make test-integration`. -The following examples are all shown relative to the project's root directory, -but you should be able to invoke them from any directory without issue. +You can invoke a test or subset of tests for a particular driver. +To set the driver, use the `DRIVER` environment variable. To invoke just one test: ```console -$ DRIVER=virtualbox ./test/integration/run-bats.sh test/integration/core/core-commands.bats +$ DRIVER=virtualbox make test-integration test/integration/core/core-commands.bats ✓ virtualbox: machine should not exist ✓ virtualbox: create ✓ virtualbox: ls @@ -141,23 +173,17 @@ Successfully removed bats-virtualbox-test To invoke a shared test with a different driver: ```console -$ DRIVER=digitalocean ./test/integration/run-bats.sh test/integration/core/core-commands.bats +$ DRIVER=digitalocean make test-integration test/integration/core/core-commands.bats ... ``` To invoke a directory of tests recursively: ```console -$ DRIVER=virtualbox ./test/integration/run-bats.sh test/integration/core/ +$ DRIVER=virtualbox make test-integration test/integration/core/ ... ``` -If you want to invoke a group of tests across two or more different drivers at -once (e.g. every test in the `drivers` directory), at the time of writing there -is no first-class support to do so - you will have to write your own wrapper -scripts, bash loops, etc. However, in the future, this may gain first-class -support as usage patterns become more clear. - ### Extra Create Arguments In some cases, for instance to test the creation of a specific base OS (e.g. @@ -175,7 +201,7 @@ $ DRIVER=amazonec2 \ AWS_ACCESS_KEY_ID=zzzzzzzzzzzzzzzz \ AWS_AMI=ami-12663b7a \ AWS_SSH_USER=ec2-user \ - ./test/integration/run-bats.sh test/integration/core + make test-integration test/integration/core ``` in order to run the core tests on Red Hat Enterprise Linux on Amazon. diff --git a/Dockerfile b/Dockerfile index 00bb5f639d..cf54caf842 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,11 @@ FROM golang:1.5 -# TODO: Vendor these `go get` commands using Godep. -RUN go get github.com/mitchellh/gox -RUN go get github.com/aktau/github-release -RUN go get github.com/tools/godep -RUN go get golang.org/x/tools/cmd/cover - -ENV GOPATH /go/src/github.com/docker/machine/Godeps/_workspace:/go -ENV MACHINE_BINARY /go/src/github.com/docker/machine/docker-machine -ENV USER root +RUN go get github.com/mitchellh/gox \ + github.com/golang/lint/golint \ + github.com/mattn/goveralls \ + golang.org/x/tools/cover \ + github.com/aktau/github-release WORKDIR /go/src/github.com/docker/machine -ADD . /go/src/github.com/docker/machine +ADD . /go/src/github.com/docker/machine \ No newline at end of file diff --git a/Makefile b/Makefile index 4f4d249c8f..51812be8d8 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,31 @@ -.PHONY: test validate-dco validate-gofmt +# Plain make targets if not requested inside a container +ifeq ($(USE_CONTAINER),) + include Makefile.inc + include mk/main.mk +else +# Otherwise, with docker, swallow all targets and forward into a container +DOCKER_IMAGE_NAME := "docker-machine-build" +DOCKER_CONTAINER_NAME := "docker-machine-build-container" -default: build +%: + @docker build -t $(DOCKER_IMAGE_NAME) . -remote: build-remote + @test -z '$(shell docker ps -a | grep $(DOCKER_CONTAINER_NAME))' || docker rm -f $(DOCKER_CONTAINER_NAME) -test: - script/test + @docker run --name $(DOCKER_CONTAINER_NAME) \ + -e DEBUG \ + -e STATIC \ + -e VERBOSE \ + -e BUILDTAGS \ + -e PARALLEL \ + -e COVERAGE_DIR \ + -e TARGET_OS \ + -e TARGET_ARCH \ + -e PREFIX \ + $(DOCKER_IMAGE_NAME) \ + make $@ -validate-dco: - script/validate-dco + @test ! -d bin || rm -Rf bin + @test -z "$(findstring build,$@)" || docker cp $(DOCKER_CONTAINER_NAME):/go/src/github.com/docker/machine/bin bin -validate-gofmt: - script/validate-gofmt - -validate: validate-dco validate-gofmt test - -build: clean - script/build - -build-remote: clean - script/build-remote - -clean: - rm -f docker-machine_* - rm -rf Godeps/_workspace/pkg +endif diff --git a/Makefile.inc b/Makefile.inc new file mode 100644 index 0000000000..39dd478e9b --- /dev/null +++ b/Makefile.inc @@ -0,0 +1,39 @@ +# Project name, used to name the binaries +PKG_NAME := docker-machine +GH_USER ?= docker +GH_REPO ?= machine + +# If true, disable optimizations and does NOT strip the binary +DEBUG ?= +# If true, "build" will produce a static binary (cross compile always produce static build regardless) +STATIC ?= +# If true, turn on verbose output for build +VERBOSE ?= +# Build tags +BUILDTAGS ?= +# Adjust parallelism for gox +PARALLEL ?= -1 +# Coverage default directory +COVERAGE_DIR ?= cover +# Whether to perform targets inside a docker container, or natively on the host +USE_CONTAINER ?= + +# List of cross compilation targets +ifeq ($(TARGET_OS),) + TARGET_OS := darwin freebsd linux windows +endif + +ifeq ($(TARGET_ARCH),) + TARGET_ARCH := amd64 arm 386 +endif + +# Output prefix, defaults to local directory if not specified +ifeq ($(PREFIX),) + PREFIX := $(shell pwd) +endif + +default: build +clean: coverage-clean build-clean +build: build-simple +test: dco fmt test-short +validate: dco fmt vet lint test-short test-long \ No newline at end of file diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000000..5d8049985c --- /dev/null +++ b/circle.yml @@ -0,0 +1,53 @@ +# Pony-up! +machine: + pre: + # Install gvm + - bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/1.0.22/binscripts/gvm-installer) + # Install bats + - git clone https://github.com/sstephenson/bats.git && cd bats && sudo ./install.sh /usr/local + # - sudo apt-get install -y virtualbox + + post: + - gvm install go1.5 -B --name=stable + + environment: + # Convenient shortcuts to "common" locations + CHECKOUT: /home/ubuntu/$CIRCLE_PROJECT_REPONAME + BASE_DIR: src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME + # Trick circle brainflat "no absolute path" behavior + BASE_STABLE: ../../../$HOME/.gvm/pkgsets/stable/global/$BASE_DIR + # BASE_BLEED: ../../../$HOME/.gvm/pkgsets/bleed/global/$BASE_DIR + BUILDTAGS: "" + +dependencies: + override: + - > + gvm use stable && + mkdir -p "$(dirname $BASE_STABLE)" && + cp -R "$CHECKOUT" "$BASE_STABLE" + +test: + pre: + - gvm use stable && go version + - gvm use stable && TARGET_ARCH=amd64 TARGET_OS=linux make build-x: + pwd: $BASE_STABLE + + override: + - DRIVER=none test/integration/run-bats.sh test/integration/cli: + pwd: $BASE_STABLE + timeout: 600 + # - DRIVER=virtualbox test/integration/run-bats.sh test/integration/core: + # pwd: $BASE_STABLE + # timeout: 1200 + # - DRIVER=digitalocean test/integration/run-bats.sh test/integration/core: + # pwd: $BASE_STABLE + # timeout: 1200 + # - DRIVER=azure test/integration/run-bats.sh test/integration/core: + # pwd: $BASE_STABLE + # timeout: 1200 + # - DRIVER=amazonec2 test/integration/run-bats.sh test/integration/core: + # pwd: $BASE_STABLE + # timeout: 1200 + + # - gvm use stable && DRIVER=amazonec2 test/integration/run-bats.sh test/integration/core: + # pwd: $BASE_STABLE diff --git a/docs/img/coverage.png b/docs/img/coverage.png index 210a30ff83..98d0ffab96 100644 Binary files a/docs/img/coverage.png and b/docs/img/coverage.png differ diff --git a/docs/reference/ls.md b/docs/reference/ls.md index 9223e4ed47..f62c604b4e 100644 --- a/docs/reference/ls.md +++ b/docs/reference/ls.md @@ -31,7 +31,7 @@ The currently supported filters are: * driver (driver name) * swarm (swarm master's name) * state (`Running|Paused|Saved|Stopped|Stopping|Starting|Error`) -* name (Machine name returned by driver, supports golang style (https://github.com/google/re2/wiki/Syntax) regular expressions in machine name) +* name (Machine name returned by driver, supports [golang style](https://github.com/google/re2/wiki/Syntax) regular expressions) ## Examples diff --git a/drivers/none/none.go b/drivers/none/none.go index 94dd7e7efc..c237845fa5 100644 --- a/drivers/none/none.go +++ b/drivers/none/none.go @@ -51,10 +51,6 @@ func (d *Driver) GetIP() (string, error) { return d.IPAddress, nil } -func (d *Driver) GetMachineName() string { - return "" -} - func (d *Driver) GetSSHHostname() (string, error) { return "", nil } diff --git a/mk/build.mk b/mk/build.mk new file mode 100644 index 0000000000..bc63b48c44 --- /dev/null +++ b/mk/build.mk @@ -0,0 +1,33 @@ +build-clean: + @rm -f $(PREFIX)/bin/* + +# Simple build +build-simple: $(PREFIX)/bin/$(PKG_NAME) + +# XXX building with -a fails in debug (with -N -l) ???? +$(PREFIX)/bin/$(PKG_NAME): $(shell find . -type f -name '*.go') + go build -o $@ $(VERBOSE_GO) -tags "$(BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS) ./main.go + +# Cross-build: careful, does always rebuild! +build-x: clean + $(if $(GOX), , \ + $(error Please install gox: go get -u github.com/mitchellh/gox)) + @$(GOX) \ + -os "$(TARGET_OS)" \ + -arch "$(TARGET_ARCH)" \ + -output="$(PREFIX)/bin/docker-machine_{{.OS}}-{{.Arch}}" \ + -ldflags="$(GO_LDFLAGS)" \ + -tags="$(BUILDTAGS)" \ + -gcflags="$(GO_GCFLAGS)" \ + -parallel=$(PARALLEL) \ + -rebuild $(VERBOSE_GOX) + +# Cross builder helper +# define gocross +# GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build -o $(PREFIX)/$(PKG_NAME)_$(1)-$(2) \ +# -a $(VERBOSE_GO) -tags "static_build netgo $(BUILDTAGS)" -installsuffix netgo -ldflags "$(GO_LDFLAGS) -extldflags -static" $(GO_GCFLAGS) ./main.go; +# endef + +# Native build-x (no gox) +# build-x: $(shell find . -type f -name '*.go') +# @$(foreach GOARCH,$(TARGET_ARCH),$(foreach GOOS,$(TARGET_OS),$(call gocross,$(GS),$(GA)))) \ No newline at end of file diff --git a/mk/coverage.mk b/mk/coverage.mk new file mode 100644 index 0000000000..368f10c55e --- /dev/null +++ b/mk/coverage.mk @@ -0,0 +1,45 @@ +# COVERAGE_OUTPUT dir is a temp dir (OSX/Linux compatible), unless explicitly specified through env COVERAGE_DIR +COVERAGE_OUTPUT := $(COVERAGE_DIR) +ifeq ($(COVERAGE_OUTPUT),) + COVERAGE_OUTPUT := $(shell mktemp -d 2>/dev/null || mktemp -d -t machine-coverage) +endif + +# Final cover file, html, and mode +COVERAGE_PROFILE := $(COVERAGE_OUTPUT)/profile.out +COVERAGE_HTML := $(COVERAGE_OUTPUT)/index.html +COVERAGE_MODE := set + +# Goveralls dependency +GOVERALLS_BIN := $(GOPATH)/bin/goveralls +GOVERALLS := $(shell [ -x $(GOVERALLS_BIN) ] && echo $(GOVERALLS_BIN) || echo '') + +# Generate coverage +coverage-generate: $(COVERAGE_PROFILE) + +# Send the results to coveralls +coverage-send: $(COVERAGE_PROFILE) + $(if $(GOVERALLS), , $(error Please install goveralls: go get github.com/mattn/goveralls)) + @$(GOVERALLS) -service travis-ci -coverprofile="$(COVERAGE_PROFILE)" + +# Generate html report +coverage-html: $(COVERAGE_HTML) + @open "$(COVERAGE_HTML)" + +# Serve over http - useful only if building remote/headless +coverage-serve: $(COVERAGE_HTML) + @cd "$(COVERAGE_OUTPUT)" && python -m SimpleHTTPServer 8000 + +# Clean up coverage coverage output +coverage-clean: + @rm -Rf "$(COVERAGE_OUTPUT)/coverage" + @rm -f "$(COVERAGE_HTML)" + @rm -f "$(COVERAGE_PROFILE)" + +$(COVERAGE_PROFILE): $(shell find . -type f -name '*.go') + @mkdir -p "$(COVERAGE_OUTPUT)/coverage" + @$(foreach PKG,$(PKGS), go test $(VERBOSE) -tags "$(BUILDTAGS)" -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_OUTPUT)/coverage/`echo $(PKG) | tr "/" "-"`.cover" "$(PKG)";) + @echo "mode: $(COVERAGE_MODE)" > "$(COVERAGE_PROFILE)" + @grep -h -v "^mode:" "$(COVERAGE_OUTPUT)/coverage"/*.cover >> "$(COVERAGE_PROFILE)" + +$(COVERAGE_HTML): $(COVERAGE_PROFILE) + @go tool cover -html="$(COVERAGE_PROFILE)" -o "$(COVERAGE_HTML)" diff --git a/mk/main.mk b/mk/main.mk new file mode 100644 index 0000000000..9a67fad0c9 --- /dev/null +++ b/mk/main.mk @@ -0,0 +1,53 @@ +# Initialize version and gc flags +GO_LDFLAGS := -X `go list ./version`.GitCommit=`git rev-parse --short HEAD` +GO_GCFLAGS := + +# Full package list +PKGS := $(shell go list -tags "$(BUILDTAGS)" ./... | grep -v "/vendor/" | grep -v "/Godeps/") + +# Support go1.5 vendoring (let us avoid messing with GOPATH or using godep) +export GO15VENDOREXPERIMENT = 1 + +# Resolving binary dependencies for specific targets +GOLINT_BIN := $(GOPATH)/bin/golint +GOLINT := $(shell [ -x $(GOLINT_BIN) ] && echo $(GOLINT_BIN) || echo '') + +GOX_BIN := $(GOPATH)/bin/gox +GOX := $(shell [ -x $(GOX_BIN) ] && echo $(GOX_BIN) || echo '') + +# Honor debug +ifeq ($(DEBUG),true) + # Disable function inlining and variable registerization + GO_GCFLAGS := -gcflags "-N -l" +else + # Turn of DWARF debugging information and strip the binary otherwise + GO_LDFLAGS := $(GO_LDFLAGS) -w -s +endif + +# Honor static +ifeq ($(STATIC),true) + # Append to the version + GO_LDFLAGS := $(GO_LDFLAGS) -extldflags -static +endif + +# Honor verbose +VERBOSE_GO := +VERBOSE_GOX := +ifeq ($(VERBOSE),true) + VERBOSE_GO := -v + VERBOSE_GOX := -verbose +endif + +include mk/build.mk +include mk/coverage.mk +include mk/release.mk +include mk/test.mk +include mk/validate.mk + +.all_build: build build-clean build-x +.all_coverage: coverage-generate coverage-html coverage-send coverage-serve coverage-clean +.all_release: release-checksum release +.all_test: test-short test-long test-integration +.all_validate: dco fmt vet lint + +.PHONY: .all_build .all_coverage .all_release .all_test .all_validate diff --git a/mk/release.mk b/mk/release.mk new file mode 100644 index 0000000000..66710334a4 --- /dev/null +++ b/mk/release.mk @@ -0,0 +1,42 @@ +# XXX FIXME: suboptimal, as it will sign signatures files if they are there +release-checksum: + $(foreach MACHINE_FILE, $(wildcard $(PREFIX)/bin/*), \ + $(shell openssl dgst -sha256 < "$(MACHINE_FILE)" > "$(MACHINE_FILE).sha256" && \ + openssl dgst -md5 < "$(MACHINE_FILE)" > "$(MACHINE_FILE).md5" \ + )) + @: + +release: clean dco fmt test test-long build-x release-checksum + $(if $(GITHUB_TOKEN), , \ + $(error GITHUB_TOKEN must be set for github-release)) + + $(eval VERSION=$(filter-out $@,$(MAKECMDGOALS))) + + $(if $(VERSION), , \ + $(error Pass the version number as the first arg. E.g.: make release 1.2.3)) + + @echo $(VERSION) + + git tag $(VERSION) + git push --tags + + github-release release + --user $(GH_USER) \ + --repo $(GH_REPO) \ + --tag $(VERSION) \ + --name $(VERSION) \ + --description "" \ + --pre-release + + $(foreach MACHINE_FILE, $(wildcard $(PREFIX)/bin/*), \ + $(shell github-release upload \ + --user $(GH_USER) \ + --repo $(GH_REPO) \ + --tag $(VERSION) \ + --name $(MACHINE_FILE) \ + --file $(MACHINE_FILE) \ + ) \ + ) + +%: + @: diff --git a/mk/test.mk b/mk/test.mk new file mode 100644 index 0000000000..cf3b9a5bc4 --- /dev/null +++ b/mk/test.mk @@ -0,0 +1,14 @@ +# Quick test. You can bypass long tests using: `if testing.Short() { t.Skip("Skipping in short mode.") }` +test-short: + @go test $(VERBOSE_GO) -test.short -tags "$(BUILDTAGS)" $(PKGS) + +# Runs long tests also, plus race detection +test-long: + @go test $(VERBOSE_GO) -race -tags "$(BUILDTAGS)" $(PKGS) + +test-integration: build + $(eval TESTSUITE=$(filter-out $@,$(MAKECMDGOALS))) + test/integration/run-bats.sh $(TESTSUITE) + +%: + @: diff --git a/mk/validate.mk b/mk/validate.mk new file mode 100644 index 0000000000..c953dd4061 --- /dev/null +++ b/mk/validate.mk @@ -0,0 +1,18 @@ +# Validate DCO on all history +dco: + @script/validate-dco + +# Fmt +fmt: + @test -z "$$(gofmt -s -l . 2>&1 | grep -v vendor/ | grep -v Godeps/ | tee /dev/stderr)" + +# Vet +vet: build + @test -z "$$(go vet $(PKGS) 2>&1 | tee /dev/stderr)" + +# Lint +lint: + $(if $(GOLINT), , \ + $(error Please install golint: go get -u github.com/golang/lint/golint)) + @test -z "$$($(GOLINT) ./... 2>&1 | grep -v vendor/ | grep -v Godeps/ | tee /dev/stderr)" + diff --git a/script/build b/script/build deleted file mode 100755 index 6088aa6e66..0000000000 --- a/script/build +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -set -e - -BUILD_IMAGE_NAME="docker-machine-build" -GOOS=${GOOS:-"darwin linux windows"} -GOARCH=${GOARCH:-"386 amd64 arm"} - -# Build image for compilation if not detected -if [[ $(docker images -q ${BUILD_IMAGE_NAME} | wc -l) -ne 1 ]]; then - docker build -t ${BUILD_IMAGE_NAME} . -fi - -docker run --rm \ - -v `pwd`:/go/src/github.com/docker/machine \ - ${BUILD_IMAGE_NAME} \ - gox \ - -os "$GOOS" \ - -arch "$GOARCH" \ - -output="docker-machine_{{.OS}}-{{.Arch}}" \ - -ldflags="-w -X github.com/docker/machine/version.GitCommit `git rev-parse --short HEAD`" diff --git a/script/build-remote b/script/build-remote deleted file mode 100755 index c1da55b5dd..0000000000 --- a/script/build-remote +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -set -e - -BUILD_IMAGE_NAME="docker-machine-build" -GOOS=${GOOS:-"darwin linux windows"} -GOARCH=${GOARCH:-"386 amd64 arm"} - -docker build -t ${BUILD_IMAGE_NAME} . - -BUILD_CONTAINER=$(docker run -d \ - ${BUILD_IMAGE_NAME} \ - gox \ - -os "$GOOS" \ - -arch "$GOARCH" \ - -output="docker-machine_{{.OS}}-{{.Arch}}" \ - -ldflags="-w -X github.com/docker/machine/version.GitCommit `git rev-parse --short HEAD`") -cleanup_container() { - docker rm -v ${BUILD_CONTAINER} -} -trap cleanup_container EXIT - -docker logs -f ${BUILD_CONTAINER} & -BUILD_STATUS=$(docker wait ${BUILD_CONTAINER}) -if [[ ${BUILD_STATUS} != 0 ]]; then exit ${BUILD_STATUS}; fi - -BUILT_IMAGE=$(docker commit ${BUILD_CONTAINER}) -cleanup_image() { - cleanup_container - docker rmi ${BUILT_IMAGE} -} -trap cleanup_image EXIT - -echo "Copying built binaries:" -for f in $(docker run --rm ${BUILT_IMAGE} sh -c 'echo docker-machine_*'); do - echo " "${f} - docker cp ${BUILD_CONTAINER}:/go/src/github.com/docker/machine/${f} ./ -done -echo Done diff --git a/script/coverage b/script/coverage deleted file mode 100755 index cccc352355..0000000000 --- a/script/coverage +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -docker build -t docker-machine . - -docker run -it \ - -e BUILDTAGS=${BUILDTAGS} \ - -p 8000:8000 \ - --rm docker-machine \ - ./script/generate-coverage serve /go/src/github.com/docker/machine diff --git a/script/generate-coverage b/script/generate-coverage deleted file mode 100755 index 333c3f4b9f..0000000000 --- a/script/generate-coverage +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash -set -e - -# Generate coverage for code in ., unless explicitly pointed to something else via the second argument -DIR=${2:-.} - -# Output dir is a temp dir (OSX/Linux compatible), unless explicitly specified through env COVERAGE_DIR -OUTPUT=${COVERAGE_DIR:-$(mktemp -d 2>/dev/null || mktemp -d -t machine-coverage)} - -# Ensure destination exists -mkdir -p "${OUTPUT}" - -# Final cover file, mode -PROFILE=${OUTPUT}/cover.out -MODE=set - -# Generate coverage -cover() { - cd "$DIR" - - for PKG in $(go list -tags "${BUILDTAGS}" ./... | grep -v "/vendor/" | grep -v "/Godeps/"); do - go test -tags "${BUILDTAGS}" -covermode=${MODE} -coverprofile="${OUTPUT}/$(echo ${PKG} | tr "/" "-").cover" "${PKG}" - done - - echo "mode: ${MODE}" > "${PROFILE}" - grep -h -v "^mode:" "${OUTPUT}"/*.cover >> "${PROFILE}" - go tool cover -html="${PROFILE}" - - cd - -} - -# Send the results to coveralls -report() { - go get github.com/mattn/goveralls - goveralls -service travis-ci -coverprofile="${PROFILE}" -} - -# Useful only if building remote/headless -serve(){ - @cd "${DIR}" - python -m SimpleHTTPServer 8000 - @cd - -} - -case "$1" in - # If in the legacy container, serve as well - serve) - cover - serve - ;; - # Travis does report - report) - cover - report - ;; - # Default is to just cover, no report - *) - cover - ;; -esac diff --git a/script/generate-sums b/script/generate-sums deleted file mode 100755 index 51361e05d9..0000000000 --- a/script/generate-sums +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e - -for BINARY in docker-machine_*; do - sha256sum $BINARY > $BINARY.sha256 - md5sum $BINARY >> $BINARY.md5 -done - diff --git a/script/release b/script/release deleted file mode 100755 index 30c282ee84..0000000000 --- a/script/release +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -set -e -if [ -z "$1" ]; then - echo "Pass the version number as the first arg. E.g.: script/release 1.2.3" - exit 1 -fi -VERSION=$1 -if [ -z "$GITHUB_TOKEN" ]; then - echo "GITHUB_TOKEN must be set for github-release" - exit 1 -fi - -script/build - -docker run --rm -v `pwd`:/go/src/github.com/docker/machine docker-machine ./script/generate-sums - -git tag $VERSION -git push --tags -docker run --rm -e GITHUB_TOKEN docker-machine github-release release \ - --user docker \ - --repo machine \ - --tag $VERSION \ - --name $VERSION \ - --description "" \ - --pre-release -for BINARY in docker-machine_*; do - docker run --rm -e GITHUB_TOKEN -v `pwd`:/go/src/github.com/docker/machine \ - docker-machine github-release upload \ - --user docker \ - --repo machine \ - --tag $VERSION \ - --name $BINARY \ - --file $BINARY -done diff --git a/script/run-integration-tests b/script/run-integration-tests deleted file mode 100755 index 6f3163c2b5..0000000000 --- a/script/run-integration-tests +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -godep go test -v ./_integration-test - diff --git a/script/test b/script/test deleted file mode 100755 index b297812c13..0000000000 --- a/script/test +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -set -e - -ARGS=$@ -if [ -z "$ARGS" ]; then - ARGS="./..." -fi - -echo $ARGS - -docker build -t docker-machine . -exec docker run --rm docker-machine godep go test -v -short $ARGS diff --git a/script/validate-git-marks b/script/validate-git-marks deleted file mode 100755 index 24f048425d..0000000000 --- a/script/validate-git-marks +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -IN_MARK=$(grep -r "^<<<<<<<" *) -if [ $? -eq 0 ]; then - echo "-- Git conflict marks have been found, please correct them :" - echo "$IN_MARK" - exit 1 -fi - -OUT_MARK=$(grep -r "^>>>>>>>" *) -if [ $? -eq 0 ]; then - echo "-- Git conflict marks have been found, please correct them :" - echo "$OUT_MARK" - exit 1 -fi - -SEPARATE_MARK=$(grep -r "^=======$" *) -if [ $? -eq 0 ]; then - echo "-- Git conflict marks have been found, please correct them :" - echo "$SEPARATE_MARK" - exit 1 -fi - -echo "-- Congratulations : no git conflict marks have been found !" diff --git a/script/validate-gofmt b/script/validate-gofmt deleted file mode 100755 index c565976b41..0000000000 --- a/script/validate-gofmt +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -source "$(dirname "$BASH_SOURCE")/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^Godeps/' || true) ) -unset IFS - -badFiles=() -for f in "${files[@]}"; do - # we use "git show" here to validate that what's committed is formatted - if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then - badFiles+=( "$f" ) - fi -done - -if [ ${#badFiles[@]} -eq 0 ]; then - echo 'Congratulations! All Go source files are properly formatted.' -else - { - echo "These files are not properly gofmt'd:" - for f in "${badFiles[@]}"; do - echo " - $f" - done - echo - echo 'Please reformat the above files using "gofmt -s -w" and commit the result.' - echo - } >&2 - false -fi diff --git a/test/integration/azure/test.cer b/test/integration/azure/test.cer new file mode 100644 index 0000000000..87900e4d93 Binary files /dev/null and b/test/integration/azure/test.cer differ diff --git a/test/integration/cli/create-rm.bats b/test/integration/cli/create-rm.bats new file mode 100644 index 0000000000..e16ae36ddf --- /dev/null +++ b/test/integration/cli/create-rm.bats @@ -0,0 +1,98 @@ +#!/usr/bin/env bats + +load ${BASE_TEST_DIR}/helpers.bash + +@test "bogus: non-existent driver fails 'machine create -d bogus bogus'" { + run machine create -d bogus bogus + [ "$status" -eq 1 ] + [[ ${lines[0]} == "Driver bogus not found" ]] +} + +@test "none: create with no name fails 'machine create -d none " "'" { + run machine create -d none + last=$((${#lines[@]} - 1)) + [ "$status" -eq 1 ] + [[ ${lines[$last]} == "You must specify a machine name" ]] +} + +@test "none: create with invalid name fails 'machine create -d none --url none ∞'" { + run machine create -d none --url none ∞ + last=$((${#lines[@]} - 2)) + [ "$status" -eq 1 ] + [[ ${lines[$last]} == "Error creating machine: Invalid hostname specified" ]] +} + +@test "none: create with invalid name fails 'machine create -d none --url none -'" { + run machine create -d none --url none - + [ "$status" -eq 1 ] + [[ ${lines[0]} == "Error creating machine: Invalid hostname specified" ]] +} + +@test "none: create with invalid name fails 'machine create -d none --url none .'" { + run machine create -d none --url none . + [ "$status" -eq 1 ] + [[ ${lines[0]} == "Error creating machine: Invalid hostname specified" ]] +} + +@test "none: create with invalid name fails 'machine create -d none --url none ..'" { + run machine create -d none --url none .. + [ "$status" -eq 1 ] + [[ ${lines[0]} == "Error creating machine: Invalid hostname specified" ]] +} + +@test "none: create with weird but valid name succeeds 'machine create -d none --url none a'" { + run machine create -d none --url none a + [ "$status" -eq 0 ] +} + +# @test "none: name is case insensitive 'machine create -d none --url none A'" { +# run machine create -d none --url none A +# [ "$status" -eq 1 ] +# [[ ${lines[0]} == "Error creating machine: Machine A already exists" ]] +# } + +@test "none: extraneous argument is ignored in name 'machine create -d none --url none a foo'" { + run machine create -d none a foo + [ "$status" -eq 1 ] + [[ ${lines[0]} == "Error creating machine: Machine a already exists" ]] +} + +@test "none: create with weird but valid name succeeds 'machine create -d none --url none 0'" { + run machine create -d none --url none 0 + [ "$status" -eq 0 ] +} + +@test "none: rm with no name fails 'machine rm'" { + run machine rm + last=$(expr ${#lines[@]} - 1) + [ "$status" -eq 1 ] + [[ ${lines[$last]} == "You must specify a machine name" ]] +} + +@test "none: rm non existent machine fails 'machine rm ∞'" { + run machine rm ∞ + [ "$status" -eq 1 ] + [[ ${lines[0]} == "Error removing machine ∞: Error: Host does not exist: ∞" ]] +} + +@test "none: rm is succesful 'machine rm 0'" { + run machine rm 0 + [ "$status" -eq 0 ] +} + +# Should be replaced by the test below +@test "none: rm is succesful 'machine rm a'" { + run machine rm a + [ "$status" -eq 0 ] +} + +# @test "none: rm is case insensitive 'machine rm A'" { +# run machine rm A +# [ "$status" -eq 0 ] +# } + +@test "none: rm non existent machine fails 'machine rm ∞'" { + run machine rm ∞ + [ "$status" -eq 1 ] + [[ ${lines[0]} == "Error removing machine ∞: Error: Host does not exist: ∞" ]] +} diff --git a/test/integration/cli/help.bats b/test/integration/cli/help.bats index f30c8f2806..58376e7d67 100644 --- a/test/integration/cli/help.bats +++ b/test/integration/cli/help.bats @@ -21,6 +21,18 @@ load ${BASE_TEST_DIR}/helpers.bash [[ ${lines[0]} =~ "machine config" ]] } +@test "cli: show create help" { + run machine create -h + [ "$status" -eq 0 ] + [[ ${lines[0]} =~ "machine create" ]] +} + +@test "cli: show env help" { + run machine env -h + [ "$status" -eq 0 ] + [[ ${lines[0]} =~ "machine env" ]] +} + @test "cli: show inspect help" { run machine inspect -h [ "$status" -eq 0 ] @@ -45,6 +57,12 @@ load ${BASE_TEST_DIR}/helpers.bash [[ ${lines[0]} =~ "machine ls" ]] } +@test "cli: show regenerate-certs help" { + run machine regenerate-certs -h + [ "$status" -eq 0 ] + [[ ${lines[0]} =~ "machine regenerate-certs" ]] +} + @test "cli: show restart help" { run machine restart -h [ "$status" -eq 0 ] @@ -57,10 +75,10 @@ load ${BASE_TEST_DIR}/helpers.bash [[ ${lines[0]} =~ "machine rm" ]] } -@test "cli: show env help" { - run machine env -h +@test "cli: show scp help" { + run machine scp -h [ "$status" -eq 0 ] - [[ ${lines[0]} =~ "machine env" ]] + [[ ${lines[0]} =~ "machine scp" ]] } @test "cli: show ssh help" { @@ -75,6 +93,12 @@ load ${BASE_TEST_DIR}/helpers.bash [[ ${lines[0]} =~ "machine start" ]] } +@test "cli: show status help" { + run machine status -h + [ "$status" -eq 0 ] + [[ ${lines[0]} =~ "machine status" ]] +} + @test "cli: show stop help" { run machine stop -h [ "$status" -eq 0 ] diff --git a/test/integration/cli/ls.bats b/test/integration/cli/ls.bats index f80697035e..01529a57e3 100644 --- a/test/integration/cli/ls.bats +++ b/test/integration/cli/ls.bats @@ -4,36 +4,160 @@ load ${BASE_TEST_DIR}/helpers.bash teardown () { machine rm testmachine + machine rm testmachine2 + machine rm testmachine3 } -@test "ls: filter on driver" { - run machine create -d none --url tcp://127.0.0.1:2375 testmachine +@test "ls: filter on driver 'machine ls --filter driver=none'" { + run machine create -d none --url none testmachine3 + run machine create -d none --url none testmachine2 + run machine create -d none --url none testmachine run machine ls --filter driver=none - [ "$status" -eq 0 ] + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 4 ]] [[ ${lines[1]} =~ "testmachine" ]] + [[ ${lines[2]} =~ "testmachine2" ]] + [[ ${lines[3]} =~ "testmachine3" ]] } -@test "ls: filter on swarm" { - run machine create -d none --url tcp://127.0.0.1:2375 --swarm --swarm-master --swarm-discovery token://deadbeef testmachine - run machine ls --filter swarm=testmachine - [ "$status" -eq 0 ] - [[ ${lines[1]} =~ "testmachine" ]] +@test "ls: filter on driver 'machine ls -q --filter driver=none'" { + run machine create -d none --url none testmachine3 + run machine create -d none --url none testmachine2 + run machine create -d none --url none testmachine + run machine ls -q --filter driver=none + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 3 ]] + [[ ${lines[0]} == "testmachine" ]] + [[ ${lines[1]} == "testmachine2" ]] + [[ ${lines[2]} == "testmachine3" ]] } -@test "ls: filter on name" { - run mchine create -d none -url tcp://127.0.0.1:2375 testmachine - run mchine create -d none -url tcp://127.0.0.1:2375 testmachine2 - run mchine create -d none -url tcp://127.0.0.1:2375 testmachine3 - run mchine ls --filter name=testmachine2 +@test "ls: filter on state 'machine ls --filter state=\"\"'" { + run machine create -d none --url none testmachine3 + run machine create -d none --url none testmachine2 + run machine create -d none --url none testmachine + run machine ls --filter state="" [ "$status" -eq 0 ] + [[ ${#lines[@]} == 4 ]] + [[ ${lines[1]} =~ "testmachine" ]] + [[ ${lines[2]} =~ "testmachine2" ]] + [[ ${lines[3]} =~ "testmachine3" ]] + + # TODO: have machines in that state + run machine ls --filter state="Running" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 1 ]] + run machine ls --filter state="Paused" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 1 ]] + run machine ls --filter state="Saved" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 1 ]] + run machine ls --filter state="Stopped" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 1 ]] + run machine ls --filter state="Stopping" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 1 ]] + run machine ls --filter state="Starting" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 1 ]] + run machine ls --filter state="Error" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 1 ]] +} + +@test "ls: filter on state 'machine ls -q --filter state=\"\"'" { + run machine create -d none --url none testmachine3 + run machine create -d none --url none testmachine2 + run machine create -d none --url none testmachine + run machine ls -q --filter state="" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 3 ]] + [[ ${lines[0]} == "testmachine" ]] + [[ ${lines[1]} == "testmachine2" ]] + [[ ${lines[2]} == "testmachine3" ]] +} + +@test "ls: filter on name 'machine ls --filter name=\"testmachine2\"'" { + run machine create -d none --url none testmachine3 + run machine create -d none --url none testmachine2 + run machine create -d none --url none testmachine + run machine ls --filter name="testmachine2" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 2 ]] [[ ${lines[1]} =~ "testmachine2" ]] } -@test "ls: filter on name with regex" { - run mchine create -d none -url tcp://127.0.0.1:2375 squirrel - run mchine create -d none -url tcp://127.0.0.1:2375 cat - run mchine create -d none -url tcp://127.0.0.1:2375 dog - run mchine ls --filter name=c.?t - [ "$status" -eq 0 ] - [[ ${lines[1]} =~ "cat" ]] +@test "ls: filter on name 'machine ls -q --filter name=\"testmachine2\"'" { + run machine create -d none --url none testmachine3 + run machine create -d none --url none testmachine2 + run machine create -d none --url none testmachine + run machine ls -q --filter name="testmachine2" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 1 ]] + [[ ${lines[0]} == "testmachine2" ]] +} + +@test "ls: filter on name with regex 'machine ls --filter name=\"^t.*e\"'" { + run machine create -d none --url none testmachine3 + run machine create -d none --url none testmachine2 + run machine create -d none --url none testmachine + run machine ls --filter name="^t.*e" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 4 ]] + [[ ${lines[1]} =~ "testmachine" ]] + [[ ${lines[2]} =~ "testmachine2" ]] + [[ ${lines[3]} =~ "testmachine3" ]] +} + +@test "ls: filter on name with regex 'machine ls -q --filter name=\"^t.*e\"'" { + run machine create -d none --url none testmachine3 + run machine create -d none --url none testmachine2 + run machine create -d none --url none testmachine + run machine ls -q --filter name="^t.*e" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 3 ]] + [[ ${lines[0]} == "testmachine" ]] + [[ ${lines[1]} == "testmachine2" ]] + [[ ${lines[2]} == "testmachine3" ]] +} + +@test "ls: filter on swarm 'machine ls --filter swarm=testmachine3'" { + run machine create -d none --url tcp://127.0.0.1:2375 --swarm --swarm-master --swarm-discovery token://deadbeef testmachine3 + run machine create -d none --url tcp://127.0.0.1:2375 --swarm --swarm-discovery token://deadbeef testmachine2 + run machine create -d none --url tcp://127.0.0.1:2375 --swarm --swarm-discovery token://deadbeef testmachine + sleep 0.5 + run machine ls --filter swarm=testmachine3 + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 4 ]] + [[ ${lines[1]} =~ "testmachine" ]] + [[ ${lines[2]} =~ "testmachine2" ]] + [[ ${lines[3]} =~ "testmachine3" ]] +} + +@test "ls: filter on swarm 'machine ls -q --filter swarm=testmachine3'" { + run machine create -d none --url none --swarm --swarm-master --swarm-discovery token://deadbeef testmachine3 + run machine create -d none --url none --swarm --swarm-discovery token://deadbeef testmachine2 + run machine create -d none --url none --swarm --swarm-discovery token://deadbeef testmachine + sleep 0.5 + run machine ls -q --filter swarm=testmachine3 + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 3 ]] + [[ ${lines[0]} == "testmachine" ]] + [[ ${lines[1]} == "testmachine2" ]] + [[ ${lines[2]} == "testmachine3" ]] +} + +@test "ls: multi filter 'machine ls -q --filter swarm=testmachine3 --filter name=\"^t.*e\" --filter driver=none --filter state=\"\"'" { + run machine create -d none --url none --swarm --swarm-master --swarm-discovery token://deadbeef testmachine3 + run machine create -d none --url none --swarm --swarm-discovery token://deadbeef testmachine2 + run machine create -d none --url none --swarm --swarm-discovery token://deadbeef testmachine + sleep 0.5 + run machine ls -q --filter swarm=testmachine3 --filter name="^t.*e" --filter driver=none --filter state="" + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 3 ]] + [[ ${lines[0]} == "testmachine" ]] + [[ ${lines[1]} == "testmachine2" ]] + [[ ${lines[2]} == "testmachine3" ]] } diff --git a/test/integration/core/arbitrary-engine-envs.bats b/test/integration/core/arbitrary-engine-envs.bats index 4e8fe89a7e..21797ca4ce 100644 --- a/test/integration/core/arbitrary-engine-envs.bats +++ b/test/integration/core/arbitrary-engine-envs.bats @@ -2,18 +2,17 @@ load ${BASE_TEST_DIR}/helpers.bash - @test "$DRIVER: create with arbitrary engine envs" { - -run machine create -d $DRIVER \ - --engine-env=TEST=VALUE \ - $NAME + run machine create -d $DRIVER \ + --engine-env=TEST=VALUE \ + $NAME + echo ${output} [ $status -eq 0 ] } @test "$DRIVER: test docker process envs" { - # get pid of docker process, check process envs for set Environment Variable from above test - run machine ssh $NAME 'pgrep -f "docker -d" | xargs -I % sudo cat /proc/%/environ | grep -q "TEST=VALUE"' + run machine ssh $NAME 'pgrep -f "docker" | xargs -I % sudo cat /proc/%/environ | grep "TEST=VALUE"' + echo ${output} [ $status -eq 0 ] } diff --git a/test/integration/core/arbitrary-engine-options.bats b/test/integration/core/arbitrary-engine-options.bats index afdee75824..f7703bde56 100644 --- a/test/integration/core/arbitrary-engine-options.bats +++ b/test/integration/core/arbitrary-engine-options.bats @@ -6,11 +6,13 @@ load ${BASE_TEST_DIR}/helpers.bash run machine create -d $DRIVER \ --engine-opt log-driver=none \ $NAME + echo ${output} [ $status -eq 0 ] } @test "$DRIVER: check created engine option (log driver)" { docker $(machine config $NAME) run --name nolog busybox echo this should not be logged run docker $(machine config $NAME) logs nolog + echo ${output} [ $status -eq 1 ] } diff --git a/test/integration/core/core-commands.bats b/test/integration/core/core-commands.bats index 027be89aea..1c09238b3a 100644 --- a/test/integration/core/core-commands.bats +++ b/test/integration/core/core-commands.bats @@ -5,108 +5,142 @@ load ${BASE_TEST_DIR}/helpers.bash @test "$DRIVER: machine should not exist" { run machine inspect $NAME echo ${output} - [ "$status" -eq 1 ] + [ "$status" -eq 1 ] + [[ ${lines[0]} == "unable to load host: Error: Host does not exist: $NAME" ]] } @test "$DRIVER: create" { run machine create -d $DRIVER $NAME + echo ${output} [ "$status" -eq 0 ] } -@test "$DRIVER: ls" { - run machine ls +@test "$DRIVER: appears with ls" { + run machine ls -q + echo ${output} [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] + [[ ${lines[0]} == "$NAME" ]] +} + +@test "$DRIVER: has status 'started' appearing in ls" { + run machine ls --filter state=Running + echo ${output} + [ "$status" -eq 0 ] + [[ ${lines[0]} == "$NAME" ]] +} + +@test "$DRIVER: create with same name again fails" { + run machine create -d $DRIVER $NAME + echo ${output} + [ "$status" -eq 0 ] + [[ ${lines[0]} == "Error creating machine: Machine $NAME already exists" ]] } @test "$DRIVER: run busybox container" { run docker $(machine config $NAME) run busybox echo hello world + echo ${output} [ "$status" -eq 0 ] } @test "$DRIVER: url" { run machine url $NAME + echo ${output} [ "$status" -eq 0 ] } @test "$DRIVER: ip" { run machine ip $NAME + echo ${output} [ "$status" -eq 0 ] } @test "$DRIVER: ssh" { run machine ssh $NAME -- ls -lah / + echo ${output} [ "$status" -eq 0 ] [[ ${lines[0]} =~ "total" ]] } @test "$DRIVER: docker commands with the socket should work" { run machine ssh $NAME -- sudo docker version + echo ${output} } @test "$DRIVER: stop" { run machine stop $NAME + echo ${output} [ "$status" -eq 0 ] } @test "$DRIVER: machine should show stopped after stop" { run machine ls + echo ${output} [ "$status" -eq 0 ] [[ ${lines[1]} == *"Stopped"* ]] } @test "$DRIVER: url should show an error when machine is stopped" { run machine url $NAME + echo ${output} [ "$status" -eq 1 ] [[ ${output} == *"not running"* ]] } @test "$DRIVER: env should show an error when machine is stopped" { run machine env $NAME + echo ${output} [ "$status" -eq 1 ] [[ ${output} == *"not running. Please start this with"* ]] } @test "$DRIVER: machine should not allow upgrade when stopped" { run machine upgrade $NAME + echo ${output} [[ "$status" -eq 1 ]] } @test "$DRIVER: start" { run machine start $NAME + echo ${output} [ "$status" -eq 0 ] } @test "$DRIVER: machine should show running after start" { run machine ls + echo ${output} [ "$status" -eq 0 ] [[ ${lines[1]} == *"Running"* ]] } @test "$DRIVER: kill" { run machine kill $NAME + echo ${output} [ "$status" -eq 0 ] } @test "$DRIVER: machine should show stopped after kill" { run machine ls + echo ${output} [ "$status" -eq 0 ] [[ ${lines[1]} == *"Stopped"* ]] } @test "$DRIVER: restart" { run machine restart $NAME + echo ${output} [ "$status" -eq 0 ] } @test "$DRIVER: machine should show running after restart" { run machine ls + echo ${output} [ "$status" -eq 0 ] [[ ${lines[1]} == *"Running"* ]] } @test "$DRIVER: status" { run machine status $NAME + echo ${output} [ "$status" -eq 0 ] [[ ${output} == *"Running"* ]] } diff --git a/vendor b/vendor new file mode 120000 index 0000000000..a8edbc6567 --- /dev/null +++ b/vendor @@ -0,0 +1 @@ +Godeps/_workspace/src \ No newline at end of file