Skip to content

Commit

Permalink
fix(pin): segfault orchestrion.tool.go is not valid go code (#407)
Browse files Browse the repository at this point in the history
Triggered it on top of #406 because it left the `orchestrion.tool.go`
file empty. And an empty file is not valid go code...

---------

Signed-off-by: Eliott Bouhana <[email protected]>
  • Loading branch information
eliottness authored Nov 21, 2024
1 parent 770042c commit 04b4196
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/pin/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +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 err
}

updateGoGenerateDirective(opts.NoGenerate, dstFile)
Expand Down
10 changes: 10 additions & 0 deletions internal/pin/pin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 04b4196

Please sign in to comment.