-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain_test.go
57 lines (44 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
package main
import (
"os"
"os/exec"
"strings"
"testing"
)
func TestNeocitiesCommand(t *testing.T) {
t.Run("outputs usage instructions if no args", func(t *testing.T) {
out := execGo("run", "main.go")
expected := "neocities <command> [<args>]"
if !strings.Contains(out, expected) {
t.Fatalf("%q does not contain %q", out, expected)
}
})
t.Run("can output help for command", func(t *testing.T) {
out := execGo("run", "main.go", "help", "version")
expected := "Show the version number of the neocities client"
if !strings.Contains(out, expected) {
t.Fatalf("%q does not contain %q", out, expected)
}
})
t.Run("outputs note about missing NEOCITIES_USER variable", func(t *testing.T) {
os.Setenv("NEOCITIES_USER", "")
out := execGo("run", "main.go", "upload", "LICENSE")
expected := "Error: Missing environment variable NEOCITIES_USER or NEOCITIES_KEY"
if !strings.Contains(out, expected) {
t.Fatalf("%q does not contain %q", out, expected)
}
})
t.Run("outputs note about missing NEOCITIES_PASS variable", func(t *testing.T) {
os.Setenv("NEOCITIES_USER", "foo")
os.Setenv("NEOCITIES_PASS", "")
out := execGo("run", "main.go", "upload", "LICENSE")
expected := "Error: Missing environment variable NEOCITIES_PASS"
if !strings.Contains(out, expected) {
t.Fatalf("%q does not contain %q", out, expected)
}
})
}
func execGo(args ...string) string {
out, _ := exec.Command("go", args...).CombinedOutput()
return string(out)
}