-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion_integration_test.go
More file actions
112 lines (93 loc) · 2.59 KB
/
version_integration_test.go
File metadata and controls
112 lines (93 loc) · 2.59 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
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
//go:build integration
package commands
import (
"encoding/json"
"strings"
"testing"
"github.com/jongio/azd-core/testutil"
"github.com/jongio/azd-exec/cli/src/internal/version"
)
func TestVersionCommandIntegration(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
tests := []struct {
name string
outputFlag string
wantText string
}{
{
name: "Default output",
outputFlag: "default",
wantText: version.Version,
},
{
name: "JSON output",
outputFlag: "json",
wantText: `"version"`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
outputFormat := tt.outputFlag
cmd := NewVersionCommand(&outputFormat)
// Capture output
output := testutil.CaptureOutput(t, func() error {
return cmd.Execute()
})
// Verify output
if !strings.Contains(output, tt.wantText) {
t.Errorf("Output does not contain expected text.\nGot: %s\nWant substring: %s", output, tt.wantText)
}
// For JSON output, verify it's valid JSON
if tt.outputFlag == "json" {
var result map[string]string
if err := json.Unmarshal([]byte(output), &result); err != nil {
t.Errorf("JSON output is invalid: %v\nOutput: %s", err, output)
}
if result["version"] == "" {
t.Error("JSON output missing version field")
}
}
})
}
}
func TestVersionCommandIntegration_DefaultFormat(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
outputFormat := "default"
cmd := NewVersionCommand(&outputFormat)
output := testutil.CaptureOutput(t, func() error {
return cmd.Execute()
})
// Default output should contain the version
output = strings.TrimSpace(output)
if !strings.Contains(output, version.Version) {
t.Errorf("Default output should contain version, got: %s", output)
}
}
func TestVersionCommandIntegration_JSONFormat(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
outputFormat := "json"
cmd := NewVersionCommand(&outputFormat)
output := testutil.CaptureOutput(t, func() error {
return cmd.Execute()
})
// Parse JSON
var result map[string]string
if err := json.Unmarshal([]byte(output), &result); err != nil {
t.Fatalf("Failed to parse JSON output: %v\nOutput: %s", err, output)
}
// Verify version field exists
version, ok := result["version"]
if !ok {
t.Error("JSON output missing 'version' field")
}
// Verify version format (should be semver-like)
if !strings.Contains(version, ".") {
t.Errorf("Version should contain dots (semver format), got: %s", version)
}
}