-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
76 lines (58 loc) · 1.46 KB
/
main_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
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"strconv"
"strings"
"testing"
"github.com/sirupsen/logrus"
"github.com/newtonproject/newchain-notify/cli"
)
func getTempFile() (string, func()) {
dir, err := ioutil.TempDir("", "example")
if err != nil {
log.Fatal(err)
}
file := dir + string(os.PathSeparator) + "lumen-integration-test.json"
return file, func() {
logrus.Debugf("cleaning up temp file: %s", file)
os.RemoveAll(dir)
}
}
func run(cli *cli.CLI, command string) string {
fmt.Printf("$ ./NewCommander %s\n", command)
got := cli.TestCommand(command)
fmt.Printf("%s\n", got)
return strings.TrimSpace(got)
}
func runArgs(cli *cli.CLI, args ...string) string {
fmt.Printf("$ ./NewCommander %s\n", strings.Join(args, " "))
got := cli.Embeddable().Run(args...)
fmt.Printf("%s\n", got)
return strings.TrimSpace(got)
}
func expectOutput(t *testing.T, cli *cli.CLI, want string, command string) {
got := run(cli, command)
if got != want {
t.Errorf("(%s) wrong output: want %v, got %v", command, want, got)
}
}
func newCLI() (*cli.CLI, func()) {
_, cleanupFunc := getTempFile()
glumen := cli.NewCLI()
glumen.TestCommand("version")
run(glumen, fmt.Sprintf("version"))
return glumen, cleanupFunc
}
func getBalance(cli *cli.CLI, account string) float64 {
balanceString := run(cli, "balance "+account)
balance, err := strconv.ParseFloat(balanceString, 64)
if err != nil {
return 0
}
return balance
}
func TestTx(t *testing.T) {
}