-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth_test.go
57 lines (45 loc) · 1.05 KB
/
auth_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
package goidoit
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
type testValuesNewAPI struct {
URL, APIKEY string
Error error
}
func TestNewAPI(t *testing.T) {
testValues := []testValuesNewAPI{
{"", "test", fmt.Errorf("url or apikey empty")},
{"test", "", fmt.Errorf("url or apikey empty")},
{"test", "test", nil},
}
for _, test := range testValues {
api, err := NewAPI(test.URL, test.APIKEY)
if test.Error == nil {
assert.Nil(t, err)
} else {
assert.Equal(t, test.Error.Error(), err.Error())
}
if err == nil {
assert.Equal(t, test.URL, api.URL)
assert.Equal(t, test.APIKEY, api.APIkey)
}
}
}
func TestLogin(t *testing.T) {
server := idoitAPIStub()
api, err := NewAPI(server.URL, "apikey")
assert.Nil(t, err)
test := api.IsLoggedIn()
assert.False(t, test)
err = api.Login()
assert.Nil(t, err)
api, err = NewLogin(server.URL, "apikey", "username", "password")
assert.Nil(t, err)
assert.NotNil(t, api)
test = api.IsLoggedIn()
assert.True(t, test)
err = api.Logout()
assert.Nil(t, err)
}