-
Notifications
You must be signed in to change notification settings - Fork 1
/
storage_test.go
74 lines (68 loc) · 1.71 KB
/
storage_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
package mfa
import (
"os"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
)
const TestTableName = "WebAuthn"
const DisableSSL = true
func (ms *MfaSuite) TestStorage_StoreLoad() {
type fields struct {
Table string
AwsSession *session.Session
AwsEndpoint string
AwsRegion string
AwsDisableSSL bool
PrimaryKeyAttribute string
}
type args struct {
key string
item interface{}
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{
name: "simple test",
fields: fields{
Table: TestTableName,
AwsEndpoint: os.Getenv("AWS_ENDPOINT"),
AwsRegion: os.Getenv("AWS_DEFAULT_REGION"),
AwsDisableSSL: DisableSSL,
PrimaryKeyAttribute: "uuid",
},
args: args{
key: "2B28BED1-1225-4EC9-98F9-EAB8FBCEDBA0",
item: &DynamoUser{
ID: "2B28BED1-1225-4EC9-98F9-EAB8FBCEDBA0",
Name: "test_user",
DisplayName: "Test User",
},
},
wantErr: false,
},
}
for _, tt := range tests {
ms.T().Run(tt.name, func(t *testing.T) {
s, err := NewStorage(&aws.Config{
Endpoint: aws.String(tt.fields.AwsEndpoint),
Region: aws.String(tt.fields.AwsRegion),
DisableSSL: aws.Bool(tt.fields.AwsDisableSSL),
})
ms.NoError(err)
err = s.Store(tt.fields.Table, tt.args.item)
if tt.wantErr {
ms.Error(err, "didn't get an expected error Store()")
return
}
ms.NoError(err, "unexpected error with Store()")
var user DynamoUser
ms.NoError(s.Load(tt.fields.Table, "uuid", tt.args.key, &user), "error with s.Load()")
ms.Equal(tt.args.key, user.ID, "incorrect user.ID")
})
}
}