-
Notifications
You must be signed in to change notification settings - Fork 0
/
poem_test.go
115 lines (106 loc) · 2.99 KB
/
poem_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
/*
Copyright (c) 2022, Vaclovas Lapinskis. All rights reserved.
*/
package poem_test
import (
"bytes"
"io"
"os"
"testing"
"github.com/google/subcommands"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"webimizer.dev/poem"
)
/* Testing Poem CLI application output */
func TestInitApplication(t *testing.T) {
r, w, err := os.Pipe()
require.NoError(t, err)
os.Stderr = w
subcommands.DefaultCommander.Error = w
poem.InitApplication()
_ = w.Close()
buf := new(bytes.Buffer)
_, err = io.Copy(buf, r)
require.NoError(t, err)
assert.Contains(t, buf.String(), "Usage:")
assert.Contains(t, buf.String(), "Subcommands:")
assert.Contains(t, buf.String(), "commands")
assert.Contains(t, buf.String(), "flags")
assert.Contains(t, buf.String(), "help")
assert.Contains(t, buf.String(), "install")
assert.Contains(t, buf.String(), "poems-server")
assert.Contains(t, buf.String(), "oauth-server")
assert.Contains(t, buf.String(), "admin-server")
assert.Contains(t, buf.String(), "admin-frontend")
}
/* Testing Poems server output */
func TestInitPoemsServer(t *testing.T) {
os.Args = []string{"poem", "poems-server"}
r, w, err := os.Pipe()
require.NoError(t, err)
os.Stdout = w
subcommands.DefaultCommander.Output = w
poem.InitApplication()
_ = w.Close()
buf := new(bytes.Buffer)
_, err = io.Copy(buf, r)
require.NoError(t, err)
assert.Contains(t, buf.String(), "Starting server...")
}
/* Testing Poems server output */
func TestInitOauthServer(t *testing.T) {
os.Args = []string{"poem", "oauth-server"}
r, w, err := os.Pipe()
require.NoError(t, err)
os.Stdout = w
subcommands.DefaultCommander.Output = w
poem.InitApplication()
_ = w.Close()
buf := new(bytes.Buffer)
_, err = io.Copy(buf, r)
require.NoError(t, err)
assert.Contains(t, buf.String(), "Starting server...")
}
/* Testing Admin server output */
func TestInitAdminServer(t *testing.T) {
os.Args = []string{"poem", "admin-server"}
r, w, err := os.Pipe()
require.NoError(t, err)
os.Stdout = w
subcommands.DefaultCommander.Output = w
poem.InitApplication()
_ = w.Close()
buf := new(bytes.Buffer)
_, err = io.Copy(buf, r)
require.NoError(t, err)
assert.Contains(t, buf.String(), "Starting server...")
}
/* Testing Admin frontend command output */
func TestInitAdminFrontend(t *testing.T) {
os.Args = []string{"poem", "admin-frontend"}
r, w, err := os.Pipe()
require.NoError(t, err)
os.Stdout = w
subcommands.DefaultCommander.Output = w
poem.InitApplication()
_ = w.Close()
buf := new(bytes.Buffer)
_, err = io.Copy(buf, r)
require.NoError(t, err)
assert.Contains(t, buf.String(), "Starting server...")
}
/* Testing install subcommand output */
func TestInstallSubcommand(t *testing.T) {
os.Args = []string{"poem", "install"}
r, w, err := os.Pipe()
require.NoError(t, err)
os.Stdout = w
subcommands.DefaultCommander.Output = w
poem.InitApplication()
_ = w.Close()
buf := new(bytes.Buffer)
_, err = io.Copy(buf, r)
require.NoError(t, err)
assert.Contains(t, buf.String(), "Installing CMS database...")
}