Skip to content

Commit

Permalink
Fix failing nuget job (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
4ernovm authored Jan 9, 2024
1 parent ab09596 commit 5f01b57
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/resolution/pm/nuget/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 19 additions & 0 deletions internal/resolution/pm/nuget/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
21 changes: 21 additions & 0 deletions internal/resolution/pm/nuget/testdata/empty_cmd_factory_mock.go
Original file line number Diff line number Diff line change
@@ -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 ""
}

0 comments on commit 5f01b57

Please sign in to comment.