Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Moar tests. #235

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/docker/go-units v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/ghodss/yaml v1.0.0
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/gorilla/mux v1.7.4 // indirect
github.com/imdario/mergo v0.3.9
github.com/mitchellh/go-homedir v1.1.0
Expand All @@ -20,6 +21,7 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/pelletier/go-toml v1.7.0 // indirect
github.com/smartystreets/assertions v1.1.1 // indirect
github.com/smartystreets/goconvey v1.6.4
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
Expand Down Expand Up @@ -203,6 +205,8 @@ github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.1.1 h1:T/YLemO5Yp7KPzS+lVtu+WsHn8yoSwTfItdAd1r3cck=
github.com/smartystreets/assertions v1.1.1/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand Down
34 changes: 34 additions & 0 deletions service/dnsmasq/dnsmasq_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package dnsmasq_test

import (
"fmt"
"testing"

"github.com/docker/go-connections/nat"
"github.com/fubarhouse/pygmy-go/service/dnsmasq"
. "github.com/smartystreets/goconvey/convey"
)

// This example creates a Service with the default values for dnsmasq.
func Example() {
dnsmasq.New()
}

func Test(t *testing.T) {
Convey("DNSMasq: Field equality tests...", t, func() {
obj := dnsmasq.New()

So(obj.Config.Image, ShouldEqual, "andyshinn/dnsmasq:2.78")
So(fmt.Sprint(obj.Config.Cmd), ShouldEqual, fmt.Sprint([]string{"-A", "/docker.amazee.io/127.0.0.1"}))
So(obj.Config.Labels["pygmy.defaults"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.enable"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.name"], ShouldEqual, "amazeeio-dnsmasq")
So(obj.Config.Labels["pygmy.weight"], ShouldEqual, "13")
So(obj.HostConfig.AutoRemove, ShouldBeFalse)
So(fmt.Sprint(obj.HostConfig.CapAdd), ShouldEqual, fmt.Sprint([]string{"NET_ADMIN"}))
So(obj.HostConfig.IpcMode, ShouldEqual, "private")
So(fmt.Sprint(obj.HostConfig.PortBindings), ShouldEqual, fmt.Sprint(nat.PortMap{"53/tcp": []nat.PortBinding{{HostIP: "", HostPort: "6053",},}, "53/udp": []nat.PortBinding{{HostIP: "", HostPort: "6053"}}}))
So(obj.HostConfig.RestartPolicy.Name, ShouldEqual, "on-failure")
So(obj.HostConfig.RestartPolicy.MaximumRetryCount, ShouldBeZeroValue)
})
}
19 changes: 19 additions & 0 deletions service/endpoint/endpoint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package endpoint_test

import (
"testing"

"github.com/fubarhouse/pygmy-go/service/endpoint"
. "github.com/smartystreets/goconvey/convey"
)

func Example() {
endpoint.Validate("http://127.0.0.1:8080")
}

func Test(t *testing.T) {
Convey("URL Endpoint tests...", t, func() {
valid := endpoint.Validate("https://www.golang.org/")
So(valid, ShouldBeTrue)
})
}
36 changes: 36 additions & 0 deletions service/haproxy/haproxy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package haproxy_test

import (
"fmt"
"testing"

"github.com/docker/go-connections/nat"
"github.com/fubarhouse/pygmy-go/service/haproxy"
. "github.com/smartystreets/goconvey/convey"
)

// This example creates a Service with the default values for haproxy.
func Example() {
haproxy.New()
haproxy.NewDefaultPorts()
}

