Skip to content

Commit

Permalink
Fix tests and add Makefile
Browse files Browse the repository at this point in the history
- Fix network ports (my bad)
- Fix failing test since the `CapabilitiesResponse` was added
- Create Makefile for ease of running tests using Docker
  - make test = with docker
  - make test-local = using local go
- Tell Travis to use Docker

Signed-off-by: Dave Tucker <[email protected]>
  • Loading branch information
Dave Tucker committed Feb 8, 2016
1 parent 9512bef commit 2ec24c6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
14 changes: 4 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
---
language: go
sudo: required
services:
- docker
notifications:
email: false
go:
- 1.5
install:
- go get -t ./...
- go get github.com/golang/lint/golint
script:
- go vet ./...
- test -z "$(golint ./... | tee /dev/stderr)"
- test -z "$(gofmt -s -l . | tee /dev/stderr)"
- go test -v ./...
- make test
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.PHONY: all test test-local install-deps lint fmt vet

REPO_NAME = go-plugins-helpers
REPO_OWNER = docker
PKG_NAME = github.com/${REPO_NAME}/${REPO_OWNER}
IMAGE = golang:1.5

all: test

test-local: install-deps fmt lint vet
@echo "+ $@"
@go test -v ./...

test:
@docker run -v ${shell pwd}:/go/src/${PKG_NAME} -w /go/src/${PKG_NAME} ${IMAGE} make test-local

install-deps:
@echo "+ $@"
@go get -u github.com/golang/lint/golint
@go get -d ./...

lint:
@echo "+ $@"
@test -z "$$(golint ./... | tee /dev/stderr)"

fmt:
@echo "+ $@"
@test -z "$$(gofmt -s -l . | tee /dev/stderr)"

vet:
@echo "+ $@"
@go vet ./...

4 changes: 1 addition & 3 deletions network/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
)

const (
manifest = `{"Implements": ["NetworkDriver"]}`
defaultScope = `{"Scope": "local"}`

manifest = `{"Implements": ["NetworkDriver"]}`
// LocalScope is the correct scope response for a local scope driver
LocalScope = `local`
// GlobalScope is the correct scope response for a global scope driver
Expand Down
17 changes: 9 additions & 8 deletions network/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ func (e *ErrDriver) Leave(r *LeaveRequest) error {
func TestMain(m *testing.M) {
d := &TestDriver{}
h1 := NewHandler(d)
go h1.ServeTCP("test", ":328234")
go h1.ServeTCP("test", ":32234")

e := &ErrDriver{}
h2 := NewHandler(e)
go h2.ServeTCP("err", ":328567")
go h2.ServeTCP("err", ":32567")

m.Run()
}

func TestActivate(t *testing.T) {
response, err := http.Get("http://localhost:328234/Plugin.Activate")
response, err := http.Get("http://localhost:32234/Plugin.Activate")
if err != nil {
t.Fatal(err)
}
Expand All @@ -101,22 +101,23 @@ func TestActivate(t *testing.T) {
}

func TestCapabilitiesExchange(t *testing.T) {
response, err := http.Get("http://localhost:328234/NetworkDriver.GetCapabilities")
response, err := http.Get("http://localhost:32234/NetworkDriver.GetCapabilities")
if err != nil {
t.Fatal(err)
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)

if string(body) != defaultScope+"\n" {
t.Fatalf("Expected %s, got %s\n", defaultScope+"\n", string(body))
expected := `{"Scope":"local"}`
if string(body) != expected+"\n" {
t.Fatalf("Expected %s, got %s\n", expected+"\n", string(body))
}
}

func TestCreateNetworkSuccess(t *testing.T) {
request := `{"NetworkID":"d76cfa51738e8a12c5eca71ee69e9d65010a4b48eaad74adab439be7e61b9aaf","Options":{"com.docker.network.generic":{}},"IPv4Data":[{"AddressSpace":"","Gateway":"172.18.0.1/16","Pool":"172.18.0.0/16"}],"IPv6Data":[]}`

response, err := http.Post("http://localhost:328234/NetworkDriver.CreateNetwork",
response, err := http.Post("http://localhost:32234/NetworkDriver.CreateNetwork",
sdk.DefaultContentTypeV1_1,
strings.NewReader(request),
)
Expand All @@ -136,7 +137,7 @@ func TestCreateNetworkSuccess(t *testing.T) {

func TestCreateNetworkError(t *testing.T) {
request := `{"NetworkID":"d76cfa51738e8a12c5eca71ee69e9d65010a4b48eaad74adab439be7e61b9aaf","Options":{"com.docker.network.generic": {}},"IPv4Data":[{"AddressSpace":"","Gateway":"172.18.0.1/16","Pool":"172.18.0.0/16"}],"IPv6Data":[]}`
response, err := http.Post("http://localhost:328567/NetworkDriver.CreateNetwork",
response, err := http.Post("http://localhost:32567/NetworkDriver.CreateNetwork",
sdk.DefaultContentTypeV1_1,
strings.NewReader(request))
if err != nil {
Expand Down

0 comments on commit 2ec24c6

Please sign in to comment.