forked from flamingo-stack/openframe-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
64 lines (57 loc) · 1.2 KB
/
Copy pathmain_test.go
File metadata and controls
64 lines (57 loc) · 1.2 KB
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
package main
import (
"bytes"
"os"
"os/exec"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMainIntegration(t *testing.T) {
// Build test binary
testBinary := "openframe-test-main"
buildCmd := exec.Command("go", "build", "-o", testBinary, ".")
require.NoError(t, buildCmd.Run())
defer os.Remove(testBinary)
tests := []struct {
name string
args []string
wantErr bool
contains string
}{
{
name: "help",
args: []string{"--help"},
wantErr: false,
contains: "OpenFrame CLI",
},
{
name: "version",
args: []string{"--version"},
wantErr: false,
contains: "dev",
},
{
name: "invalid flag",
args: []string{"--invalid"},
wantErr: true,
contains: "unknown flag",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cmd := exec.Command("./"+testBinary, tc.args...)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
output := stdout.String() + stderr.String()
if tc.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Contains(t, output, tc.contains)
})
}
}