-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
config_test.go
103 lines (78 loc) · 1.69 KB
/
config_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"fmt"
"os"
"testing"
)
func Test_GetLicenseKey_FromLiteral(t *testing.T) {
want := "static.key.text"
c := InletsProConfig{
License: want,
}
key, err := c.GetLicenseKey()
if err != nil {
t.Fatalf("no error wanted for a valid key")
}
if want != key {
t.Fatalf("want %s but got %s", want, key)
}
}
func Test_GetLicenseKey_FromFile(t *testing.T) {
want := "static.key.text"
tmp := os.TempDir()
f, err := os.CreateTemp(tmp, "test-license.txt")
if err != nil {
t.Fatal(err)
}
name := f.Name()
f.Write([]byte(want))
f.Close()
defer os.Remove(name)
c := InletsProConfig{
LicenseFile: name,
}
key, err := c.GetLicenseKey()
if err != nil {
t.Fatalf("no error wanted for a valid key")
}
if want != key {
t.Fatalf("want %s but got %s", want, key)
}
}
func Test_GetLicenseKey_FromFileTrimsWhitespace_JWT(t *testing.T) {
want := `static.key.text`
tmp := os.TempDir()
f, err := os.CreateTemp(tmp, "test-license-with-newline.txt")
if err != nil {
t.Fatal(err)
}
name := f.Name()
// Add a new line at the beginning of the text, and one
// at the end
f.Write([]byte(fmt.Sprintf("\n%s\n", want)))
f.Close()
defer os.Remove(name)
c := InletsProConfig{
LicenseFile: name,
}
key, err := c.GetLicenseKey()
if err != nil {
t.Fatalf("no error wanted for a valid key")
}
if want != key {
t.Fatalf("want %q but got %q", want, key)
}
}
func Test_GetLicenseKey_FromLiteral_WithDashes(t *testing.T) {
want := `static-dashes-key-text`
c := InletsProConfig{
License: want,
}
key, err := c.GetLicenseKey()
if err != nil {
t.Fatalf("no error wanted for a valid key")
}
if want != key {
t.Fatalf("want %q but got %q", want, key)
}
}