func Test(t *testing.T) {
Convey("HAProxy: Field equality tests...", t, func() {
obj := haproxy.New()
objPorts := haproxy.NewDefaultPorts()
So(obj.Config.Image, ShouldEqual, "amazeeio/haproxy")
So(obj.Config.Labels["pygmy.defaults"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.enable"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.name"], ShouldEqual, "amazeeio-haproxy")
So(obj.Config.Labels["pygmy.network"], ShouldEqual, "amazeeio-network")
So(obj.Config.Labels["pygmy.url"], ShouldEqual, "http://docker.amazee.io/stats")
So(obj.Config.Labels["pygmy.weight"], ShouldEqual, "14")
So(obj.HostConfig.AutoRemove, ShouldBeFalse)
So(fmt.Sprint(obj.HostConfig.Binds), ShouldEqual, fmt.Sprint([]string{"/var/run/docker.sock:/tmp/docker.sock"}))
So(obj.HostConfig.PortBindings, ShouldEqual, nil)
So(obj.HostConfig.RestartPolicy.Name, ShouldEqual, "on-failure")
So(obj.HostConfig.RestartPolicy.MaximumRetryCount, ShouldEqual, 0)
So(fmt.Sprint(objPorts.HostConfig.PortBindings), ShouldEqual, fmt.Sprint(nat.PortMap{"80/tcp": []nat.PortBinding{{HostIP: "", HostPort: "80"}}}))
})
}
38 changes: 38 additions & 0 deletions service/mailhog/mailhog_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package mailhog_test

import (
"fmt"
"testing"

"github.com/docker/go-connections/nat"
"github.com/fubarhouse/pygmy-go/service/mailhog"
. "github.com/smartystreets/goconvey/convey"
)

// This example creates a Service with the default values for mailhog.
func Example() {
mailhog.New()
mailhog.NewDefaultPorts()
}

func Test(t *testing.T) {
Convey("MailHog: Field equality tests...", t, func() {
obj := mailhog.New()
objPorts := mailhog.NewDefaultPorts()
So(obj.Config.User, ShouldEqual, "0")
So(obj.Config.Image, ShouldEqual, "mailhog/mailhog")
So(fmt.Sprint(obj.Config.ExposedPorts), ShouldEqual, fmt.Sprint(nat.PortSet{"80/tcp": struct{}{}, "1025/tcp": struct{}{}, "8025/tcp": struct{}{}}))
So(fmt.Sprint(obj.Config.Env), ShouldEqual, fmt.Sprint([]string{"MH_UI_BIND_ADDR=0.0.0.0:80", "MH_API_BIND_ADDR=0.0.0.0:80", "AMAZEEIO=AMAZEEIO", "AMAZEEIO_URL=mailhog.docker.amazee.io"}))
So(obj.Config.Labels["pygmy.defaults"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.enable"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.name"], ShouldEqual, "amazeeio-mailhog")
So(obj.Config.Labels["pygmy.network"], ShouldEqual, "amazeeio-network")
So(obj.Config.Labels["pygmy.url"], ShouldEqual, "http://mailhog.docker.amazee.io")
So(obj.Config.Labels["pygmy.weight"], ShouldEqual, "15")
So(obj.HostConfig.AutoRemove, ShouldBeFalse)
So(obj.HostConfig.PortBindings, ShouldEqual, nil)
So(obj.HostConfig.RestartPolicy.Name, ShouldEqual, "on-failure")
So(obj.HostConfig.RestartPolicy.MaximumRetryCount, ShouldEqual, 0)
So(fmt.Sprint(objPorts.HostConfig.PortBindings), ShouldEqual, fmt.Sprint(nat.PortMap{"1025/tcp": []nat.PortBinding{{HostIP: "", HostPort: "1025"}}}))
})
}
26 changes: 26 additions & 0 deletions service/network/network_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package network_test

import (
"fmt"
"testing"

"github.com/docker/docker/api/types/network"
n "github.com/fubarhouse/pygmy-go/service/network"
. "github.com/smartystreets/goconvey/convey"
)

// This example creates a Network with the default values for amazeeio-network.
func Example() {
n.New()
}

