-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsecurepassctl_test.go
98 lines (90 loc) · 2.15 KB
/
securepassctl_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package securepassctl
import (
"fmt"
"math/rand"
"time"
)
var (
testInstance SecurePass
appLabel string
)
func init() {
testInstance = SecurePass{
AppID: "[email protected]",
AppSecret: "E2m6HawI743as61Kv0OhyPb6wAewXnwVkLLcF82rKOWe1SJ0Wd",
Endpoint: DefaultRemote,
}
appLabel = fmt.Sprintf("test_fixture_%d_%d", time.Now().Unix(), rand.Int())
}
func ExampleSecurePass() {
fmt.Println(testInstance.AppID)
fmt.Println(testInstance.AppSecret)
fmt.Println(testInstance.Endpoint)
// Output:
// E2m6HawI743as61Kv0OhyPb6wAewXnwVkLLcF82rKOWe1SJ0Wd
// https://beta.secure-pass.net
}
func ExampleSecurePass_Ping() {
resp, err := testInstance.Ping()
fmt.Println(err)
fmt.Println(resp.IPVersion)
fmt.Println(resp.ErrorCode())
fmt.Println(resp.ErrorMessage())
// Output:
// <nil>
// 4
// 0
//
}
func ExampleSecurePass_AppAdd() {
var (
resp APIResponse
addResponse *AppAddResponse
infoResponse *AppInfoResponse
fixtureAppID string
)
// Create a new app
addResponse, _ = testInstance.AppAdd(&ApplicationDescriptor{
Label: appLabel,
})
fixtureAppID = addResponse.AppID
fmt.Println(addResponse.ErrorCode())
fmt.Println(addResponse.ErrorMessage() == "")
// Check for its existence
resp, _ = testInstance.AppInfo(fixtureAppID)
fmt.Println(resp.ErrorCode())
// Modify it
resp, _ = testInstance.AppMod(fixtureAppID, &ApplicationDescriptor{
Write: false,
Label: appLabel + "newLabel",
Privacy: true,
})
fmt.Println(resp.ErrorCode())
// Check whether the modifcations have been applied
infoResponse, _ = testInstance.AppInfo(fixtureAppID)
fmt.Println(infoResponse.Label == appLabel+"newLabel")
// Remove it
resp, _ = testInstance.AppDel(fixtureAppID)
fmt.Println(resp.ErrorCode())
// Check whether it does not longer exist
resp, _ = testInstance.AppInfo(fixtureAppID)
fmt.Println(resp.ErrorCode())
// Output:
// 0
// true
// 0
// 0
// true
// 0
// 10
}
func ExampleSecurePass_AppList() {
var resp APIResponse
resp, err := testInstance.AppList("")
fmt.Println(resp.ErrorCode())
fmt.Println(err)
// Output:
// 0
// <nil>
}