-
Notifications
You must be signed in to change notification settings - Fork 18
/
main_test.go
158 lines (127 loc) · 3.53 KB
/
main_test.go
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package main
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestFindMostRootPodfile(t *testing.T) {
t.Log("single Podfile")
{
fileList := []string{
"./Podfile",
}
podfile, err := findMostRootPodfileInFileList(fileList)
require.NoError(t, err)
require.Equal(t, "./Podfile", podfile)
}
t.Log("single Podfile")
{
fileList := []string{
"/Users/bitrise/my/podfile/dir/Podfile",
}
podfile, err := findMostRootPodfileInFileList(fileList)
require.NoError(t, err)
require.Equal(t, "/Users/bitrise/my/podfile/dir/Podfile", podfile)
}
t.Log("lower case Podfile")
{
fileList := []string{
"/Users/bitrise/my/podfile/dir/podfile",
}
podfile, err := findMostRootPodfileInFileList(fileList)
require.NoError(t, err)
require.Equal(t, "/Users/bitrise/my/podfile/dir/podfile", podfile)
}
t.Log("multi case Podfile")
{
fileList := []string{
"/Users/bitrise/my/podfile/dir/poDfile",
}
podfile, err := findMostRootPodfileInFileList(fileList)
require.NoError(t, err)
require.Equal(t, "/Users/bitrise/my/podfile/dir/poDfile", podfile)
}
t.Log("multiple Podfile")
{
fileList := []string{
"/Users/bitrise/my/podfile/dir/Podfile",
"/Users/bitrise/my/dir/Podfile",
"/Users/bitrise/dir/Podfile",
}
podfile, err := findMostRootPodfileInFileList(fileList)
require.NoError(t, err)
require.Equal(t, "/Users/bitrise/dir/Podfile", podfile)
}
t.Log("multiple Podfile")
{
fileList := []string{
"./my/podfile/dir/Podfile",
"./my/dir/Podfile",
"./dir/Podfile",
"./",
}
podfile, err := findMostRootPodfileInFileList(fileList)
require.NoError(t, err)
require.Equal(t, "./dir/Podfile", podfile)
}
}
func TestCocoapodsVersionFromPodfileLockContent(t *testing.T) {
t.Log("Podfile.lock cocoapods")
{
content := `PODS:
- Alamofire (3.4.0)
DEPENDENCIES:
- Alamofire (~> 3.4)
SPEC CHECKSUMS:
Alamofire: c19a627cefd6a95f840401c49ab1f124e07f54ee
PODFILE CHECKSUM: f2a6f4eed25b89d16fc8e906af222b4e63afa6c3
COCOAPODS: 1.0.0
`
actual := cocoapodsVersionFromPodfileLockContent(content)
require.Equal(t, "1.0.0", actual)
}
t.Log("Podfile.lock without cocoapods")
{
content := `PODS:
- Alamofire (3.4.0)
DEPENDENCIES:
- Alamofire (~> 3.4)
SPEC CHECKSUMS:
Alamofire: c19a627cefd6a95f840401c49ab1f124e07f54ee
PODFILE CHECKSUM: f2a6f4eed25b89d16fc8e906af222b4e63afa6c3
`
actual := cocoapodsVersionFromPodfileLockContent(content)
require.Equal(t, "", actual)
}
}
func TestIsIncludedInGemfileLockVersionRanges(t *testing.T) {
t.Log("Match version")
{
gemfileLockVersion := "1.0.0"
isIncluded, err := isIncludedInGemfileLockVersionRanges("1.0.0", gemfileLockVersion)
require.NoError(t, err)
require.True(t, isIncluded)
isExcluded, err := isIncludedInGemfileLockVersionRanges("2.0.0", gemfileLockVersion)
require.NoError(t, err)
require.False(t, isExcluded)
}
t.Log("Specify version")
{
gemfileLockVersion := "~> 1.0.0"
isIncluded, err := isIncludedInGemfileLockVersionRanges("1.0.0", gemfileLockVersion)
require.NoError(t, err)
require.True(t, isIncluded)
isExcluded, err := isIncludedInGemfileLockVersionRanges("2.0.0", gemfileLockVersion)
require.NoError(t, err)
require.False(t, isExcluded)
}
t.Log("Range version")
{
gemfileLockVersion := ">= 1.0.0, < 2.0.0"
isIncluded, err := isIncludedInGemfileLockVersionRanges("1.0.0", gemfileLockVersion)
require.NoError(t, err)
require.True(t, isIncluded)
isExcluded, err := isIncludedInGemfileLockVersionRanges("2.0.0", gemfileLockVersion)
require.NoError(t, err)
require.False(t, isExcluded)
}
}