diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2018-01-31 22:21:00 +0100 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2018-01-31 22:21:00 +0100 |
| commit | cd525f8ab11068a16b93035599887d8a8e4146d6 (patch) | |
| tree | f87617dab51afc193509001841d33f315f793476 | |
| parent | 447267b24f921f9640eea14a59997fda37e271b0 (diff) | |
| download | go-schwift-cd525f8ab11068a16b93035599887d8a8e4146d6.tar.gz | |
add testing scripts based on github.com/bouncestorage/docker-swift
| -rw-r--r-- | CONTRIBUTING.md | 39 | ||||
| -rw-r--r-- | testing/data/.gitignore | 2 | ||||
| -rwxr-xr-x | testing/start-saio.sh | 7 | ||||
| -rwxr-xr-x | testing/with-saio.sh | 13 |
4 files changed, 61 insertions, 0 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..96ae415 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,39 @@ +# Coding style + +Before submitting a pull request: + +- Please format your code with `gofmt` or `goimports`. +- Please fix warnings generated by `golint` and `go vet`. +- When changing the API, run `godoc -http=:6060`, point your browser to + http://localhost:6060/pkg/github.com/majewsky/schwift and check how your documentation looks. + +As a general rule of thumb, we prefer idiomatic Go code as described in: + +- [Effective Go](https://golang.org/doc/effective_go.html) +- [Collected Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments) + +# Running the unit tests + +The unit tests require a Swift server (duh). + +## Using a Swift cluster + +The preferred option is a regular Swift deployment: Run `go test` with the same authentication variables that you give +to the official `swift` client: + +- for Swift inside an OpenStack cluster: `OS_AUTH_URL`, `OS_USERNAME`, `OS_PASSWORD`, etc. +- for Swift using its builtin authentication: `ST_AUTH`, `ST_USER`, `ST_KEY` + +## Using a Swift All-in-One container + +If you don't have a Swift deployment at your disposal where you're running the unit tests, you can use the scripts in +the [`testing` subdirectory](./testing/) to run a Swift all-in-one (SAIO) [development setup in a Docker +container](https://github.com/bouncestorage/docker-swift). + +1. Run `./testing/start-saio.sh` to start the SAIO container (possibly with `sudo` if your user is not in the `docker` + group). Once that has come up successfully, press Ctrl-C to get back to your terminal prompt; the SAIO container will + continue running. + +2. Run the tests with `./testing/with-saio.sh go test`. The script will find how to access the Swift API inside the + container, and configure the auth environment variables accordingly. You can use this with any command that requires + Swift credentials, e.g. `./testing/with-saio.sh swift stat`. diff --git a/testing/data/.gitignore b/testing/data/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/testing/data/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/testing/start-saio.sh b/testing/start-saio.sh new file mode 100755 index 0000000..81cf845 --- /dev/null +++ b/testing/start-saio.sh @@ -0,0 +1,7 @@ +#!/bin/sh +if docker inspect schwift-testing &>/dev/null; then + echo 'Already running.' +else + # The `readlink -f` converts the path to repo/testing/data to an absolute path. + exec docker run --name schwift-testing -P -v "$(readlink -f "$(dirname $0)")/data:/swift/nodes" -t bouncestorage/swift-aio +fi diff --git a/testing/with-saio.sh b/testing/with-saio.sh new file mode 100755 index 0000000..9f040eb --- /dev/null +++ b/testing/with-saio.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +if ! docker inspect schwift-testing >/dev/null; then + echo "SAIO container not running yet. Run ./testing/start-saio.sh to start it." >&2 + exit 1 +fi + +ST_PORT="$(docker inspect schwift-testing | jq -r '.[0].NetworkSettings.Ports["8080/tcp"][0].HostPort')" +export ST_AUTH="http://127.0.0.1:${ST_PORT}/auth/v1.0" +export ST_USER="test:tester" # hardcoded auth parameters in the bouncestorage/docker-swift image +export ST_KEY="testing" + +exec "$@" |
