-
Notifications
You must be signed in to change notification settings - Fork 2
/
api_key_storer_test.go
79 lines (63 loc) · 1.59 KB
/
api_key_storer_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
package lol
import (
"io/ioutil"
"os"
"testing"
. "gopkg.in/check.v1"
)
type TempHomer struct {
envOverrides map[string]string
envSaves map[string]string
tmpDir string
}
func (h *TempHomer) SetUp() error {
var err error
h.tmpDir, err = ioutil.TempDir("", "go-deb.ddesk_test")
if err != nil {
}
h.OverrideEnv("HOME", h.tmpDir)
h.envSaves = make(map[string]string)
for key, value := range h.envOverrides {
h.envSaves[key] = os.Getenv(key)
os.Setenv(key, value)
}
return nil
}
func (h *TempHomer) TearDown() error {
for key, value := range h.envSaves {
os.Setenv(key, value)
}
return os.RemoveAll(h.tmpDir)
}
func (h *TempHomer) OverrideEnv(key, value string) {
if h.envOverrides == nil {
h.envOverrides = make(map[string]string)
}
h.envOverrides[key] = value
}
type XdgAPIKeyStorerSuite struct {
h TempHomer
}
var _ = Suite(&XdgAPIKeyStorerSuite{})
func Test(t *testing.T) { TestingT(t) }
func (s *XdgAPIKeyStorerSuite) SetUpSuite(c *C) {
s.h.OverrideEnv("XDG_CONFIG_HOME", "")
err := s.h.SetUp()
c.Assert(err, IsNil, Commentf("Initialization error: %s"))
}
func (s *XdgAPIKeyStorerSuite) TearDownSuite(c *C) {
err := s.h.TearDown()
c.Assert(err, IsNil, Commentf("Cleanup error: %s", err))
}
func (s *XdgAPIKeyStorerSuite) TestKeyValidity(c *C) {
// These are old valid key got from riot games, invalid now :-P
validData := []string{
"b7b2daaf-ef84-41a0-8d79-de45ff42d311",
"8975503a-9e88-4252-b11e-fc649f2dbe0d",
}
for _, keyStr := range validData {
k := APIKey(keyStr)
err := k.Check()
c.Check(err, IsNil, Commentf("Got unexpected error: %s", err))
}
}