Skip to content

Commit

Permalink
first pass at a docker system test
Browse files Browse the repository at this point in the history
Signed-off-by: kung-foo <github@jonathan.camp>
  • Loading branch information
kung-foo committed Mar 7, 2017
1 parent 118b87a commit 69989f1
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 0 deletions.
12 changes: 12 additions & 0 deletions system_test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.8-alpine

RUN apk update && apk add curl build-base iptables libpcap-dev "libnetfilter_queue-dev>=1.0.0" git gcc libc-dev linux-headers
RUN go get golang.org/x/net/bpf
RUN go get golang.org/x/net/context
RUN go get golang.org/x/net/proxy
RUN go get github.com/smartystreets/goconvey

WORKDIR /go/src/github.com/kung-foo/freki

RUN curl -s -L https://github.com/kung-foo/waitforit/releases/download/v0.0.1/waitforit-linux-amd64 > /bin/waitforit
RUN chmod +x /bin/waitforit
18 changes: 18 additions & 0 deletions system_test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.1'

services:
freki:
build: .
stop_signal: SIGINT
cap_add:
- NET_ADMIN
command: system_test/run_freki.sh
volumes:
- ../:/go/src/github.com/kung-foo/freki:ro
test:
build: .
command: system_test/run_test.sh
volumes:
- ../:/go/src/github.com/kung-foo/freki:ro
links:
- freki
9 changes: 9 additions & 0 deletions system_test/rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 1
rules:
- match: tcp port 80 or tcp port 8080
type: log_http
- match: tcp port 1337
type: proxy
target: tcp://port.party:666
- match:
type: passthrough
6 changes: 6 additions & 0 deletions system_test/run_freki.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env ash

set -ex

go build -o /tmp/freki app/main.go
exec /tmp/freki -v -i eth0 -r system_test/rules.yaml
8 changes: 8 additions & 0 deletions system_test/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env ash

set -ex

echo "Wating for freki to start..."
waitforit -r 60 -s http://freki:80

go test -v system_test/system_test.go
55 changes: 55 additions & 0 deletions system_test/system_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package system_test

import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"testing"

. "github.com/smartystreets/goconvey/convey"
)

func TestEndToEnd(t *testing.T) {
Convey("Given freki is working...", t, func() {
Convey("Port 80 and 8080 should return OK", func() {
f := func(p int) {
resp, err := http.Get(fmt.Sprintf("http://freki:%d/", p))

So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)

So(resp.StatusCode, ShouldEqual, 200)

body, err := ioutil.ReadAll(resp.Body)
So(err, ShouldBeNil)
So(bytes.Equal(body, []byte("OK\n")), ShouldBeTrue)
resp.Body.Close()
}

f(80)
f(8080)
})

Convey("Port 1137 should proxy to port.party:666", func() {
resp, err := http.Get("http://freki:1337/cors.json")
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)

So(resp.StatusCode, ShouldEqual, 200)

body, err := ioutil.ReadAll(resp.Body)
So(err, ShouldBeNil)

j := make(map[string]int)

So(json.Unmarshal(body, &j), ShouldBeNil)

So(j, ShouldContainKey, "Port")
So(j["Port"], ShouldEqual, 666)

resp.Body.Close()
})
})
}

0 comments on commit 69989f1

Please sign in to comment.