|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package tfe |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/stretchr/testify/require" |
| 11 | +) |
| 12 | + |
| 13 | +func Test_validateAdminRunFilterParams(t *testing.T) { |
| 14 | + // All RunStatus values - keep this in sync with run.go |
| 15 | + validRunStatuses := []string{ |
| 16 | + "applied", |
| 17 | + "applying", |
| 18 | + "apply_queued", |
| 19 | + "canceled", |
| 20 | + "confirmed", |
| 21 | + "cost_estimated", |
| 22 | + "cost_estimating", |
| 23 | + "discarded", |
| 24 | + "errored", |
| 25 | + "fetching", |
| 26 | + "fetching_completed", |
| 27 | + "pending", |
| 28 | + "planned", |
| 29 | + "planned_and_finished", |
| 30 | + "planned_and_saved", |
| 31 | + "planning", |
| 32 | + "plan_queued", |
| 33 | + "policy_checked", |
| 34 | + "policy_checking", |
| 35 | + "policy_override", |
| 36 | + "policy_soft_failed", |
| 37 | + "post_plan_awaiting_decision", |
| 38 | + "post_plan_completed", |
| 39 | + "post_plan_running", |
| 40 | + "pre_apply_running", |
| 41 | + "pre_apply_completed", |
| 42 | + "pre_plan_completed", |
| 43 | + "pre_plan_running", |
| 44 | + "queuing", |
| 45 | + "queuing_apply", |
| 46 | + } |
| 47 | + for _, v := range validRunStatuses { |
| 48 | + t.Run(v, func(t *testing.T) { |
| 49 | + require.NoError(t, validateAdminRunFilterParams(v), fmt.Sprintf("'%s' should be valid", v)) |
| 50 | + }) |
| 51 | + } |
| 52 | + |
| 53 | + // empty string is allowed |
| 54 | + require.NoError(t, validateAdminRunFilterParams(""), "empty string should be valid") |
| 55 | + |
| 56 | + // comma-separated list, all valid |
| 57 | + require.NoError(t, validateAdminRunFilterParams("applied,planned,canceled"), "'applied,planned,canceled' should be valid)") |
| 58 | + |
| 59 | + // invalid values |
| 60 | + require.Error(t, validateAdminRunFilterParams("cost_estimate"), "invalid value: cost_estimate") |
| 61 | + |
| 62 | + // comma-separated list, some invalid |
| 63 | + require.Error(t, validateAdminRunFilterParams("applied,not-planned,canceled"), "'applied,not-planned,canceled' should be invalid)") |
| 64 | +} |
0 commit comments