-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathauth_test.go
More file actions
52 lines (44 loc) · 1.44 KB
/
auth_test.go
File metadata and controls
52 lines (44 loc) · 1.44 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
package storage
import (
"testing"
"github.com/arschles/assert"
"github.com/deis/builder/pkg/sys"
)
func TestGetAuthEmptyAuth(t *testing.T) {
fs := sys.NewFakeFS()
creds, err := getAuth(fs)
assert.NoErr(t, err)
assert.Equal(t, *creds, emptyCreds, "returned credentials")
}
func TestGetAuthMissingSecret(t *testing.T) {
fs := sys.NewFakeFS()
fs.Files[accessSecretKeyFile] = []byte("hello world")
creds, err := getAuth(fs)
assert.Err(t, err, errMissingKey)
assert.True(t, creds == nil, "returned credentials were not nil")
}
func TestGetAuthMissingKey(t *testing.T) {
fs := sys.NewFakeFS()
fs.Files[accessKeyIDFile] = []byte("hello world")
creds, err := getAuth(fs)
assert.Err(t, err, errMissingSecret)
assert.True(t, creds == nil, "returned credentials were not nil")
}
func TestGetAuthSuccess(t *testing.T) {
fs := sys.NewFakeFS()
fs.Files[accessKeyIDFile] = []byte("stuff")
fs.Files[accessSecretKeyFile] = []byte("other stuff")
creds, err := getAuth(fs)
assert.NoErr(t, err)
assert.True(t, creds != nil, "creds were nil when they shouldn't have been")
}
func TestCredsOKFail(t *testing.T) {
fs := sys.NewFakeFS()
assert.False(t, CredsOK(fs), "true returned when there were no credentials")
}
func TestCredsOKSuccess(t *testing.T) {
fs := sys.NewFakeFS()
fs.Files[accessKeyIDFile] = []byte("stuff")
fs.Files[accessSecretKeyFile] = []byte("other stuff")
assert.True(t, CredsOK(fs), "false returned when there were valid credentials")
}