MCPcopy
hub / github.com/TomWright/dasel / TestErrors

Function TestErrors

execution/execute_error_test.go:12–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestErrors(t *testing.T) {
13 t.Run("unknown function", func(t *testing.T) {
14 in := model.NewNullValue()
15 _, err := execution.ExecuteSelector(context.Background(), `unknownFunc123()`, in, execution.NewOptions())
16 if err == nil {
17 t.Fatal("expected error for unknown function")
18 }
19 if !strings.Contains(err.Error(), "unknown function") {
20 t.Fatalf("unexpected error: %s", err)
21 }
22 })
23
24 t.Run("empty selector returns input", func(t *testing.T) {
25 in := model.NewStringValue("hello")
26 res, err := execution.ExecuteSelector(context.Background(), ``, in, execution.NewOptions())
27 if err != nil {
28 t.Fatal(err)
29 }
30 got, err := res.StringValue()
31 if err != nil {
32 t.Fatal(err)
33 }
34 if got != "hello" {
35 t.Errorf("expected 'hello', got %s", got)
36 }
37 })
38
39 t.Run("filter on non-array", func(t *testing.T) {
40 in := model.NewStringValue("not a slice")
41 _, err := execution.ExecuteSelector(context.Background(), `filter($this == "x")`, in, execution.NewOptions())
42 if err == nil {
43 t.Fatal("expected error for filter on non-array")
44 }
45 })
46
47 t.Run("each on non-array", func(t *testing.T) {
48 in := model.NewStringValue("not a slice")
49 _, err := execution.ExecuteSelector(context.Background(), `each($this = $this)`, in, execution.NewOptions())
50 if err == nil {
51 t.Fatal("expected error for each on non-array")
52 }
53 })
54
55 t.Run("sortBy on non-array", func(t *testing.T) {
56 in := model.NewStringValue("not a slice")
57 _, err := execution.ExecuteSelector(context.Background(), `sortBy($this)`, in, execution.NewOptions())
58 if err == nil {
59 t.Fatal("expected error for sortBy on non-array")
60 }
61 })
62
63 t.Run("map on non-array", func(t *testing.T) {
64 in := model.NewStringValue("not a slice")
65 _, err := execution.ExecuteSelector(context.Background(), `map($this)`, in, execution.NewOptions())
66 if err == nil {
67 t.Fatal("expected error for map on non-array")
68 }
69 })

Callers

nothing calls this directly

Calls 8

NewNullValueFunction · 0.92
ExecuteSelectorFunction · 0.92
NewOptionsFunction · 0.92
NewStringValueFunction · 0.92
NewIntValueFunction · 0.92
StringValueMethod · 0.80
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected