-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.go
More file actions
192 lines (162 loc) · 5.51 KB
/
integration_test.go
File metadata and controls
192 lines (162 loc) · 5.51 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// +build integration
package main
import (
"fmt"
"os"
"os/exec"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestIntegration_FullWorkflow tests a complete end-to-end workflow
func TestIntegration_FullWorkflow(t *testing.T) {
apiURL := os.Getenv("BEEPER_API_URL")
token := os.Getenv("BEEPER_TOKEN")
testChatID := os.Getenv("BEEPER_TEST_CHAT_ID")
if apiURL == "" || token == "" || testChatID == "" {
t.Skip("Integration test environment not configured")
}
// 1. Test discover
t.Run("Discover API", func(t *testing.T) {
cmd := exec.Command("./beeper", "discover")
output, err := cmd.CombinedOutput()
assert.NoError(t, err)
assert.NotEmpty(t, output)
})
// 2. Test listing chats
t.Run("List Chats", func(t *testing.T) {
cmd := exec.Command("./beeper", "chats", "list", "--output", "json")
output, err := cmd.CombinedOutput()
require.NoError(t, err)
assert.Contains(t, string(output), "[")
})
// 3. Test getting specific chat
t.Run("Get Chat", func(t *testing.T) {
cmd := exec.Command("./beeper", "chats", "get", testChatID, "--output", "json")
output, err := cmd.CombinedOutput()
require.NoError(t, err)
assert.Contains(t, string(output), testChatID)
})
// 4. Test listing messages
t.Run("List Messages", func(t *testing.T) {
cmd := exec.Command("./beeper", "messages", "list", testChatID, "--limit", "5", "--output", "json")
output, err := cmd.CombinedOutput()
require.NoError(t, err)
assert.Contains(t, string(output), "[")
})
// 5. Test sending a message
t.Run("Send Message", func(t *testing.T) {
testMsg := fmt.Sprintf("Integration test message - %v", time.Now().Unix())
cmd := exec.Command("./beeper", "send", "--chat-id", testChatID, "--message", testMsg)
output, err := cmd.CombinedOutput()
require.NoError(t, err)
assert.NotEmpty(t, output)
})
// 6. Test search
t.Run("Search Messages", func(t *testing.T) {
cmd := exec.Command("./beeper", "search", "--query", "test", "--limit", "5", "--output", "json")
output, err := cmd.CombinedOutput()
require.NoError(t, err)
assert.NotEmpty(t, output)
})
}
// TestIntegration_OutputFormats tests all output formats work correctly
func TestIntegration_OutputFormats(t *testing.T) {
apiURL := os.Getenv("BEEPER_API_URL")
token := os.Getenv("BEEPER_TOKEN")
if apiURL == "" || token == "" {
t.Skip("Integration test environment not configured")
}
formats := []string{"json", "text", "markdown"}
for _, format := range formats {
t.Run("Format_"+format, func(t *testing.T) {
cmd := exec.Command("./beeper", "chats", "list", "--output", format)
output, err := cmd.CombinedOutput()
require.NoError(t, err)
assert.NotEmpty(t, output)
result := string(output)
switch format {
case "json":
assert.Contains(t, result, "[")
case "markdown":
assert.Contains(t, result, "#")
case "text":
assert.NotEmpty(t, result)
}
})
}
}
// TestIntegration_ErrorHandling tests error scenarios
func TestIntegration_ErrorHandling(t *testing.T) {
t.Run("Invalid Chat ID", func(t *testing.T) {
cmd := exec.Command("./beeper", "chats", "get", "invalid-chat-id-that-does-not-exist")
output, err := cmd.CombinedOutput()
assert.Error(t, err)
assert.NotEmpty(t, output)
})
t.Run("Missing Required Argument", func(t *testing.T) {
cmd := exec.Command("./beeper", "send", "--message", "test")
output, err := cmd.CombinedOutput()
assert.Error(t, err)
assert.NotEmpty(t, output)
})
t.Run("Invalid Output Format", func(t *testing.T) {
cmd := exec.Command("./beeper", "chats", "list", "--output", "invalid")
output, err := cmd.CombinedOutput()
// Should either error or default to valid format
assert.NotEmpty(t, output)
})
}
// TestIntegration_Config tests configuration management
func TestIntegration_Config(t *testing.T) {
tmpDir := t.TempDir()
configPath := tmpDir + "/config.yaml"
os.Setenv("BEEPER_CONFIG", configPath)
defer os.Unsetenv("BEEPER_CONFIG")
t.Run("Set Config", func(t *testing.T) {
cmd := exec.Command("./beeper", "config", "set", "output_format", "markdown")
output, err := cmd.CombinedOutput()
assert.NoError(t, err)
assert.NotEmpty(t, output)
// Verify file exists
_, err = os.Stat(configPath)
assert.NoError(t, err)
})
t.Run("Show Config", func(t *testing.T) {
cmd := exec.Command("./beeper", "config", "show")
output, err := cmd.CombinedOutput()
assert.NoError(t, err)
assert.Contains(t, string(output), "output_format")
})
t.Run("Get Config Value", func(t *testing.T) {
cmd := exec.Command("./beeper", "config", "get", "output_format")
output, err := cmd.CombinedOutput()
assert.NoError(t, err)
assert.Contains(t, string(output), "markdown")
})
}
// TestIntegration_PipelineUsage tests CLI works in Unix pipelines
func TestIntegration_PipelineUsage(t *testing.T) {
apiURL := os.Getenv("BEEPER_API_URL")
token := os.Getenv("BEEPER_TOKEN")
if apiURL == "" || token == "" {
t.Skip("Integration test environment not configured")
}
t.Run("Pipe JSON to jq", func(t *testing.T) {
// Test that JSON output can be piped to jq
cmd := exec.Command("bash", "-c", "./beeper chats list --output json | jq -r '.[0].id'")
output, err := cmd.CombinedOutput()
// Only assert if jq is available
if err == nil {
assert.NotEmpty(t, output)
}
})
t.Run("Grep text output", func(t *testing.T) {
cmd := exec.Command("bash", "-c", "./beeper chats list --output text | grep -i chat")
output, err := cmd.CombinedOutput()
// May not match anything, but should not error on pipe
assert.NotNil(t, output)
})
}