|
7 | 7 | "github.com/stackitcloud/stackit-cli/internal/cmd/params"
|
8 | 8 | "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
|
9 | 9 | "github.com/stackitcloud/stackit-cli/internal/pkg/print"
|
| 10 | + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" |
10 | 11 |
|
11 | 12 | "github.com/google/go-cmp/cmp"
|
12 | 13 | "github.com/google/go-cmp/cmp/cmpopts"
|
@@ -234,6 +235,184 @@ func TestOutputResult(t *testing.T) {
|
234 | 235 | },
|
235 | 236 | wantErr: false,
|
236 | 237 | },
|
| 238 | + { |
| 239 | + name: "cluster with single error", |
| 240 | + args: args{ |
| 241 | + outputFormat: "", |
| 242 | + cluster: &ske.Cluster{ |
| 243 | + Name: utils.Ptr("test-cluster"), |
| 244 | + Status: &ske.ClusterStatus{ |
| 245 | + Errors: &[]ske.ClusterError{ |
| 246 | + { |
| 247 | + Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"), |
| 248 | + Message: utils.Ptr("Network configuration not found"), |
| 249 | + }, |
| 250 | + }, |
| 251 | + }, |
| 252 | + }, |
| 253 | + }, |
| 254 | + wantErr: false, |
| 255 | + }, |
| 256 | + { |
| 257 | + name: "cluster with multiple errors", |
| 258 | + args: args{ |
| 259 | + outputFormat: "", |
| 260 | + cluster: &ske.Cluster{ |
| 261 | + Name: utils.Ptr("test-cluster"), |
| 262 | + Status: &ske.ClusterStatus{ |
| 263 | + Errors: &[]ske.ClusterError{ |
| 264 | + { |
| 265 | + Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"), |
| 266 | + Message: utils.Ptr("Network configuration not found"), |
| 267 | + }, |
| 268 | + { |
| 269 | + Code: utils.Ptr("SKE_NODE_MACHINE_TYPE_NOT_FOUND"), |
| 270 | + Message: utils.Ptr("Specified machine type unavailable"), |
| 271 | + }, |
| 272 | + { |
| 273 | + Code: utils.Ptr("SKE_FETCHING_ERRORS_NOT_POSSIBLE"), |
| 274 | + Message: utils.Ptr("Fetching errors not possible"), |
| 275 | + }, |
| 276 | + }, |
| 277 | + }, |
| 278 | + }, |
| 279 | + }, |
| 280 | + wantErr: false, |
| 281 | + }, |
| 282 | + { |
| 283 | + name: "cluster with error but no message", |
| 284 | + args: args{ |
| 285 | + outputFormat: "", |
| 286 | + cluster: &ske.Cluster{ |
| 287 | + Name: utils.Ptr("test-cluster"), |
| 288 | + Status: &ske.ClusterStatus{ |
| 289 | + Errors: &[]ske.ClusterError{ |
| 290 | + { |
| 291 | + Code: utils.Ptr("SKE_FETCHING_ERRORS_NOT_POSSIBLE"), |
| 292 | + }, |
| 293 | + }, |
| 294 | + }, |
| 295 | + }, |
| 296 | + }, |
| 297 | + wantErr: false, |
| 298 | + }, |
| 299 | + { |
| 300 | + name: "cluster with nil errors", |
| 301 | + args: args{ |
| 302 | + outputFormat: "", |
| 303 | + cluster: &ske.Cluster{ |
| 304 | + Name: utils.Ptr("test-cluster"), |
| 305 | + Status: &ske.ClusterStatus{ |
| 306 | + Errors: nil, |
| 307 | + }, |
| 308 | + }, |
| 309 | + }, |
| 310 | + wantErr: false, |
| 311 | + }, |
| 312 | + { |
| 313 | + name: "cluster with empty errors array", |
| 314 | + args: args{ |
| 315 | + outputFormat: "", |
| 316 | + cluster: &ske.Cluster{ |
| 317 | + Name: utils.Ptr("test-cluster"), |
| 318 | + Status: &ske.ClusterStatus{ |
| 319 | + Errors: &[]ske.ClusterError{}, |
| 320 | + }, |
| 321 | + }, |
| 322 | + }, |
| 323 | + wantErr: false, |
| 324 | + }, |
| 325 | + { |
| 326 | + name: "cluster without status", |
| 327 | + args: args{ |
| 328 | + outputFormat: "", |
| 329 | + cluster: &ske.Cluster{ |
| 330 | + Name: utils.Ptr("test-cluster"), |
| 331 | + }, |
| 332 | + }, |
| 333 | + wantErr: false, |
| 334 | + }, |
| 335 | + { |
| 336 | + name: "JSON output format with errors", |
| 337 | + args: args{ |
| 338 | + outputFormat: print.JSONOutputFormat, |
| 339 | + cluster: &ske.Cluster{ |
| 340 | + Name: utils.Ptr("test-cluster"), |
| 341 | + Status: &ske.ClusterStatus{ |
| 342 | + Errors: &[]ske.ClusterError{ |
| 343 | + { |
| 344 | + Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"), |
| 345 | + Message: utils.Ptr("Network configuration not found"), |
| 346 | + }, |
| 347 | + }, |
| 348 | + }, |
| 349 | + }, |
| 350 | + }, |
| 351 | + wantErr: false, |
| 352 | + }, |
| 353 | + { |
| 354 | + name: "YAML output format with errors", |
| 355 | + args: args{ |
| 356 | + outputFormat: print.YAMLOutputFormat, |
| 357 | + cluster: &ske.Cluster{ |
| 358 | + Name: utils.Ptr("test-cluster"), |
| 359 | + Status: &ske.ClusterStatus{ |
| 360 | + Errors: &[]ske.ClusterError{ |
| 361 | + { |
| 362 | + Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"), |
| 363 | + Message: utils.Ptr("Network configuration not found"), |
| 364 | + }, |
| 365 | + }, |
| 366 | + }, |
| 367 | + }, |
| 368 | + }, |
| 369 | + wantErr: false, |
| 370 | + }, |
| 371 | + { |
| 372 | + name: "cluster with kubernetes info and errors", |
| 373 | + args: args{ |
| 374 | + outputFormat: "", |
| 375 | + cluster: &ske.Cluster{ |
| 376 | + Name: utils.Ptr("test-cluster"), |
| 377 | + Kubernetes: &ske.Kubernetes{ |
| 378 | + Version: utils.Ptr("1.28.0"), |
| 379 | + }, |
| 380 | + Status: &ske.ClusterStatus{ |
| 381 | + Errors: &[]ske.ClusterError{ |
| 382 | + { |
| 383 | + Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"), |
| 384 | + Message: utils.Ptr("Network configuration not found"), |
| 385 | + }, |
| 386 | + }, |
| 387 | + }, |
| 388 | + }, |
| 389 | + }, |
| 390 | + wantErr: false, |
| 391 | + }, |
| 392 | + { |
| 393 | + name: "cluster with extensions and errors", |
| 394 | + args: args{ |
| 395 | + outputFormat: "", |
| 396 | + cluster: &ske.Cluster{ |
| 397 | + Name: utils.Ptr("test-cluster"), |
| 398 | + Extensions: &ske.Extension{ |
| 399 | + Acl: &ske.ACL{ |
| 400 | + AllowedCidrs: &[]string{"10.0.0.0/8"}, |
| 401 | + Enabled: utils.Ptr(true), |
| 402 | + }, |
| 403 | + }, |
| 404 | + Status: &ske.ClusterStatus{ |
| 405 | + Errors: &[]ske.ClusterError{ |
| 406 | + { |
| 407 | + Code: utils.Ptr("SKE_INFRA_SNA_NETWORK_NOT_FOUND"), |
| 408 | + Message: utils.Ptr("Network configuration not found"), |
| 409 | + }, |
| 410 | + }, |
| 411 | + }, |
| 412 | + }, |
| 413 | + }, |
| 414 | + wantErr: false, |
| 415 | + }, |
237 | 416 | }
|
238 | 417 | p := print.NewPrinter()
|
239 | 418 | p.Cmd = NewCmd(¶ms.CmdParams{Printer: p})
|
|
0 commit comments