-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathio_test.go
76 lines (58 loc) · 2.56 KB
/
io_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
package io
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestProcessAllowedReposErrsOnBadFilepath(t *testing.T) {
t.Parallel()
intentionallyBadFilepath := "../data/test/i-am-not-really-here.sh"
allowedRepos, err := ProcessAllowedRepos(intentionallyBadFilepath)
assert.Error(t, err)
assert.Equal(t, len(allowedRepos), 0)
}
func TestProcessAllowedReposCorrectlyParsesValidReposFile(t *testing.T) {
t.Parallel()
filepathToValidReposFile := "../data/test/test-file-parsing.txt"
allowedRepos, err := ProcessAllowedRepos(filepathToValidReposFile)
assert.NoError(t, err)
assert.Equal(t, len(allowedRepos), 3)
// Test that repo names are correctly parsed from the flat file by initially setting a map of each repo name
// to false, and then updating each entry to true as we find them in the flat file. At the end, all map entries should be true / seen
mapOfExpectedRepoNames := make(map[string]bool)
mapOfExpectedRepoNames["fetch"] = false
mapOfExpectedRepoNames["cloud-nuke"] = false
mapOfExpectedRepoNames["bash-commons"] = false
// ensure all test repos have the correct gruntwork-io org
for _, repo := range allowedRepos {
assert.Equal(t, repo.Organization, "gruntwork-io")
// Update the map as having "seen" the repo
mapOfExpectedRepoNames[repo.Name] = true
}
for _, v := range mapOfExpectedRepoNames {
assert.True(t, v)
}
}
func TestProcessAllowedReposCorrectlyFiltersMalformedInput(t *testing.T) {
t.Parallel()
filepathToReposFileWithSomeMalformedRepos := "../data/test/mixed-test-repos.txt"
allowedRepos, err := ProcessAllowedRepos(filepathToReposFileWithSomeMalformedRepos)
assert.NoError(t, err)
// There are 3 valid repos defined in this test file, and 3 intentionally malformed repos, so only 3 should
// be returned by the function as valid repos to operate on
assert.Equal(t, len(allowedRepos), 3)
// Test that repo names are correctly parsed from the flat file by initially setting a map of each repo name
// to false, and then updating each entry to true as we find them in the flat file. At the end, all map entries should be true / seen
mapOfExpectedRepoNames := make(map[string]bool)
mapOfExpectedRepoNames["fetch"] = false
mapOfExpectedRepoNames["cloud-nuke"] = false
mapOfExpectedRepoNames["bash-commons"] = false
// ensure all test repos have the correct gruntwork-io org
for _, repo := range allowedRepos {
assert.Equal(t, repo.Organization, "gruntwork-io")
// Update the map as having "seen" the repo
mapOfExpectedRepoNames[repo.Name] = true
}
for _, v := range mapOfExpectedRepoNames {
assert.True(t, v)
}
}