-
-
Notifications
You must be signed in to change notification settings - Fork 917
Expand file tree
/
Copy pathrequires_internal_test.go
More file actions
44 lines (29 loc) · 1.15 KB
/
Copy pathrequires_internal_test.go
File metadata and controls
44 lines (29 loc) · 1.15 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
package task
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/go-task/task/v3/taskfile/ast"
)
func TestResolveEnumRefForPrompt(t *testing.T) {
t.Parallel()
vars := ast.NewVars()
vars.Set("ALLOWED_ENVS", ast.Var{Value: []any{"dev", "staging", "prod"}})
t.Run("resolves a static ref into values", func(t *testing.T) {
t.Parallel()
v := &ast.VarsWithValidation{Name: "ENV", Enum: &ast.Enum{Ref: ".ALLOWED_ENVS"}}
resolved := resolveEnumRefForPrompt(v, vars)
require.Equal(t, []string{"dev", "staging", "prod"}, getEnumValues(resolved.Enum))
require.Empty(t, v.Enum.Value, "input var must not be mutated")
require.Equal(t, ".ALLOWED_ENVS", v.Enum.Ref)
})
t.Run("leaves an unresolvable ref as-is", func(t *testing.T) {
t.Parallel()
v := &ast.VarsWithValidation{Name: "ENV", Enum: &ast.Enum{Ref: ".NONEXISTENT"}}
require.Empty(t, getEnumValues(resolveEnumRefForPrompt(v, vars).Enum))
})
t.Run("passes through a static enum unchanged", func(t *testing.T) {
t.Parallel()
v := &ast.VarsWithValidation{Name: "ENV", Enum: &ast.Enum{Value: []string{"a", "b"}}}
require.Same(t, v, resolveEnumRefForPrompt(v, vars))
})
}