Ejemplo n.º 1
0
func TestAutoAcceptOptionString(t *testing.T) {
	opt := NewAutoAcceptOption()
	assert.NilError(t, opt.Set("manager"))
	assert.NilError(t, opt.Set("worker"))

	repr := opt.String()
	assert.Contains(t, repr, "worker=true")
	assert.Contains(t, repr, "manager=true")
}
Ejemplo n.º 2
0
func TestRunCommandWithCombined(t *testing.T) {
	// TODO Windows: Port this test
	if runtime.GOOS == "windows" {
		t.Skip("Needs porting to Windows")
	}

	result := RunCommand("ls", "-a")
	result.Assert(t, Expected{})

	assert.Contains(t, result.Combined(), "..")
	assert.Contains(t, result.Stdout(), "..")
}
Ejemplo n.º 3
0
func TestPrint(t *testing.T) {
	var buffer bytes.Buffer
	bundle := &Bundlefile{
		Version: "0.1",
		Services: map[string]Service{
			"web": {
				Image:   "image",
				Command: []string{"echo", "something"},
			},
		},
	}
	assert.NilError(t, Print(&buffer, bundle))
	output := buffer.String()
	assert.Contains(t, output, "\"Image\": \"image\"")
	assert.Contains(t, output,
		`"Command": [
                "echo",
                "something"
            ]`)
}
Ejemplo n.º 4
0
func TestNodeListQuietShouldOnlyPrintIDs(t *testing.T) {
	buf := new(bytes.Buffer)
	cmd := newListCommand(
		test.NewFakeCli(&fakeClient{
			nodeListFunc: func() ([]swarm.Node, error) {
				return []swarm.Node{
					*Node(),
				}, nil
			},
		}, buf))
	cmd.Flags().Set("quiet", "true")
	assert.NilError(t, cmd.Execute())
	assert.Contains(t, buf.String(), "nodeID")
}
Ejemplo n.º 5
0
func TestNodeList(t *testing.T) {
	buf := new(bytes.Buffer)
	cmd := newListCommand(
		test.NewFakeCli(&fakeClient{
			nodeListFunc: func() ([]swarm.Node, error) {
				return []swarm.Node{
					*Node(NodeID("nodeID1"), Hostname("nodeHostname1"), Manager(Leader())),
					*Node(NodeID("nodeID2"), Hostname("nodeHostname2"), Manager()),
					*Node(NodeID("nodeID3"), Hostname("nodeHostname3")),
				}, nil
			},
			infoFunc: func() (types.Info, error) {
				return types.Info{
					Swarm: swarm.Info{
						NodeID: "nodeID1",
					},
				}, nil
			},
		}, buf))
	assert.NilError(t, cmd.Execute())
	assert.Contains(t, buf.String(), `nodeID1 *  nodeHostname1  Ready   Active        Leader`)
	assert.Contains(t, buf.String(), `nodeID2    nodeHostname2  Ready   Active        Reachable`)
	assert.Contains(t, buf.String(), `nodeID3    nodeHostname3  Ready   Active`)
}
Ejemplo n.º 6
0
func TestRunCommand(t *testing.T) {
	// TODO Windows: Port this test
	if runtime.GOOS == "windows" {
		t.Skip("Needs porting to Windows")
	}

	result := RunCommand("ls")
	result.Assert(t, Expected{})

	result = RunCommand("doesnotexists")
	expectedError := `exec: "doesnotexists": executable file not found`
	result.Assert(t, Expected{ExitCode: 127, Error: expectedError})

	result = RunCommand("ls", "-z")
	result.Assert(t, Expected{
		ExitCode: 2,
		Error:    "exit status 2",
		Err:      "invalid option",
	})
	assert.Contains(t, result.Combined(), "invalid option")
}
Ejemplo n.º 7
0
// Test case for #24090
func TestNodeListContainsHostname(t *testing.T) {
	buf := new(bytes.Buffer)
	cmd := newListCommand(test.NewFakeCli(&fakeClient{}, buf))
	assert.NilError(t, cmd.Execute())
	assert.Contains(t, buf.String(), "HOSTNAME")
}