-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcredentials_test.go
45 lines (35 loc) · 996 Bytes
/
credentials_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
package zulip_test
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/wakumaku/go-zulip"
)
func TestCredentials(t *testing.T) {
expectedSite := "the url"
expectedEmail := "the email"
expectedAPIKey := "the key"
credentials := zulip.Credentials(expectedSite, expectedEmail, expectedAPIKey)
c, err := credentials()
assert.NoError(t, err)
assert.Equal(t, expectedSite, c.Site)
assert.Equal(t, expectedEmail, c.Email)
assert.Equal(t, expectedAPIKey, c.APIKey)
}
func TestCredentialsFromZuliprc(t *testing.T) {
fileContent := `[api]
email=user@localhost
key=apikey
site=https://localhost
`
f, err := os.CreateTemp("", "zuliprc")
assert.NoError(t, err)
_, err = f.WriteString(fileContent)
assert.NoError(t, err)
credentials := zulip.CredentialsFromZuliprc(f.Name(), "api")
c, err := credentials()
assert.NoError(t, err)
assert.Equal(t, "user@localhost", c.Email)
assert.Equal(t, "apikey", c.APIKey)
assert.Equal(t, "https://localhost", c.Site)
}