|
1 | 1 | package config
|
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "os" |
| 6 | + "path" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/Schroedinger-Hat/Daje/constants" |
| 10 | +) |
| 11 | + |
| 12 | +const configNotExistsFileName = ".confignotexists" |
| 13 | + |
| 14 | +func Test_getConfigFilePathShouldPassWithNoErrorsWhenFindConfigurationFile(t *testing.T) { |
| 15 | + workingDirectory, _ := os.Getwd() |
| 16 | + constants.DajeBasePath = workingDirectory + "/../../testdata" |
| 17 | + |
| 18 | + _, err := getConfigFilePath() |
| 19 | + |
| 20 | + if err != nil { |
| 21 | + t.Fatalf("getConfigFilePath should pass with no errors when find configuration file: expected=\"\" - get=\"%v\"", err) |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +func Test_getConfigFilePathShouldReturnTheExactPathWhenItFindTheConfigurationFile(t *testing.T) { |
| 26 | + workingDirectory, _ := os.Getwd() |
| 27 | + constants.DajeBasePath = workingDirectory + "/../../testdata" |
| 28 | + expectedConfigPath := path.Join(constants.DajeBasePath, "../testdata/.config/daje", constants.DajeConfigFileName) |
| 29 | + |
| 30 | + path, _ := getConfigFilePath() |
| 31 | + |
| 32 | + if path != expectedConfigPath { |
| 33 | + t.Fatalf("getConfigFilePath should return the exact path when find configuration file: expected=%v - get=%v", expectedConfigPath, path) |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +func Test_getConfigFilePathShouldFailWhenDontFindConfigurationFile(t *testing.T) { |
| 38 | + constants.DajeConfigFileName = configNotExistsFileName |
| 39 | + |
| 40 | + _, err := getConfigFilePath() |
| 41 | + errExpected := errors.New("getConfigFilePath: Configuration not found") |
| 42 | + |
| 43 | + if err.Error() != errExpected.Error() { |
| 44 | + t.Fatalf("getConfigFilePath should fail when don't find configuration file: expected=%v - get=%v", errExpected, err) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +func Test_getConfigFilePathShouldHaveEmptyPathWhenDontFindConfigurationFile(t *testing.T) { |
| 49 | + constants.DajeConfigFileName = configNotExistsFileName |
| 50 | + path, _ := getConfigFilePath() |
| 51 | + |
| 52 | + if path != "" { |
| 53 | + t.Fatalf("getConfigFilePath should have empty path when don't find configuration file: expected=\"\" - get=%v", path) |
| 54 | + } |
| 55 | +} |
0 commit comments