Skip to content

Commit 43d3315

Browse files
committed
Go SDK: test the per-Dag source alias check through runPack
The old test called rejectOutputAlias directly, so removing the call in runPack for per-Dag files kept the suite green.
1 parent 0d5f0e3 commit 43d3315

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

‎go-sdk/cmd/airflow-go-pack/sources_test.go‎

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ import (
2121
"bytes"
2222
"crypto/sha256"
2323
"encoding/hex"
24+
"io"
2425
"os"
2526
"os/exec"
2627
"path/filepath"
2728
"runtime"
29+
"strconv"
2830
"testing"
2931

3032
"github.com/stretchr/testify/assert"
@@ -289,20 +291,32 @@ func TestRunPack_DagFileOutsideModuleFallsBackToEntrypoint(t *testing.T) {
289291
)
290292
}
291293

292-
func TestRejectOutputAlias_EmbeddedSourceFile(t *testing.T) {
293-
dir := t.TempDir()
294-
exe := filepath.Join(dir, "exe")
295-
entry := filepath.Join(dir, "main.go")
296-
other := filepath.Join(dir, "dag.go")
297-
for _, p := range []string{exe, entry, other} {
298-
require.NoError(t, os.WriteFile(p, []byte("x"), 0o644))
299-
}
294+
func TestRunPack_RejectsOutputAliasingDagSourceFile(t *testing.T) {
295+
dir := writeModule(t, "example.com/app", map[string]string{
296+
"main.go": "package main\nfunc main() {}\n",
297+
"dags/reports.go": "package dags\n",
298+
})
299+
exe := filepath.Join(dir, "prebuilt")
300+
require.NoError(t, os.WriteFile(exe, []byte("prebuilt-binary-bytes"), 0o755))
301+
reports := filepath.Join(dir, "dags", "reports.go")
302+
meta := filepath.Join(dir, "airflow-metadata.json")
303+
require.NoError(t, os.WriteFile(meta, []byte(
304+
`{"airflow_bundle_metadata_version":"1.0",`+
305+
`"sdk":{"language":"go","version":"0.1.0","supervisor_schema_version":"2026-06-16"},`+
306+
`"dags":{},"dag_source_files":{"reports":`+strconv.Quote(reports)+`}}`,
307+
), 0o644))
300308

301-
err := rejectOutputAlias(other, exe, []string{entry, other}, "")
302-
require.Error(t, err)
303-
assert.Contains(t, err.Error(), "same file as the source")
309+
err := runPack(io.Discard, io.Discard, &packOptions{
310+
executable: exe,
311+
source: filepath.Join(dir, "main.go"),
312+
airflowMetadata: meta,
313+
output: reports,
314+
})
315+
require.ErrorContains(t, err, "same file as the source")
304316

305-
assert.NoError(t, rejectOutputAlias(filepath.Join(dir, "out"), exe, []string{entry, other}, ""))
317+
got, readErr := os.ReadFile(reports)
318+
require.NoError(t, readErr)
319+
assert.Equal(t, "package dags\n", string(got))
306320
}
307321

308322
// Packs the multidag fixture through the real build path: three Dag files across two imported

0 commit comments

Comments
 (0)