-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-workspace-system.sh
More file actions
executable file
·272 lines (223 loc) · 7.34 KB
/
test-workspace-system.sh
File metadata and controls
executable file
·272 lines (223 loc) · 7.34 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/bin/bash
# Test Workspace Management System
# Validates that the workspace management system works correctly
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
# Test workspace configuration file
test_workspace_config() {
print_info "Testing workspace configuration file..."
local config_file="$SCRIPT_DIR/.devpod-workspace-config"
if [[ ! -f "$config_file" ]]; then
print_error "Workspace config file not found: $config_file"
return 1
fi
# Check if config has all expected projects
local expected_projects=(
"nodejs-project"
"java17-project"
"python3-project"
"react-project"
"angular-project"
"mern-fullstack"
"angular-java-fullstack"
"postgresql-devpod-project"
)
for project in "${expected_projects[@]}"; do
if grep -q "$project" "$config_file"; then
print_success "Config includes: $project"
else
print_error "Config missing: $project"
fi
done
}
# Test manage-workspaces.sh script
test_workspace_manager() {
print_info "Testing workspace manager script..."
local manager_script="$SCRIPT_DIR/manage-workspaces.sh"
if [[ ! -f "$manager_script" ]]; then
print_error "Workspace manager script not found: $manager_script"
return 1
fi
if [[ ! -x "$manager_script" ]]; then
print_error "Workspace manager script not executable: $manager_script"
return 1
fi
print_success "Workspace manager script exists and is executable"
# Test script help output
if "$manager_script" help > /dev/null 2>&1; then
print_success "Workspace manager help command works"
else
print_warning "Workspace manager help command failed"
fi
}
# Test project devcontainer files
test_project_devcontainers() {
print_info "Testing project devcontainer configurations..."
local projects_dir="$SCRIPT_DIR/projects"
if [[ ! -d "$projects_dir" ]]; then
print_error "Projects directory not found: $projects_dir"
return 1
fi
local projects=($(find "$projects_dir" -maxdepth 1 -type d -name "*-project"))
for project_path in "${projects[@]}"; do
local project_name=$(basename "$project_path")
local devcontainer_file="$project_path/.devcontainer/devcontainer.json"
if [[ -f "$devcontainer_file" ]]; then
# Check if file has proper workspace folder naming
if grep -q "/workspaces/${project_name}-workspace" "$devcontainer_file"; then
print_success "$project_name: devcontainer has standardized workspace folder"
else
print_warning "$project_name: devcontainer may not have standardized workspace folder"
fi
# Check if file has proper name
if grep -q '"name":' "$devcontainer_file"; then
local name=$(grep '"name":' "$devcontainer_file" | head -n1)
print_info "$project_name: $name"
fi
else
print_warning "$project_name: No devcontainer.json found"
fi
done
}
# Test project workspace scripts
test_project_scripts() {
print_info "Testing project workspace scripts..."
local projects_dir="$SCRIPT_DIR/projects"
local projects=($(find "$projects_dir" -maxdepth 1 -type d -name "*-project"))
for project_path in "${projects[@]}"; do
local project_name=$(basename "$project_path")
local script_file="$project_path/open-workspace.sh"
if [[ -f "$script_file" ]]; then
if [[ -x "$script_file" ]]; then
print_success "$project_name: workspace script exists and is executable"
else
print_warning "$project_name: workspace script exists but not executable"
fi
else
print_warning "$project_name: no workspace script found"
fi
done
}
# Test DevPod CLI availability
test_devpod_cli() {
print_info "Testing DevPod CLI availability..."
if command -v devpod &> /dev/null; then
local version=$(devpod version 2>/dev/null || echo "unknown")
print_success "DevPod CLI available: $version"
# Test list workspaces
if devpod list 2>/dev/null | head -n1 > /dev/null; then
print_success "DevPod list command works"
else
print_warning "DevPod list command failed (may be normal if no workspaces exist)"
fi
else
print_error "DevPod CLI not found in PATH"
print_info "Please install DevPod from: https://devpod.sh"
fi
}
# Test directory structure
test_directory_structure() {
print_info "Testing directory structure..."
local expected_files=(
"manage-workspaces.sh"
".devpod-workspace-config"
"update-all-workspaces.sh"
"projects"
)
for file in "${expected_files[@]}"; do
if [[ -e "$SCRIPT_DIR/$file" ]]; then
print_success "Found: $file"
else
print_error "Missing: $file"
fi
done
}
# Test JSON parsing dependency
test_dependencies() {
print_info "Testing dependencies..."
if command -v jq &> /dev/null; then
print_success "jq (JSON parser) available"
else
print_error "jq not found - required for JSON parsing"
print_info "Install with: sudo apt install jq"
fi
}
# Run all tests
run_all_tests() {
echo "=============================================="
echo "Testing DevPod Workspace Management System"
echo "=============================================="
echo ""
test_directory_structure
echo ""
test_dependencies
echo ""
test_devpod_cli
echo ""
test_workspace_config
echo ""
test_workspace_manager
echo ""
test_project_devcontainers
echo ""
test_project_scripts
echo ""
echo "=============================================="
print_info "Test completed!"
echo ""
print_info "Next steps:"
print_info "1. If any tests failed, address the issues"
print_info "2. Run './update-all-workspaces.sh' to update all projects"
print_info "3. Run './manage-workspaces.sh status' to check current workspaces"
print_info "4. Test with DevPod Desktop for workspace reuse"
echo "=============================================="
}
# Main function
main() {
case "${1:-all}" in
"config")
test_workspace_config
;;
"manager")
test_workspace_manager
;;
"devcontainers")
test_project_devcontainers
;;
"scripts")
test_project_scripts
;;
"devpod")
test_devpod_cli
;;
"deps")
test_dependencies
;;
"structure")
test_directory_structure
;;
"all"|*)
run_all_tests
;;
esac
}
# Run main function
main "$@"