forked from dorkitude/linctl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmoke_test.sh
More file actions
executable file
·181 lines (155 loc) · 6.73 KB
/
smoke_test.sh
File metadata and controls
executable file
·181 lines (155 loc) · 6.73 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
#!/bin/bash
# Smoke test for linctl - tests all READ commands
# This script runs through all the read-only commands to ensure basic functionality
set -e # Exit on error
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
# Test counters
TESTS_RUN=0
TESTS_PASSED=0
TESTS_FAILED=0
# Function to run a test
run_test() {
local test_name="$1"
local command="$2"
local expected_pattern="$3" # Optional pattern to check in output
TESTS_RUN=$((TESTS_RUN + 1))
echo -n "Testing: $test_name... "
# Run the command and capture output and exit code
set +e # Temporarily disable exit on error
output=$(eval "$command" 2>&1)
exit_code=$?
set -e
if [ $exit_code -eq 0 ]; then
# If an expected pattern is provided, check for it
if [ -n "$expected_pattern" ]; then
if echo "$output" | grep -q "$expected_pattern"; then
echo -e "${GREEN}PASS${NC}"
TESTS_PASSED=$((TESTS_PASSED + 1))
else
echo -e "${RED}FAIL${NC} - Expected pattern not found: $expected_pattern"
echo "Output: $output" | head -5
TESTS_FAILED=$((TESTS_FAILED + 1))
fi
else
echo -e "${GREEN}PASS${NC}"
TESTS_PASSED=$((TESTS_PASSED + 1))
fi
else
echo -e "${RED}FAIL${NC} - Exit code: $exit_code"
echo "Error: $output" | head -5
TESTS_FAILED=$((TESTS_FAILED + 1))
fi
}
# Function to extract first ID from list output
get_first_id() {
local output="$1"
# Extract first UUID-like pattern (for projects) or identifier like END-1234 (for issues)
echo "$output" | grep -E -o '([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}|[A-Z]+-[0-9]+)' | head -1
}
echo "🚀 Starting linctl smoke tests..."
echo "================================"
# Check if authenticated
echo -e "\n${YELLOW}Checking authentication...${NC}"
run_test "auth status" "go run main.go auth status" "Authenticated"
# If not authenticated, skip tests
if [ $TESTS_FAILED -gt 0 ]; then
echo -e "\n${RED}Not authenticated. Please run 'linctl auth' first.${NC}"
exit 1
fi
# Test whoami
echo -e "\n${YELLOW}Testing user commands...${NC}"
run_test "whoami" "go run main.go whoami" "@"
# Test user list
run_test "user list" "go run main.go user list"
run_test "user list (plaintext)" "go run main.go user list -p"
run_test "user list (json)" "go run main.go user list -j" "\"email\""
# Note: user get requires user ID, not email - skipping for now
# Could be implemented by parsing JSON output from user list
# Test team commands
echo -e "\n${YELLOW}Testing team commands...${NC}"
run_test "team list" "go run main.go team list"
run_test "team list (plaintext)" "go run main.go team list -p"
run_test "team list (json)" "go run main.go team list -j" "\"key\""
# Get first team key for additional tests - look for pattern at start of line
team_key=$(go run main.go team list 2>/dev/null | awk 'NR>1 {print $1}' | head -1)
if [ -n "$team_key" ]; then
run_test "team get" "go run main.go team get $team_key" "$team_key"
run_test "team members" "go run main.go team members $team_key"
fi
# Test project commands
echo -e "\n${YELLOW}Testing project commands...${NC}"
run_test "project list" "go run main.go project list"
run_test "project list (plaintext)" "go run main.go project list -p" "# Projects"
run_test "project list (json)" "go run main.go project list -j" "\"id\""
# Note: project list doesn't support team filter in the API
# run_test "project list (with team filter)" "go run main.go project list --team $team_key"
run_test "project list (state filter)" "go run main.go project list --state started"
run_test "project list (time filter)" "go run main.go project list --newer-than 1_month_ago"
# Get first project ID for project get test
project_output=$(go run main.go project list 2>/dev/null || true)
project_id=$(get_first_id "$project_output")
if [ -n "$project_id" ]; then
run_test "project get" "go run main.go project get $project_id" "Project:"
run_test "project get (plaintext)" "go run main.go project get $project_id -p" "# "
fi
# Test issue commands
echo -e "\n${YELLOW}Testing issue commands...${NC}"
run_test "issue list" "go run main.go issue list"
run_test "issue list (plaintext)" "go run main.go issue list -p" "# Issues"
run_test "issue list (json)" "go run main.go issue list -j" "\"identifier\""
run_test "issue list (assignee filter)" "go run main.go issue list --assignee me"
run_test "issue list (state filter)" "go run main.go issue list --state Todo"
run_test "issue list (team filter)" "go run main.go issue list --team $team_key"
run_test "issue list (priority filter)" "go run main.go issue list --priority 3"
run_test "issue list (time filter)" "go run main.go issue list --newer-than 2_weeks_ago"
run_test "issue list (sort by updated)" "go run main.go issue list --sort updated"
# Get first issue ID for additional tests
issue_output=$(go run main.go issue list --limit 5 2>/dev/null || true)
issue_id=$(echo "$issue_output" | grep -E -o '[A-Z]+-[0-9]+' | head -1)
if [ -n "$issue_id" ]; then
run_test "issue get" "go run main.go issue get $issue_id"
run_test "issue get (plaintext)" "go run main.go issue get $issue_id -p" "# $issue_id"
# Test comment list for this issue
echo -e "\n${YELLOW}Testing comment commands...${NC}"
run_test "comment list" "go run main.go comment list $issue_id"
run_test "comment list (plaintext)" "go run main.go comment list $issue_id -p"
fi
# Test help commands
echo -e "\n${YELLOW}Testing help commands...${NC}"
run_test "help" "go run main.go --help" "Usage:"
run_test "issue help" "go run main.go issue --help" "Available Commands:"
run_test "project help" "go run main.go project --help" "Available Commands:"
run_test "team help" "go run main.go team --help" "Available Commands:"
run_test "user help" "go run main.go user --help" "Available Commands:"
# Test unknown command handling
echo -e "\n${YELLOW}Testing error handling...${NC}"
# This should fail but gracefully
set +e
output=$(go run main.go nonexistent-command 2>&1)
if echo "$output" | grep -q "unknown command"; then
echo -e "Unknown command handling: ${GREEN}PASS${NC}"
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_PASSED=$((TESTS_PASSED + 1))
else
echo -e "Unknown command handling: ${RED}FAIL${NC}"
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_FAILED=$((TESTS_FAILED + 1))
fi
set -e
# Summary
echo -e "\n================================"
echo "Test Summary:"
echo " Total tests: $TESTS_RUN"
echo -e " Passed: ${GREEN}$TESTS_PASSED${NC}"
echo -e " Failed: ${RED}$TESTS_FAILED${NC}"
if [ $TESTS_FAILED -eq 0 ]; then
echo -e "\n${GREEN}✅ All tests passed!${NC}"
exit 0
else
echo -e "\n${RED}❌ Some tests failed!${NC}"
exit 1
fi