File tree 1 file changed +54
-1
lines changed
1 file changed +54
-1
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
- import "testing"
3
+ import (
4
+ "bytes"
5
+ "encoding/json"
6
+ "io"
7
+ "os"
8
+ "strings"
9
+ "testing"
10
+ )
4
11
5
12
func TestBuildCommand (t * testing.T ) {
6
13
rootCmd := buildRootCmd ()
@@ -15,3 +22,49 @@ func TestBuildCommand(t *testing.T) {
15
22
t .Errorf ("Expected %d command, got %d" , numCommands , len (rootCmd .Commands ()))
16
23
}
17
24
}
25
+
26
+ func TestGetVersion (t * testing.T ) {
27
+ cmd := buildRootCmd ()
28
+ if cmd == nil {
29
+ t .Errorf ("Expected cmd to be defined" )
30
+ }
31
+ version := generateVersionCommand ()
32
+ old := os .Stdout
33
+ r , w , _ := os .Pipe ()
34
+ os .Stdout = w
35
+
36
+ version .Run (cmd , nil )
37
+
38
+ w .Close ()
39
+ os .Stdout = old
40
+
41
+ var buf bytes.Buffer
42
+ io .Copy (& buf , r )
43
+ output := buf .String ()
44
+ if ! strings .Contains (output , "(devel)" ) {
45
+ t .Errorf ("Expected output to contain '(devel)', got %s" , output )
46
+ }
47
+ }
48
+
49
+ func TestSchemaCommand (t * testing.T ) {
50
+ cmd := buildRootCmd ()
51
+ if cmd == nil {
52
+ t .Errorf ("Expected cmd to be defined" )
53
+ }
54
+ schema := generateSchemaCommand ()
55
+ old := os .Stdout
56
+ r , w , _ := os .Pipe ()
57
+ os .Stdout = w
58
+ schema .Run (cmd , nil )
59
+ w .Close ()
60
+ os .Stdout = old
61
+ var buf bytes.Buffer
62
+ io .Copy (& buf , r )
63
+ output := buf .String ()
64
+
65
+ // try to parse json
66
+ schemaContent := make (map [string ]interface {})
67
+ if err := json .Unmarshal ([]byte (output ), & schemaContent ); err != nil {
68
+ t .Errorf ("Expected valid json, got %s" , output )
69
+ }
70
+ }
You can’t perform that action at this time.
0 commit comments