Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint issues #137

Merged
merged 4 commits into from
Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions testing/def/definitions.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package def

// ConfigFileName is name of config file for 1build
const ConfigFileName string = "1build.yaml"
2 changes: 1 addition & 1 deletion testing/fixtures/command_init_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
)

func FeatureInitTestsData() []Test {
func featureInitTestsData() []Test {
feature := "init"
return []Test{
shouldInitialiseNewProject(feature),
Expand Down
2 changes: 1 addition & 1 deletion testing/fixtures/command_list_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
)

func FeatureListTestData() []Test {
func featureListTestData() []Test {
var feature = "list"
return []Test{
shouldShowListOfCommands(feature),
Expand Down
2 changes: 1 addition & 1 deletion testing/fixtures/command_root_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
)

func FeatureRootTestData() []Test {
func featureRootTestData() []Test {
feature := "root"

return []Test{
Expand Down
6 changes: 3 additions & 3 deletions testing/fixtures/command_set_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
)

func FeatureSetTestsData() []Test {
func featureSetTestsData() []Test {
feature := "set"

return []Test{
Expand All @@ -30,13 +30,13 @@ commands:
expectedOutput := `project: Sample Project
commands:
- build: go build
- test: go test
- Test: go Test
`

return Test{
Feature: feature,
Name: "shouldSetNewCommand",
CmdArgs: []string{"set", "test", "go test"},
CmdArgs: []string{"set", "Test", "go Test"},
Setup: func(dir string) error {
return utils.CreateConfigFile(dir, defaultFileContent)
},
Expand Down
24 changes: 12 additions & 12 deletions testing/fixtures/command_unset_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"testing"
)

func FeatureUnsetTestsData() []Test {
func featureUnsetTestsData() []Test {
feature := "unset"

return []Test{
shouldUnsetTheExistingCommand(feature),
UnsetShouldFailWhenConfigurationFileIsNotFound(feature),
UnsetShouldFailWhenConfigurationFileIsInInvalidFormat(feature),
UnsetShouldFailWhenCommandIsNotFound(feature),
unsetShouldFailWhenConfigurationFileIsNotFound(feature),
unsetShouldFailWhenConfigurationFileIsInInvalidFormat(feature),
unsetShouldFailWhenCommandIsNotFound(feature),
}
}

Expand Down Expand Up @@ -47,7 +47,7 @@ commands: []
}
}

func UnsetShouldFailWhenCommandIsNotFound(feature string) Test {
func unsetShouldFailWhenCommandIsNotFound(feature string) Test {

defaultFileContent := `
project: Sample Project
Expand All @@ -57,32 +57,32 @@ commands:

return Test{
Feature: feature,
Name: "UnsetShouldFailWhenCommandIsNotFound",
CmdArgs: []string{"unset", "test"},
Name: "unsetShouldFailWhenCommandIsNotFound",
CmdArgs: []string{"unset", "Test"},
Setup: func(dir string) error {
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
return assert.Contains(t, actualOutput, "Command 'test' not found")
return assert.Contains(t, actualOutput, "Command 'Test' not found")
},
}
}

func UnsetShouldFailWhenConfigurationFileIsNotFound(feature string) Test {
func unsetShouldFailWhenConfigurationFileIsNotFound(feature string) Test {
return Test{
Feature: feature,
Name: "UnsetShouldFailWhenConfigurationFileIsNotFound",
Name: "unsetShouldFailWhenConfigurationFileIsNotFound",
CmdArgs: []string{"unset", "build"},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
return assert.Contains(t, actualOutput, "no '"+def.ConfigFileName+"' file found in current directory")
},
}
}

func UnsetShouldFailWhenConfigurationFileIsInInvalidFormat(feature string) Test {
func unsetShouldFailWhenConfigurationFileIsInInvalidFormat(feature string) Test {
return Test{
Feature: feature,
Name: "UnsetShouldFailWhenConfigurationFileIsInInvalidFormat",
Name: "unsetShouldFailWhenConfigurationFileIsInInvalidFormat",
CmdArgs: []string{"unset", "build"},
Setup: func(dir string) error {
return utils.CreateConfigFile(dir, "invalid config content")
Expand Down
4 changes: 1 addition & 3 deletions testing/fixtures/execute_cmd_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"testing"
)

var Execute = "execute"

func FeatureExecuteCmdTestData() []Test {
func featureExecuteCmdTestData() []Test {
feature := "exec"

return []Test{
Expand Down
28 changes: 15 additions & 13 deletions testing/fixtures/fixures.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@ package fixtures

import "testing"

type Setup func(dir string) error
type Assertion func(dir string, actualOutput string, t *testing.T) bool
type Teardown func(dir string) error
type setup func(dir string) error
type assertion func(dir string, actualOutput string, t *testing.T) bool
type teardown func(dir string) error

//Test represents all the necessary information to run the test case
type Test struct {
Feature string
Name string
CmdArgs []string
Setup Setup
Assertion Assertion
Teardown Teardown
Setup setup
Assertion assertion
Teardown teardown
}

// GetFixtures returns all the fixtures to be tested
func GetFixtures() []Test {

routes := [][]Test{
FeatureRootTestData(),
FeatureExecuteCmdTestData(),
featureRootTestData(),
featureExecuteCmdTestData(),

FeatureInitTestsData(),
FeatureListTestData(),
FeatureSetTestsData(),
FeatureUnsetTestsData(),
featureInitTestsData(),
featureListTestData(),
featureSetTestsData(),
featureUnsetTestsData(),

FeatureFlagVersionTestData(),
featureFlagVersionTestData(),
}

var r1 []Test
Expand Down
2 changes: 1 addition & 1 deletion testing/fixtures/flag_version_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

func FeatureFlagVersionTestData() []Test {
func featureFlagVersionTestData() []Test {
feature := "version"
return []Test{
shouldPrintCurrentVersion(feature),
Expand Down
4 changes: 4 additions & 0 deletions testing/utils/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ import (
"os"
)

// CreateConfigFile creates a config file
func CreateConfigFile(dir string, content string) error {
return ioutil.WriteFile(dir+"/"+def.ConfigFileName, []byte(content), 0777)
}

// CreateTempDir created temporary directory
func CreateTempDir() (string, error) {
return ioutil.TempDir("", "onebuild_test")
}

// RemoveAllFilesFromDir Cleans up the directory
func RemoveAllFilesFromDir(dir string) {
_ = os.RemoveAll(dir)
}

// RecreateTestResourceDirectory cleans up test resources and recreates it
func RecreateTestResourceDirectory(dir string) string {
restResourceDirectory := dir + "/resources"
RemoveAllFilesFromDir(restResourceDirectory)
Expand Down