2015-05-23 16:05:48 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
2015-09-07 13:33:28 -04:00
|
|
|
_ "github.com/docker/libnetwork/testutils"
|
2015-05-23 16:05:48 -04:00
|
|
|
)
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
func TestClientServiceInvalidCommand(t *testing.T) {
|
2015-05-23 16:05:48 -04:00
|
|
|
var out, errOut bytes.Buffer
|
|
|
|
cli := NewNetworkCli(&out, &errOut, callbackFunc)
|
|
|
|
|
2015-06-08 07:17:24 -04:00
|
|
|
err := cli.Cmd("docker", "service", "invalid")
|
2015-05-23 16:05:48 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Passing invalid commands must fail")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
func TestClientServiceCreate(t *testing.T) {
|
2015-05-23 16:05:48 -04:00
|
|
|
var out, errOut bytes.Buffer
|
|
|
|
cli := NewNetworkCli(&out, &errOut, callbackFunc)
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
err := cli.Cmd("docker", "service", "publish", mockServiceName+"."+mockNwName)
|
2015-05-23 16:05:48 -04:00
|
|
|
if err != nil {
|
2015-06-11 11:30:45 -04:00
|
|
|
t.Fatal(err)
|
2015-05-23 16:05:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
func TestClientServiceRm(t *testing.T) {
|
2015-05-23 16:05:48 -04:00
|
|
|
var out, errOut bytes.Buffer
|
|
|
|
cli := NewNetworkCli(&out, &errOut, callbackFunc)
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
err := cli.Cmd("docker", "service", "unpublish", mockServiceName+"."+mockNwName)
|
2015-05-23 16:05:48 -04:00
|
|
|
if err != nil {
|
2015-06-11 11:30:45 -04:00
|
|
|
t.Fatal(err)
|
2015-05-23 16:05:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
func TestClientServiceLs(t *testing.T) {
|
2015-05-23 16:05:48 -04:00
|
|
|
var out, errOut bytes.Buffer
|
|
|
|
cli := NewNetworkCli(&out, &errOut, callbackFunc)
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
err := cli.Cmd("docker", "service", "ls")
|
2015-05-23 16:05:48 -04:00
|
|
|
if err != nil {
|
2015-06-11 11:30:45 -04:00
|
|
|
t.Fatal(err)
|
2015-05-23 16:05:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
func TestClientServiceInfo(t *testing.T) {
|
2015-05-23 16:05:48 -04:00
|
|
|
var out, errOut bytes.Buffer
|
|
|
|
cli := NewNetworkCli(&out, &errOut, callbackFunc)
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
err := cli.Cmd("docker", "service", "info", mockServiceName+"."+mockNwName)
|
2015-05-23 16:05:48 -04:00
|
|
|
if err != nil {
|
2015-06-11 11:30:45 -04:00
|
|
|
t.Fatal(err)
|
2015-05-23 16:05:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
func TestClientServiceInfoById(t *testing.T) {
|
2015-05-23 16:05:48 -04:00
|
|
|
var out, errOut bytes.Buffer
|
|
|
|
cli := NewNetworkCli(&out, &errOut, callbackFunc)
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
err := cli.Cmd("docker", "service", "info", mockServiceID+"."+mockNwName)
|
2015-05-23 16:05:48 -04:00
|
|
|
if err != nil {
|
2015-06-11 11:30:45 -04:00
|
|
|
t.Fatal(err)
|
2015-05-23 16:05:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
func TestClientServiceJoin(t *testing.T) {
|
2015-05-23 16:05:48 -04:00
|
|
|
var out, errOut bytes.Buffer
|
|
|
|
cli := NewNetworkCli(&out, &errOut, callbackFunc)
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
err := cli.Cmd("docker", "service", "attach", mockContainerID, mockServiceName+"."+mockNwName)
|
2015-05-23 16:05:48 -04:00
|
|
|
if err != nil {
|
2015-06-11 11:30:45 -04:00
|
|
|
t.Fatal(err)
|
2015-05-23 16:05:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 11:30:45 -04:00
|
|
|
func TestClientServiceLeave(t *testing.T) {
|
2015-05-23 16:05:48 -04:00
|
|
|
var out, errOut bytes.Buffer
|
|
|
|
cli := NewNetworkCli(&out, &errOut, callbackFunc)
|
|
|
|
|
2015-06-14 12:00:27 -04:00
|
|
|
err := cli.Cmd("docker", "service", "detach", mockContainerID, mockServiceName+"."+mockNwName)
|
2015-05-23 16:05:48 -04:00
|
|
|
if err != nil {
|
2015-06-11 11:30:45 -04:00
|
|
|
t.Fatal(err)
|
2015-05-23 16:05:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Docker Flag processing in flag.go uses os.Exit() frequently, even for --help
|
|
|
|
// TODO : Handle the --help test-case in the IT when CLI is available
|
|
|
|
/*
|
|
|
|
func TestClientNetworkServiceCreateHelp(t *testing.T) {
|
|
|
|
var out, errOut bytes.Buffer
|
|
|
|
cFunc := func(method, path string, data interface{}, headers map[string][]string) (io.ReadCloser, int, error) {
|
|
|
|
return nil, 0, nil
|
|
|
|
}
|
|
|
|
cli := NewNetworkCli(&out, &errOut, callbackFunc)
|
|
|
|
|
|
|
|
err := cli.Cmd("docker", "network", "create", "--help")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Docker flag processing in flag.go uses os.Exit(1) for incorrect parameter case.
|
|
|
|
// TODO : Handle the missing argument case in the IT when CLI is available
|
|
|
|
/*
|
|
|
|
func TestClientNetworkServiceCreateMissingArgument(t *testing.T) {
|
|
|
|
var out, errOut bytes.Buffer
|
|
|
|
cFunc := func(method, path string, data interface{}, headers map[string][]string) (io.ReadCloser, int, error) {
|
|
|
|
return nil, 0, nil
|
|
|
|
}
|
|
|
|
cli := NewNetworkCli(&out, &errOut, callbackFunc)
|
|
|
|
|
|
|
|
err := cli.Cmd("docker", "network", "create")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|