|
4 | 4 | package app |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "strings" |
7 | 8 | "testing" |
8 | 9 |
|
9 | 10 | "github.com/spf13/cobra" |
| 11 | + |
| 12 | + "github.com/stacklok/toolhive/pkg/container/runtime" |
10 | 13 | ) |
11 | 14 |
|
12 | 15 | func TestAddFormatFlag(t *testing.T) { |
@@ -266,3 +269,38 @@ func TestIsOIDCEnabled(t *testing.T) { |
266 | 269 | }) |
267 | 270 | } |
268 | 271 | } |
| 272 | + |
| 273 | +func TestWorkloadStatusIndicator(t *testing.T) { |
| 274 | + t.Parallel() |
| 275 | + tests := []struct { |
| 276 | + name string |
| 277 | + status runtime.WorkloadStatus |
| 278 | + wantHas string // substring that must appear |
| 279 | + wantExact string // if non-empty, must match exactly |
| 280 | + }{ |
| 281 | + {"unauthenticated has ⚠️ prefix", runtime.WorkloadStatusUnauthenticated, "⚠️", ""}, |
| 282 | + {"auth_retrying has 🔄 prefix", runtime.WorkloadStatusAuthRetrying, "🔄", ""}, |
| 283 | + {"policy_stopped has 🚫 prefix", runtime.WorkloadStatusPolicyStopped, "🚫", ""}, |
| 284 | + {"running passes through plain", runtime.WorkloadStatusRunning, "", "running"}, |
| 285 | + {"stopped passes through plain", runtime.WorkloadStatusStopped, "", "stopped"}, |
| 286 | + {"unhealthy passes through plain", runtime.WorkloadStatusUnhealthy, "", "unhealthy"}, |
| 287 | + } |
| 288 | + for _, tc := range tests { |
| 289 | + t.Run(tc.name, func(t *testing.T) { |
| 290 | + t.Parallel() |
| 291 | + got := workloadStatusIndicator(tc.status) |
| 292 | + if tc.wantExact != "" && got != tc.wantExact { |
| 293 | + t.Errorf("workloadStatusIndicator(%q) = %q, want exact %q", |
| 294 | + tc.status, got, tc.wantExact) |
| 295 | + } |
| 296 | + if tc.wantHas != "" && !strings.Contains(got, tc.wantHas) { |
| 297 | + t.Errorf("workloadStatusIndicator(%q) = %q, want substring %q", |
| 298 | + tc.status, got, tc.wantHas) |
| 299 | + } |
| 300 | + if !strings.Contains(got, string(tc.status)) { |
| 301 | + t.Errorf("workloadStatusIndicator(%q) = %q, must include status name", |
| 302 | + tc.status, got) |
| 303 | + } |
| 304 | + }) |
| 305 | + } |
| 306 | +} |
0 commit comments