-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkervan_test.go
64 lines (49 loc) · 1.16 KB
/
kervan_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
package kervan_test
import (
"os"
"testing"
"github.com/kervandev/kervan-go"
)
var (
testToken = os.Getenv("TOKEN")
productSecret = os.Getenv("PRODUCT_SECRET")
)
func TestGetVersion(t *testing.T) {
token := testToken
api := kervan.NewCustomAPI("http://localhost:3010/api/v1", token)
res, err := api.GetVersion()
if err != nil {
t.Error(err)
}
if res.Version == "" {
t.Error("Version is empty")
}
if res.Description == "" {
t.Error("Description is empty")
}
}
func TestCheckLicence(t *testing.T) {
token := testToken
api := kervan.NewCustomAPI("http://localhost:3010/api/v1", token)
gtoken, err := kervan.GenerateLicenceCheckJWT("ed9aba8e-cd2e-4af8-b265-1494997a05a8", "192.168.1.1", map[string]string{"test": "test"}, productSecret)
if err != nil {
t.Error(err)
}
payload := kervan.CheckLicencePayload{
Token: gtoken,
}
res, err := api.CheckLicence(&payload)
if err != nil {
t.Error(err)
}
claims, err := kervan.ParseLicenceCheckResponseJWT(res.Token, productSecret)
if err != nil {
t.Error(err)
}
if claims.IsValid == false {
t.Error("IsValid is false")
}
if claims.PlanCode == "" {
t.Error("PlanCode is empty")
}
}