-
Notifications
You must be signed in to change notification settings - Fork 52
/
sessiontoken_test.go
65 lines (49 loc) · 1.99 KB
/
sessiontoken_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
package signalfx
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/signalfx/signalfx-go/sessiontoken"
"github.com/stretchr/testify/assert"
)
func TestCreateSessionToken(t *testing.T) {
mux = http.NewServeMux()
server = httptest.NewServer(mux)
client, _ = NewClient("", APIUrl(server.URL))
defer server.Close()
mux.HandleFunc("/v2/session", verifyRequest(t, "POST", false, http.StatusOK, nil, "sessiontoken/create_success.json"))
result, err := client.CreateSessionToken(context.Background(), &sessiontoken.CreateTokenRequest{
Email: "[email protected]",
Password: "testpassword",
})
assert.NoError(t, err, "Unexpected error creating orgtoken")
assert.Equal(t, "[email protected]", result.Email, "Email does not match")
assert.Equal(t, "mytokenvalue", result.AccessToken, "Access token does not match")
}
func TestCreateBadCredentials(t *testing.T) {
mux = http.NewServeMux()
server = httptest.NewServer(mux)
client, _ = NewClient("", APIUrl(server.URL))
defer server.Close()
mux.HandleFunc("/v2/session", verifyRequest(t, "POST", false, http.StatusBadRequest, nil, ""))
result, err := client.CreateSessionToken(context.Background(), &sessiontoken.CreateTokenRequest{
Email: "email",
})
assert.Error(t, err, "Should have gotten an error from a bad create")
assert.Nil(t, result, "Should have a null token on bad create")
}
func TestDeleteSessionToken(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/session", verifyRequest(t, "DELETE", false, http.StatusNoContent, nil, ""))
err := client.DeleteSessionToken(context.Background(), TestToken)
assert.NoError(t, err, "Unexpected error deleting token")
}
func TestDeleteMissingSessionToken(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/session", verifyRequest(t, "DELETE", false, http.StatusNotFound, nil, ""))
err := client.DeleteSessionToken(context.Background(), TestToken)
assert.Error(t, err, "Should have gotten an error from a missing delete")
}