-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathload_source_test.go
76 lines (55 loc) · 2.44 KB
/
load_source_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 sourcedir
import (
"github.com/apuigsech/seekret"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"testing"
)
func TestLoadObjectsFromEmptyDirectoryReturnsNoContent(t *testing.T) {
tempDir, err := ioutil.TempDir("", "empty_directory")
sourceDir := SourceDir{}
loadOptions := seekret.LoadOptions{}
objectList, err := sourceDir.LoadObjects(tempDir, loadOptions)
assert.Nil(t, err, "Error should be nil")
assert.Empty(t, objectList, "ObjectList should be empty")
os.Remove(tempDir)
}
func TestLoadObjectsFromDirectoryWithHiddenFilesReturnsNoContent(t *testing.T) {
sourceDir := SourceDir{}
loadOptions := seekret.LoadOptions{}
objectList, err := sourceDir.LoadObjects("./testdata/dir_with_hidden_files", loadOptions)
assert.Nil(t, err, "Error should be nil")
assert.Empty(t, objectList, "ObjectList should be empty")
}
func TestLoadObjectsFromDirectoryWithHiddenFilesReturnsContentIfHiddenOptionIsSet(t *testing.T) {
sourceDir := SourceDir{}
loadOptions := seekret.LoadOptions{"hidden": true}
objectList, err := sourceDir.LoadObjects("./testdata/dir_with_hidden_files", loadOptions)
assert.Nil(t, err, "Error should be nil")
assert.NotEmpty(t, objectList, "ObjectList should not be empty")
assert.Len(t, objectList, 1, "Only one object should be present")
}
func TestLoadObjectsFromDirectoryWithTwoFilesReturnsTwoObjects(t *testing.T) {
sourceDir := SourceDir{}
loadOptions := seekret.LoadOptions{}
objectList, err := sourceDir.LoadObjects("./testdata/dir_with_two_files", loadOptions)
assert.Nil(t, err, "Error should be nil")
assert.NotEmpty(t, objectList, "ObjectList should not be empty")
assert.Len(t, objectList, 2, "Two objects should be present")
}
func TestLoadObjectsFromTwoLevelDirectoryThatContainsTwoFilesReturnsTwoObjectsIfRecursive(t *testing.T) {
sourceDir := SourceDir{}
loadOptions := seekret.LoadOptions{"recursive": true}
objectList, err := sourceDir.LoadObjects("./testdata/recursive_dir_with_two_files", loadOptions)
assert.Nil(t, err, "Error should be nil")
assert.NotEmpty(t, objectList, "ObjectList should not be empty")
assert.Len(t, objectList, 2, "Two objects should be present")
}
func TestLoadObjectsFromInvalidDirectoryShouldReturnAnError(t *testing.T) {
sourceDir := SourceDir{}
loadOptions := seekret.LoadOptions{}
objectList, err := sourceDir.LoadObjects("./testdata/invalid", loadOptions)
assert.NotNil(t, err, "Error should be nil")
assert.Empty(t, objectList, "ObjectList should be empty")
}