From 70cf9331687f68a8469ffa9b5126a34310c56cd9 Mon Sep 17 00:00:00 2001 From: Eliott Bouhana Date: Wed, 20 Nov 2024 14:09:26 +0100 Subject: [PATCH 1/2] fix(pin): segfault orchestrion.tool.go is not valid go code Signed-off-by: Eliott Bouhana --- internal/pin/pin.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/pin/pin.go b/internal/pin/pin.go index 7d1e3f06..8b03c9ac 100644 --- a/internal/pin/pin.go +++ b/internal/pin/pin.go @@ -65,6 +65,10 @@ func PinOrchestrion(opts Options) error { dstFile = defaultOrchestrionToolGo() } + if err != nil { + return fmt.Errorf("parsing %q: %w", toolFile, err) + } + updateGoGenerateDirective(opts.NoGenerate, dstFile) importSet, err := updateToolFile(dstFile) From ee071fa18f80f19bb59f111db0b60bf9d200b707 Mon Sep 17 00:00:00 2001 From: Eliott Bouhana Date: Wed, 20 Nov 2024 14:16:18 +0100 Subject: [PATCH 2/2] test(pin): add empty orchestrion.tool.go test Signed-off-by: Eliott Bouhana --- internal/pin/pin.go | 3 ++- internal/pin/pin_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/pin/pin.go b/internal/pin/pin.go index 8b03c9ac..7fa647c0 100644 --- a/internal/pin/pin.go +++ b/internal/pin/pin.go @@ -63,10 +63,11 @@ func PinOrchestrion(opts Options) error { if errors.Is(err, os.ErrNotExist) { log.Debugf("no %q file found, creating a new one", config.FilenameOrchestrionToolGo) dstFile = defaultOrchestrionToolGo() + err = nil } if err != nil { - return fmt.Errorf("parsing %q: %w", toolFile, err) + return err } updateGoGenerateDirective(opts.NoGenerate, dstFile) diff --git a/internal/pin/pin_test.go b/internal/pin/pin_test.go index 53bd37e8..7e812771 100644 --- a/internal/pin/pin_test.go +++ b/internal/pin/pin_test.go @@ -93,6 +93,16 @@ func TestPin(t *testing.T) { assert.NotContains(t, data.Require, goModRequire{"github.com/digitalocean/sample-golang", "v0.0.0-20240904143939-1e058723dcf4"}) assert.NotContains(t, data.Require, goModRequire{"github.com/skyrocknroll/go-mod-example", "v0.0.0-20190130140558-29b3c92445e5"}) }) + + t.Run("empty-tool-dot-go", func(t *testing.T) { + tmp := scaffold(t, make(map[string]string)) + require.NoError(t, os.Chdir(tmp)) + + toolDotGo := filepath.Join(tmp, config.FilenameOrchestrionToolGo) + require.NoError(t, os.WriteFile(toolDotGo, nil, 0644)) + + require.ErrorContains(t, PinOrchestrion(Options{}), "expected 'package', found 'EOF'") + }) } var goModTemplate = template.Must(template.New("go-mod").Parse(`module github.com/DataDog/orchestrion/pin-test