func Test(t *testing.T) {
Convey("Network: Field equality tests...", t, func() {
obj := n.New()
So(obj.Name, ShouldEqual, "amazeeio-network")
So(obj.IPAM.Driver, ShouldEqual, "")
So(obj.IPAM.Options, ShouldEqual, nil)
So(fmt.Sprint(obj.IPAM.Config), ShouldEqual, fmt.Sprint([]network.IPAMConfig{{Subnet: "10.99.99.0/24", Gateway: "10.99.99.1"}}))
So(fmt.Sprint(obj.Labels), ShouldEqual, fmt.Sprint(map[string]string{"pygmy.name": "amazeeio-network"}))
})
}
1 change: 1 addition & 0 deletions service/ssh/agent/ssh_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func New() model.Service {
"pygmy.defaults": "true",
"pygmy.enable": "true",
"pygmy.name": "amazeeio-ssh-agent",
"pygmy.network": "amazeeio-network",
"pygmy.output": "false",
"pygmy.purpose": "sshagent",
"pygmy.weight": "30",
Expand Down
43 changes: 43 additions & 0 deletions service/ssh/agent/ssh_agent_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package agent_test

import (
"testing"

model "github.com/fubarhouse/pygmy-go/service/interface"
"github.com/fubarhouse/pygmy-go/service/ssh/agent"
. "github.com/smartystreets/goconvey/convey"
)

// This example creates a Service with the default values for the ssh agent.
func Example() {
agent.New()
}

// This example calls the function to list ssh keys in the ssh agent service.
func ExampleList() {
agent.List(model.Service{})
}

// This example calls the function to search ssh keys in the ssh agent service.
func ExampleSearch() {
agent.Search(model.Service{}, "id_rsa.pub")
}

func Test(t *testing.T) {
Convey("SSH Agent: Field equality tests...", t, func() {
obj := agent.New()
So(obj.Config.Image, ShouldEqual, "amazeeio/ssh-agent")
So(obj.Config.Labels["pygmy.defaults"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.enable"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.output"], ShouldEqual, "false")
So(obj.Config.Labels["pygmy.name"], ShouldEqual, "amazeeio-ssh-agent")
So(obj.Config.Labels["pygmy.network"], ShouldEqual, "amazeeio-network")
So(obj.Config.Labels["pygmy.purpose"], ShouldEqual, "sshagent")
So(obj.Config.Labels["pygmy.weight"], ShouldEqual, "30")
So(obj.HostConfig.AutoRemove, ShouldBeFalse)
So(obj.HostConfig.IpcMode, ShouldEqual, "private")
So(obj.HostConfig.PortBindings, ShouldEqual, nil)
So(obj.HostConfig.RestartPolicy.Name, ShouldEqual, "on-failure")
So(obj.HostConfig.RestartPolicy.MaximumRetryCount, ShouldEqual, 0)
})
}
28 changes: 1 addition & 27 deletions service/ssh/key/ssh_addkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func NewAdder() model.Service {
"pygmy.defaults": "true",
"pygmy.enable": "true",
"pygmy.name": "amazeeio-ssh-agent-add-key",
"pygmy.network": "amazeeio-network",
"pygmy.discrete": "true",
"pygmy.output": "false",
"pygmy.purpose": "addkeys",
Expand All @@ -31,30 +32,3 @@ func NewAdder() model.Service {
NetworkConfig: network.NetworkingConfig{},
}
}

// NewShower will provide the standard object for the SSH key shower container.
func NewShower() model.Service {
return model.Service{
Config: container.Config{
Image: "amazeeio/ssh-agent",
Cmd: []string{
"ssh-add",
"-L",
},
Labels: map[string]string{
"pygmy.defaults": "true",
"pygmy.enable": "true",
"pygmy.name": "amazeeio-ssh-agent-show-keys",
"pygmy.discrete": "true",
"pygmy.output": "false",
"pygmy.purpose": "showkeys",
"pygmy.weight": "32",
},
},
HostConfig: container.HostConfig{
AutoRemove: true,
VolumesFrom: []string{"amazeeio-ssh-agent"},
},
NetworkConfig: network.NetworkingConfig{},
}
}
32 changes: 32 additions & 0 deletions service/ssh/key/ssh_addkey_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package key_test

import (
"fmt"
"testing"

"github.com/fubarhouse/pygmy-go/service/ssh/key"
. "github.com/smartystreets/goconvey/convey"
)

// This example creates a Service with the default values for the key adder.
func ExampleAdd() {
key.NewAdder()
}

func TestAdd(t *testing.T) {
Convey("SSH Key Adder: Field equality tests...", t, func() {
obj := key.NewAdder()
So(obj.Config.Image, ShouldEqual, "amazeeio/ssh-agent")
So(obj.Config.Labels["pygmy.defaults"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.enable"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.output"], ShouldEqual, "false")
So(obj.Config.Labels["pygmy.discrete"], ShouldEqual, "true")
So(obj.Config.Labels["pygmy.name"], ShouldEqual, "amazeeio-ssh-agent-add-key")
So(obj.Config.Labels["pygmy.network"], ShouldEqual, "amazeeio-network")
So(obj.Config.Labels["pygmy.purpose"], ShouldEqual, "addkeys")
So(obj.Config.Labels["pygmy.weight"], ShouldEqual, "31")
So(obj.HostConfig.AutoRemove, ShouldBeTrue)
So(obj.HostConfig.IpcMode, ShouldEqual, "private")
So(fmt.Sprint(obj.HostConfig.VolumesFrom), ShouldEqual, fmt.Sprint([]string{"amazeeio-ssh-agent"}))
})
}
28 changes: 1 addition & 27 deletions service/ssh/key/ssh_addkey_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func NewAdder() model.Service {
"pygmy.defaults": "true",
"pygmy.enable": "true",
"pygmy.name": "amazeeio-ssh-agent-add-key",
"pygmy.network": "amazeeio-network",
"pygmy.discrete": "true",
"pygmy.output": "false",
"pygmy.purpose": "addkeys",
Expand All @@ -31,30 +32,3 @@ func NewAdder() model.Service {
NetworkConfig: network.NetworkingConfig{},
}
}

// NewShower will provide the standard object for the SSH key shower container.
func NewShower() model.Service {
return model.Service{
Config: container.Config{
Image: "amazeeio/ssh-agent",
Cmd: []string{
"ssh-add",
"-L",
},
Labels: map[string]string{
"pygmy.defaults": "true",
"pygmy.enable": "true",
"pygmy.name": "amazeeio-ssh-agent-show-keys",
"pygmy.discrete": "true",
"pygmy.output": "false",
"pygmy.purpose": "showkeys",
"pygmy.weight": "32",
},
},
HostConfig: container.HostConfig{
AutoRemove: true,
VolumesFrom: []string{"amazeeio-ssh-agent"},
},
NetworkConfig: network.NetworkingConfig{},
}
}
38 changes: 38 additions & 0 deletions service/ssh/key/ssh_showkeys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// +build darwin linux

package key

import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
model "github.com/fubarhouse/pygmy-go/service/interface"
)

// NewShower will provide the standard object for the SSH key shower container.
func NewShower() model.Service {
return model.Service{
Config: container.Config{
Image: "amazeeio/ssh-agent",
Cmd: []string{
"ssh-add",
"-L",
},
Labels: map[string]string{
"pygmy.defaults": "true",
"pygmy.enable": "true",
"pygmy.name": "amazeeio-ssh-agent-show-keys",
"pygmy.network": "amazeeio-network",
"pygmy.discrete": "true",
"pygmy.output": "false",
"pygmy.purpose": "showkeys",
"pygmy.weight": "32",
},
},
HostConfig: container.HostConfig{
AutoRemove: true,
IpcMode: "private",
VolumesFrom: []string{"amazeeio-ssh-agent"},
},
NetworkConfig: network.NetworkingConfig{},
}
}
Loading