Skip to content

Commit

Permalink
ADD CONTAINS
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachid Zarouali committed Jan 3, 2016
1 parent c475dfa commit 83aa82f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions build/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ RUN useradd -d /home/mario -m -s /bin/bash mario

COPY words /usr/local/tomcat/webapps/

RUN bash -c 'echo bar >> /tmp/foo.txt'

RUN apt-get update && apt-get install -y vim

USER mario
Expand Down
15 changes: 14 additions & 1 deletion build/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,22 @@ func Assert2Ephemeral(command *parser.Command) (*parser.Command, error) {
}
test += command.Args[2]
ephemeral.Args = append(ephemeral.Args, test)

case "CONTAINS":
if len(command.Args) != 4 {
return nil, fmt.Errorf("Condition %s accept one and only one argument (found %d)", "CONTAINS", len(command.Args)-3)
}
ephemeral.Args = append(ephemeral.Args, "bash", "-c")
test := "grep "
if command.Args[0] == commands.AssertFalse {
test += "! "
}
test += command.Args[2] + " " + command.Args[3]
ephemeral.Args = append(ephemeral.Args, test)


default:
return nil, fmt.Errorf("Condition %s is not supported. Only %s, %s, %s and %s are currently supported. Please open an issue if you want to add support for it.", command.Args[1], "USER_EXISTS", "FILE_EXISTS", "CURRENT_USER_IS", "IS_INSTALLED", "IS_RUNNING")
return nil, fmt.Errorf("Condition %s is not supported. Only %s, %s, %s and %s are currently supported. Please open an issue if you want to add support for it.", command.Args[1], "USER_EXISTS", "FILE_EXISTS", "CURRENT_USER_IS", "IS_INSTALLED", "IS_RUNNING", "CONTAINS")
}

return ephemeral, nil
Expand Down
6 changes: 4 additions & 2 deletions build/tester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestNewTester(t *testing.T) {
t.Errorf("Failed to test file %s", tests)
}

if blockNum := len(tests.testBlocks); blockNum != 8 {
t.Errorf("Expected 8 blocks, found %d", blockNum)
if blockNum := len(tests.testBlocks); blockNum != 9 {
t.Errorf("Expected 9 blocks, found %d", blockNum)
}
}

Expand All @@ -40,6 +40,8 @@ func TestInjection(t *testing.T) {
{Args: []string{"EPHEMERAL", "bash", "-c", "test ! -f /usr/local/tomcat/webapps/words"}},
{Args: []string{"COPY", "words", "/usr/local/tomcat/webapps/"}},
{Args: []string{"EPHEMERAL", "bash", "-c", "test -f /usr/local/tomcat/webapps/words"}},
{Args: []string{"RUN", "bash", "-c", "echo bar >> /tmp/foo.txt"}},
{Args: []string{"EPHEMERAL", "bash", "-c", "grep bar /tmp/foo.txt"}},
// {Args: []string{"EPHEMERAL", "bash", "-c", "test ! \"$(dpkg-query -W -f='${Status}' vim)\" = \"install ok installed\""}},
{Args: []string{"EPHEMERAL", "bash", "-c", "! command -v \"vim\" 1>/dev/null 2>&1"}},
{Args: []string{"RUN", "apt-get", "update", "&&", "apt-get", "install", "-y", "vim"}},
Expand Down
3 changes: 3 additions & 0 deletions build/testfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ ASSERT_FALSE FILE_EXISTS '/usr/local/tomcat/webapps/words'
@AFTER COPY_WORDS
ASSERT_TRUE FILE_EXISTS '/usr/local/tomcat/webapps/words'

@AFTER RUN_BASH
ASSERT_TRUE CONTAINS 'bar' '/tmp/foo.txt'

@BEFORE RUN_APT
ASSERT_FALSE IS_INSTALLED 'vim'

Expand Down

0 comments on commit 83aa82f

Please sign in to comment.