| 1 | package execution_testscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution_test`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src go1.25 context/" |
| 5 | "stringsscip-go gomod github.com/golang/go/src go1.25 strings/" |
| 6 | "testingscip-go gomod github.com/golang/go/src go1.25 testing/" |
| 7 | |
| 8 | "github.com/tomwright/dasel/v3/executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/" |
| 9 | "github.com/tomwright/dasel/v3/modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/" |
| 10 | ) |
| 11 | |
| 12 | func TestVariablescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution_test`/TestVariable().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 13 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("use passed variable", testCasescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution_test`/testCase#{ |
| 14 | sscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution_test`/testCase#s.: `$x + 1`, |
| 15 | outscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution_test`/testCase#out.: modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewIntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewIntValue().(11), |
| 16 | optsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution_test`/testCase#opts.: []executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/.ExecuteOptionFnscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/ExecuteOptionFn#{ |
| 17 | executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/.WithVariablescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/WithVariable().("x", modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewIntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewIntValue().(10)), |
| 18 | }, |
| 19 | }.runscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution_test`/testCase#run().) |
| 20 | |
| 21 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("variable in expression", testCasescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution_test`/testCase#{ |
| 22 | sscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution_test`/testCase#s.: `$x + $y`, |
| 23 | outscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution_test`/testCase#out.: modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewIntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewIntValue().(30), |
| 24 | optsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution_test`/testCase#opts.: []executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/.ExecuteOptionFnscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/ExecuteOptionFn#{ |
| 25 | executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/.WithVariablescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/WithVariable().("x", modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewIntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewIntValue().(10)), |
| 26 | executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/.WithVariablescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/WithVariable().("y", modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewIntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewIntValue().(20)), |
| 27 | }, |
| 28 | }.runscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution_test`/testCase#run().) |
| 29 | |
| 30 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("undefined variable errors", func(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 31 | in := modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewNullValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewNullValue().() |
| 32 | _, err := executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/.ExecuteSelectorscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/ExecuteSelector().(contextscip-go gomod github.com/golang/go/src go1.25 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25 context/Background().(), `$undefined_var_xyz`, in, executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/.NewOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/NewOptions().()) |
| 33 | if err == nil { |
| 34 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().("expected error for undefined variable") |
| 35 | } |
| 36 | if !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(err.Error(), "not found") { |
| 37 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("unexpected error: %s", err) |
| 38 | } |
| 39 | }) |
| 40 | |
| 41 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("env variable", func(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 42 | t.Setenvscip-go gomod github.com/golang/go/src go1.25 testing/T#Setenv().("DASEL_TEST_VAR_ABC", "from_env") |
| 43 | in := modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewNullValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewNullValue().() |
| 44 | res, err := executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/.ExecuteSelectorscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/ExecuteSelector().(contextscip-go gomod github.com/golang/go/src go1.25 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25 context/Background().(), `$DASEL_TEST_VAR_ABC`, in, executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/.NewOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/NewOptions().()) |
| 45 | if err != nil { |
| 46 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 47 | } |
| 48 | got, err := res.StringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#StringValue().() |
| 49 | if err != nil { |
| 50 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 51 | } |
| 52 | if got != "from_env" { |
| 53 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected 'from_env', got %s", got) |
| 54 | } |
| 55 | }) |
| 56 | } |