44 "context"
55 "testing"
66
7+ "github.com/dagu-org/dagu/internal/common/config"
78 "github.com/dagu-org/dagu/internal/core"
89 "github.com/dagu-org/dagu/internal/core/execution"
910 "github.com/dagu-org/dagu/internal/runtime"
@@ -13,6 +14,17 @@ import (
1314// Note: These tests use execution.SetupDAGContext to set up the DAG context,
1415// then use runtime.NewEnvForStep/GetEnv/WithEnv to manage the runtime Env.
1516
17+ // setupTestContext creates a test context with properly initialized DAGContext
18+ func setupTestContext () context.Context {
19+ ctx := context .Background ()
20+ baseEnv := config .NewBaseEnv (nil )
21+ dagCtx := execution.DAGContext {
22+ DAG : & core.DAG {Name : "test-dag" },
23+ BaseEnv : & baseEnv ,
24+ }
25+ return execution .WithDAGContext (ctx , dagCtx )
26+ }
27+
1628func TestEvalString (t * testing.T ) {
1729 t .Parallel ()
1830
@@ -157,8 +169,8 @@ type NestedStruct struct {
157169}
158170
159171func TestEvalObject (t * testing.T ) {
160- // Create a test context with environment variables
161- ctx := context . Background ()
172+ // Create a test context with DAGContext and environment variables
173+ ctx := setupTestContext ()
162174 env := runtime .NewEnvForStep (ctx , core.Step {Name : "test-step" })
163175 env .Variables .Store ("NAME_VAR" , "NAME_VAR=John" )
164176 env .Variables .Store ("DESC_VAR" , "DESC_VAR=Developer" )
@@ -199,8 +211,8 @@ func TestEvalObject(t *testing.T) {
199211func TestEvalObjectWithExecutorConfig (t * testing.T ) {
200212 t .Parallel ()
201213
202- // Create a test context with environment variables
203- ctx := context . Background ()
214+ // Create a test context with DAGContext and environment variables
215+ ctx := setupTestContext ()
204216 env := runtime .NewEnvForStep (ctx , core.Step {Name : "test-step" })
205217 env .Variables .Store ("EXECUTOR_TYPE" , "EXECUTOR_TYPE=docker" )
206218 env .Variables .Store ("HOST_VAR" , "HOST_VAR=localhost" )
@@ -308,8 +320,8 @@ func TestGenerateSubDAGRunID(t *testing.T) {
308320func TestEvalObjectWithComplexNestedStructures (t * testing.T ) {
309321 t .Parallel ()
310322
311- // Create a test context with environment variables
312- ctx := context . Background ()
323+ // Create a test context with DAGContext and environment variables
324+ ctx := setupTestContext ()
313325 env := runtime .NewEnvForStep (ctx , core.Step {Name : "test-step" })
314326 env .Variables .Store ("VAR1" , "VAR1=value1" )
315327 env .Variables .Store ("VAR2" , "VAR2=value2" )
@@ -534,8 +546,8 @@ func TestEvalStringEdgeCases(t *testing.T) {
534546}
535547
536548func TestEvalObjectWithDirectStringEvaluation (t * testing.T ) {
537- // Create a test context with environment variables
538- ctx := context . Background ()
549+ // Create a test context with DAGContext and environment variables
550+ ctx := setupTestContext ()
539551 env := runtime .NewEnvForStep (ctx , core.Step {Name : "test-step" })
540552 env .Variables .Store ("STRING_VAR" , "STRING_VAR=evaluated_string" )
541553 env .Variables .Store ("PATH_VAR" , "PATH_VAR=/path/to/file" )
0 commit comments