Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit 3c146be

Browse files
committed
Add e2e test example
1 parent 72d2dd1 commit 3c146be

File tree

6 files changed

+166
-0
lines changed

6 files changed

+166
-0
lines changed

Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,45 @@ unit-tests:
6363
@go test -v ./...
6464
@echo "Unit tests completed!"
6565

66+
e2e-tests: build e2e-shell-bash e2e-shell-zsh e2e-shell-cmd e2e-shell-mintty
67+
@echo "All shell-specific tests completed!"
68+
69+
e2e-shell-bash:
70+
@echo "Running bash-specific tests..."
71+
@if command -v bash >/dev/null 2>&1; then \
72+
./e2e/shells/bash_test.sh; \
73+
else \
74+
echo "Bash not available, skipping bash tests"; \
75+
fi
76+
77+
e2e-shell-zsh:
78+
@echo "Running zsh-specific tests..."
79+
@if command -v zsh >/dev/null 2>&1; then \
80+
./e2e/shells/zsh_test.sh; \
81+
else \
82+
echo "Zsh not available, skipping zsh tests"; \
83+
fi
84+
85+
e2e-shell-cmd:
86+
@echo "Running cmd.exe-specific tests..."
87+
@if [ "$(shell uname -s)" = "MINGW64_NT" ] || [ "$(shell uname -s)" = "MSYS_NT" ]; then \
88+
cmd.exe /c e2e\\shells\\cmd_test.bat; \
89+
else \
90+
echo "Windows cmd.exe not available, skipping cmd tests"; \
91+
fi
92+
93+
e2e-shell-mintty:
94+
@echo "Running mintty bash-specific tests..."
95+
@if [ -n "$$MSYSTEM" ] || [ "$$TERM" = "xterm" ]; then \
96+
./e2e/shells/mintty_test.sh; \
97+
else \
98+
echo "Mintty/Git Bash not detected, skipping mintty tests"; \
99+
fi
100+
66101
clean:
67102
@echo "Cleaning up..."
68103
@rm -f $(BINARY_NAME)
104+
@rm -f model-cli-test
69105
@echo "Cleaned!"
70106

71107
docs:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MODEL NAME PARAMETERS QUANTIZATION ARCHITECTURE MODEL ID CREATED SIZE
2+
ai/smollm2 361.82 M IQ2_XXS/Q4_K_M llama 354bf30d0aa3 3 months ago 256.35 MiB

e2e/shells/bash_test.sh

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/bin/bash
2+
3+
# Bash-specific e2e test for docker model list command with fixture validation
4+
# This script validates the output against the expected fixture
5+
6+
set -e
7+
8+
TEST_MODEL="ai/smollm2"
9+
FAILED_TESTS=0
10+
TOTAL_TESTS=0
11+
12+
# Colors for output
13+
RED='\033[0;31m'
14+
GREEN='\033[0;32m'
15+
NC='\033[0m' # No Color
16+
17+
log_info() {
18+
echo -e "${GREEN}[INFO]${NC} $1"
19+
}
20+
21+
log_success() {
22+
echo -e "${GREEN}[PASS]${NC} $1"
23+
}
24+
25+
log_error() {
26+
echo -e "${RED}[FAIL]${NC} $1"
27+
FAILED_TESTS=$((FAILED_TESTS + 1))
28+
}
29+
30+
# Load fixture file and normalize lines
31+
load_fixture() {
32+
local fixture_path="$1"
33+
if [ ! -f "$fixture_path" ]; then
34+
log_error "Fixture file not found: $fixture_path"
35+
return 1
36+
fi
37+
# Remove trailing whitespace
38+
sed 's/[[:space:]]*$//' "$fixture_path"
39+
}
40+
41+
run_test_with_fixture_validation() {
42+
local test_name="$1"
43+
local command="$2"
44+
local fixture_path="$3"
45+
local expected_exit_code="${4:-0}"
46+
47+
TOTAL_TESTS=$((TOTAL_TESTS + 1))
48+
log_info "Running test: $test_name"
49+
50+
# Load expected output from fixture
51+
expected_output=$(load_fixture "$fixture_path")
52+
53+
if [ $? -ne 0 ]; then
54+
log_error "$test_name - Failed to load fixture"
55+
return 1
56+
fi
57+
58+
# Run command and capture output and exit code
59+
set +e
60+
output=$(eval "$command" 2>&1)
61+
exit_code=$?
62+
set -e
63+
64+
# Normalize output: remove leading/trailing blank lines and trailing spaces
65+
normalized_output=$(echo "$output" | sed 's/[[:space:]]*$//')
66+
67+
if [ $exit_code -eq $expected_exit_code ] && [ "$normalized_output" = "$expected_output" ]; then
68+
log_success "$test_name"
69+
return 0
70+
else
71+
log_error "$test_name"
72+
echo "Command: $command"
73+
echo "Expected exit code: $expected_exit_code, got: $exit_code"
74+
echo "Expected output:"
75+
echo "$expected_output"
76+
echo "Actual normalized output:"
77+
echo "$normalized_output"
78+
return 1
79+
fi
80+
}
81+
82+
# Check prerequisites
83+
log_info "Checking prerequisites..."
84+
85+
# Ensure we're running from the correct directory
86+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
87+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
88+
cd "$PROJECT_ROOT"
89+
90+
# Check if docker model is available
91+
if ! command -v docker &> /dev/null; then
92+
log_error "docker command not found"
93+
exit 1
94+
fi
95+
96+
# Check if model runner is running
97+
if ! docker model status | grep -q "Docker Model Runner is running"; then
98+
log_error "Docker Model Runner is not running"
99+
exit 1
100+
fi
101+
102+
# Check if test model is available
103+
if ! docker model list | grep -q "$TEST_MODEL"; then
104+
log_info "Test model $TEST_MODEL not found, pulling..."
105+
docker model pull "$TEST_MODEL"
106+
fi
107+
108+
log_info "Starting fixture validation test..."
109+
110+
# Test: Fixture format validation
111+
run_test_with_fixture_validation "Fixture format validation" \
112+
"docker model list" \
113+
"e2e/fixtures/table_format/with_models.txt"
114+
115+
# Summary
116+
echo
117+
log_info "Test Summary:"
118+
echo "Total tests: $TOTAL_TESTS"
119+
echo "Failed tests: $FAILED_TESTS"
120+
echo "Passed tests: $((TOTAL_TESTS - FAILED_TESTS))"
121+
122+
if [ $FAILED_TESTS -eq 0 ]; then
123+
log_success "Fixture validation test passed!"
124+
exit 0
125+
else
126+
log_error "$FAILED_TESTS tests failed"
127+
exit 1
128+
fi

e2e/shells/cmd_test.bat

Whitespace-only changes.

e2e/shells/mintty_test.sh

Whitespace-only changes.

e2e/shells/zsh_test.sh

Whitespace-only changes.

0 commit comments

Comments
 (0)