-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathconfigs_test.go
46 lines (35 loc) · 1.13 KB
/
configs_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
package github
import (
"github.com/bmizerany/assert"
"io/ioutil"
"os"
"testing"
)
func TestSaveCredentials(t *testing.T) {
file, _ := ioutil.TempFile("", "test-gh-config-")
defer os.RemoveAll(file.Name())
ccreds := Credentials{Host: "github.com", User: "jingweno", AccessToken: "123"}
c := Configs{Credentials: []Credentials{ccreds}}
err := saveTo(file.Name(), &c)
assert.Equal(t, nil, err)
cc := &Configs{}
err = loadFrom(file.Name(), cc)
assert.Equal(t, nil, err)
creds := cc.Credentials[0]
assert.Equal(t, "github.com", creds.Host)
assert.Equal(t, "jingweno", creds.User)
assert.Equal(t, "123", creds.AccessToken)
}
func TestReadAndSaveDeprecatedConfiguration(t *testing.T) {
file, _ := ioutil.TempFile("", "test-gh-config-")
defer os.RemoveAll(file.Name())
defaultConfigsFile = file.Name()
file.WriteString(`[{"host":"github.com","user":"jingweno","access_token":"123"}]`)
file.Close()
CurrentConfigs()
expectedConfig := `{"credentials":[{"host":"github.com","user":"jingweno","access_token":"123"}]}
`
f, _ := os.Open(file.Name())
content, _ := ioutil.ReadAll(f)
assert.Equal(t, expectedConfig, string(content))
}