-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathkeys_test.go
71 lines (69 loc) · 1.3 KB
/
keys_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
package resingo
import (
"io/ioutil"
"net/http"
"testing"
)
func TestKeys(t *testing.T) {
config := &Config{
Username: ENV.Username,
Password: ENV.Password,
ResinEndpoint: apiEndpoint,
}
client := &http.Client{}
ctx := &Context{
Client: client,
Config: config,
}
err := Login(ctx, Credentials)
if err != nil {
t.Fatal(err)
}
sample := []struct {
title, file string
key *Key
}{
{"testKey", "fixture/id_rsa.pub", nil},
}
t.Run("Create", func(ts *testing.T) {
for i, v := range sample {
d, err := ioutil.ReadFile(v.file)
if err != nil {
ts.Fatal(err)
}
k, err := KeyCreate(ctx, ctx.Config.UserID(), string(d), v.title)
if err != nil {
ts.Fatal(err)
}
sample[i].key = k
}
})
t.Run("GetByID", func(ts *testing.T) {
for _, v := range sample {
k, err := KeyGetByID(ctx, v.key.ID)
if err != nil {
ts.Fatal(err)
}
if k.Title != v.title {
ts.Errorf("expected %s got %s", v.title, k.Title)
}
}
})
t.Run("GetAll", func(ts *testing.T) {
keys, err := KeyGetAll(ctx)
if err != nil {
ts.Fatal(err)
}
if len(keys) < 1 {
ts.Error("expected at least one key")
}
})
t.Run("Remove", func(ts *testing.T) {
for _, v := range sample {
err := KeyRemove(ctx, v.key.ID)
if err != nil {
ts.Fatal(err)
}
}
})
}