-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapi_test.go
70 lines (58 loc) · 1.5 KB
/
api_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
package okta
import (
"os"
"strings"
"testing"
)
var client *Client
func init() {
client = NewClient(os.Getenv("OKTA_ORG"))
client.Url = "oktapreview.com"
}
func TestAPIFailure(t *testing.T) {
client := NewClient("organization")
_, err := client.Authenticate("username", "password")
if !strings.Contains(err.Error(), "E0000007") {
t.Error("Expected E0000007, got ", err.Error())
}
}
func TestAcceptance(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
_, err := client.Authenticate(os.Getenv("OKTA_USERNAME"), os.Getenv("OKTA_PASSWORD"))
if err != nil {
t.Error("Expected nil, got ", err.Error())
}
}
func TestNoTokenUser(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
_, err := client.User(os.Getenv("OKTA_USERNAME"))
if !strings.Contains(err.Error(), "E0000005") {
t.Error("Expected E0000005, got ", err.Error())
}
}
func TestUser(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
client.ApiToken = os.Getenv("OKTA_API_TOKEN")
_, err := client.User(os.Getenv("OKTA_USERNAME"))
if err != nil {
t.Error("Expected nil, got ", err.Error())
}
}
func TestUserGroups(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
client.ApiToken = os.Getenv("OKTA_API_TOKEN")
groups, err := client.Groups(os.Getenv("OKTA_USERNAME"))
if err != nil {
t.Error("Expected nil, got ", err.Error())
} else if len(*groups) != 2 {
t.Error("Expected length of 2, got ", len(*groups))
}
}