Skip to content

Commit

Permalink
Add test for multiple unset command
Browse files Browse the repository at this point in the history
  • Loading branch information
boonwj committed Sep 26, 2019
1 parent caf4366 commit 32331d4
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions testing/fixtures/command_unset_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func featureUnsetTestsData() []Test {
unsetShouldFailWhenConfigurationFileIsNotFound(feature),
unsetShouldFailWhenConfigurationFileIsInInvalidFormat(feature),
unsetShouldFailWhenCommandIsNotFound(feature),
shouldUnsetMultipleCommands(feature),
shouldUnsetMultipleCommandsEvenWhenCommandIsNotFound(feature),
}
}

Expand Down Expand Up @@ -92,3 +94,65 @@ func unsetShouldFailWhenConfigurationFileIsInInvalidFormat(feature string) Test
},
}
}

func shouldUnsetMultipleCommands(feature string) Test {

defaultFileContent := `
project: Sample Project
commands:
- build: go build
- test: go test
`

expectedOutput := `project: Sample Project
commands: []
`

return Test{
Feature: feature,
Name: "shouldUnsetMultipleCommands",
CmdArgs: []string{"unset", "build", "test"},
Setup: func(dir string) error {
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
content, _ := ioutil.ReadFile(filePath)
return assert.Exactly(t, expectedOutput, string(content))
},
}
}

func shouldUnsetMultipleCommandsEvenWhenCommandIsNotFound(feature string) Test {

defaultFileContent := `
project: Sample Project
commands:
- build: go build
- test: go test
`

expectedOutput := `project: Sample Project
commands: []
`

return Test{
Feature: feature,
Name: "shouldUnsetMultipleCommands",
CmdArgs: []string{"unset", "build", "test", "missingCmd"},
Setup: func(dir string) error {
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
content, _ := ioutil.ReadFile(filePath)

testResult := assert.Contains(t, actualOutput, "Command 'missingCmd' not found") &&
assert.Exactly(t, expectedOutput, string(content))

return testResult
},
}
}

0 comments on commit 32331d4

Please sign in to comment.