-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmain_test.go
More file actions
108 lines (84 loc) · 2.76 KB
/
main_test.go
File metadata and controls
108 lines (84 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
// parseProjectDir
func Test_GivenCustomDirProvided_WhenParseProjectDirCalled_ThenExpectCustomDir(t *testing.T) {
// Given
expectedDir := "/customDir"
customOptions := []string{"--project-directory", expectedDir}
// When
acutalProjectDir := parseProjectDir("/originalDir", customOptions)
//Then
assert.Equal(t, expectedDir, acutalProjectDir)
}
func Test_GivenCustomDirNotProvided_WhenParseProjectDirCalled_ThenExpectOriginalDir(t *testing.T) {
// Given
expectedDir := "/originalDir"
customOptions := []string{"--someparam", `"some value"`}
// When
acutalProjectDir := parseProjectDir(expectedDir, customOptions)
//Then
assert.Equal(t, expectedDir, acutalProjectDir)
}
// parseCarthageOptions
func Test_WhenParseCarthageOptionsCalled_ThenExpectCorrectValue(t *testing.T) {
// Given
expectedOpts := []string{"--parameter", "value"}
options := Config{
CarthageOptions: "--parameter value",
}
// When
actualOpts := parseCarthageOptions(options)
// Then
assert.Equal(t, expectedOpts, actualOpts)
}
// parseXCConfigPath
func Test_GivenXCConfigAsInputAndFileProviderSucceeds_WhenParseXCConfigPathCalled_ThenExpectPath(t *testing.T) {
// Given
expectedPath := "/path/from/input.xcconfig"
mockFileProvider := givenMockFileProvider().
GivenLocalPathSucceeds(expectedPath)
// When
actualPath, err := parseXCConfigPath(expectedPath, "", mockFileProvider)
// Then
assert.NoError(t, err)
assert.Equal(t, expectedPath, actualPath)
}
func Test_GivenXCConfigAsInputAndFileProviderFails_WhenParseXCConfigPathCalled_ThenExpectError(t *testing.T) {
// Given
expectedError := errors.New("sad error")
mockFileProvider := givenMockFileProvider().
GivenLocalPathFails(expectedError)
// When
actualPath, actualErr := parseXCConfigPath("whatever", "", mockFileProvider)
// Then
assert.EqualError(t, expectedError, actualErr.Error())
assert.Empty(t, actualPath)
}
func Test_GivenBothXCConfigAsInputAndEnvPassed_WhenParseXCConfigPathCalled_ThenExpectPathFromInput(t *testing.T) {
// Given
expectedPath := "/path/from/input.xcconfig"
envPath := "/path/from/env.xcconfig"
mockFileProvider := givenMockFileProvider().
GivenLocalPathSucceeds(expectedPath)
// When
actualPath, err := parseXCConfigPath(expectedPath, envPath, mockFileProvider)
// Then
assert.NoError(t, err)
assert.Equal(t, expectedPath, actualPath)
}
func Test_GivenXCConfigAsEnvPassed_WhenParseXCConfigPathCalled_ThenExpectPath(t *testing.T) {
// Given
expectedPath := "/path/from/env.xcconfig"
// When
actualPath, err := parseXCConfigPath("", expectedPath, nil)
// Then
assert.NoError(t, err)
assert.Equal(t, expectedPath, actualPath)
}
func givenMockFileProvider() *MockFileProvider {
return new(MockFileProvider)
}