From 1d61a557bfe9915c36665fca759c0c395388ce4b Mon Sep 17 00:00:00 2001 From: yohamta Date: Thu, 4 Aug 2022 19:25:21 +0900 Subject: [PATCH 1/2] Allow DAGs to be loaded without specifying an extension --- cmd/start_test.go | 4 ++++ internal/config/loader.go | 3 +++ internal/config/loader_test.go | 5 +++++ tests/testdata/cmd_start_success.yaml | 3 +++ 4 files changed, 15 insertions(+) create mode 100644 tests/testdata/cmd_start_success.yaml diff --git a/cmd/start_test.go b/cmd/start_test.go index 0ed96727d..d2614bc66 100644 --- a/cmd/start_test.go +++ b/cmd/start_test.go @@ -18,6 +18,10 @@ func Test_startCommand(t *testing.T) { args: []string{"", "start", "--params=x y", testConfig("cmd_start_with_params_2.yaml")}, errored: false, output: []string{"params are x and y"}, }, + { + args: []string{"", "start", testConfig("cmd_start_success")}, errored: false, + output: []string{"1 finished"}, + }, } for _, v := range tests { diff --git a/internal/config/loader.go b/internal/config/loader.go index 186f7ad87..9f1c3e3fe 100644 --- a/internal/config/loader.go +++ b/internal/config/loader.go @@ -109,6 +109,9 @@ func (cl *Loader) loadConfig(f string, opts *BuildConfigOptions) (*Config, error if f == "" { return nil, fmt.Errorf("config file was not specified") } + if !strings.HasSuffix(f, ".yaml") && !strings.HasSuffix(f, ".yml") { + f = fmt.Sprintf("%s.yaml", f) + } file, err := filepath.Abs(f) if err != nil { return nil, err diff --git a/internal/config/loader_test.go b/internal/config/loader_test.go index 73555d2e0..dcf9f0e6e 100644 --- a/internal/config/loader_test.go +++ b/internal/config/loader_test.go @@ -15,6 +15,11 @@ func TestLoadConfig(t *testing.T) { } _, err := l.Load(testConfig, "") require.NoError(t, err) + + // without .yaml + s := path.Join(testDir, "config_load") + _, err = l.Load(s, "") + require.NoError(t, err) } func TestLoadGlobalConfig(t *testing.T) { diff --git a/tests/testdata/cmd_start_success.yaml b/tests/testdata/cmd_start_success.yaml new file mode 100644 index 000000000..945467f2b --- /dev/null +++ b/tests/testdata/cmd_start_success.yaml @@ -0,0 +1,3 @@ +steps: + - name: "1" + command: "true" \ No newline at end of file From 46fb89df85dfce21168eddbbd3dd91686ff40949 Mon Sep 17 00:00:00 2001 From: yohamta Date: Thu, 4 Aug 2022 19:49:23 +0900 Subject: [PATCH 2/2] Add subdag examples --- examples/calling_subdag_main.yaml | 3 +++ examples/calling_subdag_sub.yaml | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 examples/calling_subdag_main.yaml create mode 100644 examples/calling_subdag_sub.yaml diff --git a/examples/calling_subdag_main.yaml b/examples/calling_subdag_main.yaml new file mode 100644 index 000000000..7cac6cdb6 --- /dev/null +++ b/examples/calling_subdag_main.yaml @@ -0,0 +1,3 @@ +steps: + - name: step1 + command: dagu start calling_subdag_sub diff --git a/examples/calling_subdag_sub.yaml b/examples/calling_subdag_sub.yaml new file mode 100644 index 000000000..b072c5ac3 --- /dev/null +++ b/examples/calling_subdag_sub.yaml @@ -0,0 +1,3 @@ +steps: + - name: step1 + command: echo hello