From 5f01b57da8c2aa1795abb67e6fb12277264a6fb1 Mon Sep 17 00:00:00 2001 From: Michael Chernov <4ernovm@gmail.com> Date: Tue, 9 Jan 2024 13:46:17 +0200 Subject: [PATCH] Fix failing nuget job (#180) --- internal/resolution/pm/nuget/job.go | 9 ++++++-- internal/resolution/pm/nuget/job_test.go | 19 +++++++++++++++++ .../nuget/testdata/empty_cmd_factory_mock.go | 21 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 internal/resolution/pm/nuget/testdata/empty_cmd_factory_mock.go diff --git a/internal/resolution/pm/nuget/job.go b/internal/resolution/pm/nuget/job.go index 5ea6a545..446c8549 100644 --- a/internal/resolution/pm/nuget/job.go +++ b/internal/resolution/pm/nuget/job.go @@ -60,11 +60,16 @@ func (j *Job) Run() { var osRemoveAll = os.RemoveAll func (j *Job) runInstallCmd() ([]byte, string, error) { - j.nugetCommand = nuget installCmd, err := j.cmdFactory.MakeInstallCmd(j.nugetCommand, j.GetFile()) + if err != nil { - return nil, installCmd.String(), err + command := "" + if installCmd != nil { + command = installCmd.String() + } + + return nil, command, err } installCmdOutput, err := installCmd.Output() diff --git a/internal/resolution/pm/nuget/job_test.go b/internal/resolution/pm/nuget/job_test.go index 3693ab7c..1b799345 100644 --- a/internal/resolution/pm/nuget/job_test.go +++ b/internal/resolution/pm/nuget/job_test.go @@ -146,3 +146,22 @@ func TestRunInstallCmdOutputErr(t *testing.T) { jobTestdata.AssertPathErr(t, j.Errors()) } + +func TestNoCmdOutputError(t *testing.T) { + cmdErr := errors.New("") + cmdFactoryMock := testdata.NewEmptyCmdFactory() + cmdFactoryMock.MakeErr = cmdErr + + expectedError := util.NewPMJobError("\n") + expectedError.SetStatus("installing dependencies") + + j := NewJob("file", true, cmdFactoryMock) + + go jobTestdata.WaitStatus(j) + j.Run() + + allErrors := j.Errors().GetAll() + + assert.Len(t, j.Errors().GetAll(), 1) + assert.Contains(t, allErrors, expectedError) +} diff --git a/internal/resolution/pm/nuget/testdata/empty_cmd_factory_mock.go b/internal/resolution/pm/nuget/testdata/empty_cmd_factory_mock.go new file mode 100644 index 00000000..e8276a6b --- /dev/null +++ b/internal/resolution/pm/nuget/testdata/empty_cmd_factory_mock.go @@ -0,0 +1,21 @@ +package testdata + +import ( + "os/exec" +) + +type EmptyCmdFactoryMock struct { + MakeErr error +} + +func NewEmptyCmdFactory() EmptyCmdFactoryMock { + return EmptyCmdFactoryMock{} +} + +func (f EmptyCmdFactoryMock) MakeInstallCmd(_ string, _ string) (*exec.Cmd, error) { + return nil, f.MakeErr +} + +func (f EmptyCmdFactoryMock) GetTempoCsproj() string { + return "" +}