-
Notifications
You must be signed in to change notification settings - Fork 0
/
Common_test.go
81 lines (65 loc) · 2.26 KB
/
Common_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
76
77
78
79
80
81
package aspace
import (
"flag"
"strconv"
"testing"
goaspacetest "github.com/nyudlts/go-aspace/goaspace_testing"
)
func TestCommon(t *testing.T) {
flag.Parse()
client, err := NewClient(goaspacetest.Config, goaspacetest.Environment, 20)
if err != nil {
t.Error(err)
}
t.Run("Test get the ASpace server info", func(t *testing.T) {
info, err := client.GetAspaceInfo()
if err != nil {
t.Error(err)
}
t.Log(info)
})
t.Run("Test get session key", func(t *testing.T) {
want := 64
t.Log(client.sessionKey)
got := len(client.sessionKey)
if want != got {
t.Errorf("wanted key length of %d, got %d", want, got)
} else {
t.Log("Succesfully requested valid session key.")
}
})
t.Run("Test ParseCreateOrUpdateResponse() Created", func(t *testing.T) {
responseBody := `{"status":"Created","id":61344,"lock_version":0,"stale":true,"uri":"/repositories/6/digital_objects/61344","warnings":[]}`
got := ParseCreateOrUpdateResponse(responseBody)
scenarios := [][]string{
{"Created", got.Status, "Incorrect Status"},
{"", got.Error, "Incorrect Error"},
{"61344", strconv.FormatInt(int64(got.ID), 10), "Incorrect ID"},
{"0", strconv.FormatInt(int64(got.LockVersion), 10), "Incorrect LockVersion"},
{"true", strconv.FormatBool(got.Stale), "Incorrect Stale"},
{"/repositories/6/digital_objects/61344", got.URI, "Incorrect URI"},
}
for _, scenario := range scenarios {
if scenario[1] != scenario[0] {
t.Errorf("unexpected result: %s: want: '%s', got: '%s'", scenario[2], scenario[0], scenario[1])
}
}
})
t.Run("Test ParseCreateOrUpdateResponse() Error", func(t *testing.T) {
responseBody := `{"error":"I need more coffee!"}`
got := ParseCreateOrUpdateResponse(responseBody)
scenarios := [][]string{
{"", got.Status, "Incorrect Status"},
{"I need more coffee!", got.Error, "Incorrect Error"},
{"0", strconv.FormatInt(int64(got.ID), 10), "Incorrect ID"},
{"0", strconv.FormatInt(int64(got.LockVersion), 10), "Incorrect LockVersion"},
{"false", strconv.FormatBool(got.Stale), "Incorrect Stale"},
{"", got.URI, "Incorrect URI"},
}
for _, scenario := range scenarios {
if scenario[1] != scenario[0] {
t.Errorf("unexpected result: %s: want: '%s', got: '%s'", scenario[2], scenario[0], scenario[1])
}
}
})
}