forked from durp/reticule
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_test.go
118 lines (113 loc) · 2.99 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package commands
import (
"io/ioutil"
"os"
"strings"
"testing"
"github.com/alecthomas/kong"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCreateCoinbaseConfigCmd(t *testing.T) {
var cli struct {
createCoinbaseConfigCmd
}
k := mustNew(t, &cli)
_, err := k.Parse([]string{
`--name=horatioHornblower`,
`--base-url=https://api-public.sandbox.pro.coinbase.com`,
`--feed-url=wss://ws-feed-public.sandbox.pro.coinbase.com`,
`--key=key`,
`--passphrase=passphrase`,
`--secret=secret`,
})
fs := afero.NewMemMapFs()
require.NoError(t, err)
err = cli.Run(fs)
require.NoError(t, err)
home, err := os.UserHomeDir()
require.NoError(t, err)
f, err := fs.Open(home + "/.reticule/coinbasepro")
require.NoError(t, err)
b, err := ioutil.ReadAll(f)
require.NoError(t, err)
assert.Equal(t, strings.TrimSpace(`
current: horatioHornblower
configs:
horatioHornblower:
baseurl: https://api-public.sandbox.pro.coinbase.com
feedurl: wss://ws-feed-public.sandbox.pro.coinbase.com
auth:
key: key
passphrase: passphrase
secret: secret
`),
strings.TrimSpace(string(b)))
}
func TestUpdateCoinbaseConfigCmd(t *testing.T) {
var cli struct {
updateCoinbaseConfigCmd
}
k := mustNew(t, &cli)
_, err := k.Parse([]string{
`--name=horatioHornblower`,
`--base-url=https://api-monkeys.sandbox.pro.coinbase.com`,
`--feed-url=wss://ws-feed-monkeys-public.sandbox.pro.coinbase.com`,
`--key=new-key`,
`--passphrase=new-passphrase`,
`--rename=new-name`,
`--secret=new-secret`,
})
fs := afero.NewMemMapFs()
require.NoError(t, err)
home, err := os.UserHomeDir()
require.NoError(t, err)
configPath := home + "/.reticule/coinbasepro"
f, err := fs.Create(configPath)
require.NoError(t, err)
_, err = f.WriteString(`
current: horatioHornblower
configs:
horatioHornblower:
baseurl: https://api-public.sandbox.pro.coinbase.com
feedurl: wss://ws-feed-public.sandbox.pro.coinbase.com
auth:
passphrase: passphrase
secret: secret
`)
require.NoError(t, err)
err = f.Close()
require.NoError(t, err)
err = cli.Run(fs)
require.NoError(t, err)
f, err = fs.Open(home + "/.reticule/coinbasepro")
require.NoError(t, err)
b, err := ioutil.ReadAll(f)
require.NoError(t, err)
assert.Equal(t, strings.TrimSpace(`
current: horatioHornblower
configs:
new-name:
baseurl: https://api-monkeys.sandbox.pro.coinbase.com
feedurl: wss://ws-feed-monkeys-public.sandbox.pro.coinbase.com
auth:
key: new-key
passphrase: new-passphrase
secret: new-secret
`),
strings.TrimSpace(string(b)))
}
func mustNew(t *testing.T, cli interface{}, options ...kong.Option) *kong.Kong {
t.Helper()
options = append([]kong.Option{
kong.Name("test"),
kong.Exit(func(int) {
t.Helper()
t.Fatalf("unexpected exit()")
}),
}, options...)
parser, err := kong.New(cli, options...)
require.NoError(t, err)
return parser
}