-
Notifications
You must be signed in to change notification settings - Fork 2
/
config_test.go
75 lines (68 loc) · 1.58 KB
/
config_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
package bunnystorage_test
import (
"testing"
"git.sr.ht/~jamesponddotco/bunnystorage-go"
)
func TestConfig_AccessKey(t *testing.T) {
t.Parallel()
tests := []struct {
name string
config *bunnystorage.Config
operation bunnystorage.Operation
expectedKey string
}{
{
name: "Read operation with read-only key available",
config: &bunnystorage.Config{
Key: "main-key",
ReadOnlyKey: "read-only-key",
},
operation: bunnystorage.OperationRead,
expectedKey: "read-only-key",
},
{
name: "Read operation without read-only key",
config: &bunnystorage.Config{
Key: "main-key",
},
operation: bunnystorage.OperationRead,
expectedKey: "main-key",
},
{
name: "Write operation with read-only key available",
config: &bunnystorage.Config{
Key: "main-key",
ReadOnlyKey: "read-only-key",
},
operation: bunnystorage.OperationWrite,
expectedKey: "main-key",
},
{
name: "Write operation without read-only key",
config: &bunnystorage.Config{
Key: "main-key",
},
operation: bunnystorage.OperationWrite,
expectedKey: "main-key",
},
{
name: "No keys available",
config: &bunnystorage.Config{
Key: "",
ReadOnlyKey: "",
},
operation: bunnystorage.OperationRead,
expectedKey: "",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
accessKey := tt.config.AccessKey(tt.operation)
if accessKey != tt.expectedKey {
t.Errorf("Expected access key %s, but got %s", tt.expectedKey, accessKey)
}
})
}
}