forked from ionos-enterprise/ionos-enterprise-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
token_test.go
45 lines (37 loc) · 1.04 KB
/
token_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
package profitbricks
import (
"net/http"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/suite"
)
type SuiteToken struct {
suite.Suite
client *Client
apiUrl string
}
func Test_SuiteToken(t *testing.T) {
suite.Run(t, new(SuiteToken))
}
func (s *SuiteToken) SetupTest() {
token := "eyJ0eXAiOiJKV1QiLCJraWQiOiJjMGY2MDQ4Yi1jZTg3LTRmOGEtODViMi01OTY3ZGI5YTA5NjEiLCJhbGciOiJSUzI1NiJ9.foo.bar"
s.client = NewClientbyToken(token)
s.apiUrl = s.client.AuthApiUrl
httpmock.ActivateNonDefault(s.client.Client.GetClient())
}
func (s *SuiteToken) TearDownTest() {
httpmock.DeactivateAndReset()
}
func (s *SuiteToken) Test_TokenID() {
id, err := s.client.TokenID()
if s.NoError(err) {
s.Equal("c0f6048b-ce87-4f8a-85b2-5967db9a0961", id)
}
}
func (s *SuiteToken) Test_DeleteCurrentToken() {
httpmock.RegisterResponder(http.MethodDelete, s.apiUrl+"/tokens/c0f6048b-ce87-4f8a-85b2-5967db9a0961",
httpmock.NewStringResponder(200, ""))
err := s.client.DeleteCurrentToken()
s.NoError(err)
s.Equal(1, httpmock.GetTotalCallCount())
}