forked from sendgridlabs/go-kinesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_test.go
66 lines (50 loc) · 1.5 KB
/
auth_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
package kinesis
import (
"os"
"testing"
)
func TestAuthInterfaceIsImplemented(t *testing.T) {
var auth Auth = &AuthCredentials{}
if auth == nil {
t.Error("Invalid nil auth credentials value")
}
}
func TestGetSecretKey(t *testing.T) {
auth := NewAuth("BAD_ACCESS_KEY", "BAD_SECRET_KEY")
if auth.GetAccessKey() != "BAD_ACCESS_KEY" {
t.Error("incorrect value for auth#accessKey")
}
}
func TestGetAccessKey(t *testing.T) {
auth := NewAuth("BAD_ACCESS_KEY", "BAD_SECRET_KEY")
if auth.GetSecretKey() != "BAD_SECRET_KEY" {
t.Error("incorrect value for auth#secretKey")
}
}
func TestNewAuthFromEnv(t *testing.T) {
os.Setenv(AccessEnvKey, "asdf")
os.Setenv(SecretEnvKey, "asdf")
auth, _ := NewAuthFromEnv()
if auth.GetAccessKey() != "asdf" {
t.Error("Expected AccessKey to be inferred as \"asdf\"")
}
if auth.GetSecretKey() != "asdf" {
t.Error("Expected SecretKey to be inferred as \"asdf\"")
}
// Validate that the fallback environment variables will also work
os.Setenv(AccessEnvKey, "") // Use Unsetenv with go1.4
os.Setenv(SecretEnvKey, "") // Use Unsetenv with go1.4
}
func TestNewAuthFromEnvWithFallbackVars(t *testing.T) {
os.Setenv(AccessEnvKeyId, "asdf")
os.Setenv(SecretEnvAccessKey, "asdf")
auth, _ := NewAuthFromEnv()
if auth.GetAccessKey() != "asdf" {
t.Error("Expected AccessKey to be inferred as \"asdf\"")
}
if auth.GetSecretKey() != "asdf" {
t.Error("Expected SecretKey to be inferred as \"asdf\"")
}
os.Setenv(AccessEnvKeyId, "")
os.Setenv(SecretEnvAccessKey, "")
}