Skip to content

Commit e37a86f

Browse files
committed
Add trail 'ps' test
1 parent 01bbeca commit e37a86f

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

ecs-cli/integ/ps_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// +build integ
2+
3+
// Copyright 2015-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
6+
// not use this file except in compliance with the License. A copy of the
7+
// License is located at
8+
//
9+
// http://aws.amazon.com/apache2.0/
10+
//
11+
// or in the "license" file accompanying this file. This file is distributed
12+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
// express or implied. See the License for the specific language governing
14+
// permissions and limitations under the License.
15+
16+
package integ
17+
18+
import (
19+
"bytes"
20+
"io"
21+
"os/exec"
22+
"regexp"
23+
"runtime"
24+
"strings"
25+
"testing"
26+
27+
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/cli/compose/container"
28+
"github.com/stretchr/testify/assert"
29+
)
30+
31+
const (
32+
binaryPath = "../../bin/local/ecs-cli"
33+
)
34+
35+
// Test executes against previously built binary and
36+
// assumes the currently configured cluster contains 3 running containers
37+
func TestDescribeRunningContainers(t *testing.T) {
38+
39+
// setup set cmd
40+
cmdPath := binaryPath
41+
42+
if runtime.GOOS == "windows" {
43+
cmdPath = cmdPath + ".exe"
44+
}
45+
cmd := exec.Command(cmdPath, "ps")
46+
47+
var stdoutWriter bytes.Buffer
48+
writer := io.MultiWriter(&stdoutWriter)
49+
50+
cmd.Stdout = writer
51+
52+
// execute command
53+
err := cmd.Run()
54+
assert.NoError(t, err, "Unexpected error starting 'ps'")
55+
56+
// assert on result
57+
actualStdout := stdoutWriter.String()
58+
assert.NotEmpty(t, actualStdout)
59+
60+
stdoutLines := strings.Split(actualStdout, "\n")
61+
length := len(stdoutLines)
62+
assert.Empty(t, stdoutLines[length-1])
63+
stdoutLines = stdoutLines[:length-1] // trim off empty row
64+
65+
headers := getRowValues(stdoutLines[0])
66+
assert.Equal(t, container.ContainerInfoColumns, headers)
67+
68+
runningContainers := stdoutLines[1:]
69+
assert.Equal(t, 3, len(runningContainers))
70+
}
71+
72+
func getRowValues(row string) []string {
73+
spaces := regexp.MustCompile(`\s+`)
74+
return strings.Split(spaces.ReplaceAllString(row, " "), " ")
75+
}

0 commit comments

Comments
 (0)