-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzuliprc_test.go
48 lines (37 loc) · 976 Bytes
/
zuliprc_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
package zulip
import (
"os"
"testing"
"github.com./stretchr/testify/assert"
)
func TestZuliprcParser(t *testing.T) {
fileContent := `[api]
// empty line
email=user@localhost
key=apikey
site=https://localhost
[bot]
email=bot@localhost
key=botapikey
site=https://localhost
`
f, err := os.CreateTemp("", "zuliprc")
assert.NoError(t, err)
defer os.Remove(f.Name())
_, err = f.WriteString(fileContent)
assert.NoError(t, err)
z, err := ParseZuliprc(f.Name())
assert.NoError(t, err)
apiSection := z["api"]
assert.Equal(t, "user@localhost", apiSection.Email)
assert.Equal(t, "apikey", apiSection.APIKey)
assert.Equal(t, "https://localhost", apiSection.Site)
botSection := z["bot"]
assert.Equal(t, "bot@localhost", botSection.Email)
assert.Equal(t, "botapikey", botSection.APIKey)
assert.Equal(t, "https://localhost", botSection.Site)
}
func TestZuliprcParseFileNotFound(t *testing.T) {
_, err := ParseZuliprc("non-existing-file")
assert.Error(t, err)
}