From ee6612beef71a7b9f1c7669076e5ce26868c14d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20W=C3=A5reus?= Date: Thu, 7 Sep 2023 13:04:49 +0200 Subject: [PATCH] Fix errors and cleanup dockerfile --- build/docker/alpine.Dockerfile | 20 +------------------ internal/file/default_exclusion.go | 1 + internal/resolution/pm/nuget/job.go | 1 + internal/resolution/pm/nuget/job_test.go | 19 ------------------ .../pm/nuget/testdata/cmd_factory_mock.go | 18 ++--------------- 5 files changed, 5 insertions(+), 54 deletions(-) diff --git a/build/docker/alpine.Dockerfile b/build/docker/alpine.Dockerfile index cbe69909..d25bcd3d 100644 --- a/build/docker/alpine.Dockerfile +++ b/build/docker/alpine.Dockerfile @@ -41,22 +41,4 @@ ENV GRADLE_HOME /usr/lib/gradle ENV PATH $GRADLE_HOME/gradle-$GRADLE_VERSION/bin:$PATH RUN wget https://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip && \ unzip gradle-$GRADLE_VERSION-bin.zip -d $GRADLE_HOME && \ - rm gradle-$GRADLE_VERSION-bin.zip - - -# ENV BIN_DIRECTORY /usr/bin -# ENV DOTNET_DIRECTORY /usr/bin/dotnet - -# #Install dotnet -# RUN apk add --no-cache --virtual build-dependencies curl \ -# && curl -SL --output dotnet.tar.gz https://download.visualstudio.microsoft.com/download/pr/f8834fef-d2ab-4cf6-abc3-d8d79cfcde11/0ee05ef4af5fe324ce2977021bf9f340/dotnet-sdk-3.1.426-linux-musl-x64.tar.gz \ -# && mkdir -p $DOTNET_DIRECTORY \ -# && tar zxf dotnet.tar.gz -C $DOTNET_DIRECTORY \ -# && chmod +x $DOTNET_DIRECTORY/dotnet \ -# && rm dotnet.tar.gz \ -# && apk del build-dependencies \ -# && rm -r $DOTNET_DIRECTORY/packs $DOTNET_DIRECTORY/sdk/3.1.426/TestHost $DOTNET_DIRECTORY/sdk/3.1.426/Extensions \ -# $DOTNET_DIRECTORY/sdk/3.1.426/FSharp $DOTNET_DIRECTORY/sdk/3.1.426/Roslyn - - - + rm gradle-$GRADLE_VERSION-bin.zip \ No newline at end of file diff --git a/internal/file/default_exclusion.go b/internal/file/default_exclusion.go index 1d3e2033..95e2b1fa 100644 --- a/internal/file/default_exclusion.go +++ b/internal/file/default_exclusion.go @@ -7,5 +7,6 @@ func DefaultExclusions() []string { filepath.Join("**", "node_modules", "**"), filepath.Join("**", "vendor", "**"), filepath.Join("**", ".git", "**"), + filepath.Join("**", "obj", "**"), // nuget } } diff --git a/internal/resolution/pm/nuget/job.go b/internal/resolution/pm/nuget/job.go index cd7e1a46..833c7392 100644 --- a/internal/resolution/pm/nuget/job.go +++ b/internal/resolution/pm/nuget/job.go @@ -44,6 +44,7 @@ func (j *Job) Run() { } else { j.Errors().Critical(errors.New(string(output))) } + return } } diff --git a/internal/resolution/pm/nuget/job_test.go b/internal/resolution/pm/nuget/job_test.go index e022deeb..2e4b90fc 100644 --- a/internal/resolution/pm/nuget/job_test.go +++ b/internal/resolution/pm/nuget/job_test.go @@ -62,22 +62,3 @@ func TestRunInstallCmdOutputErr(t *testing.T) { jobTestdata.AssertPathErr(t, j.Errors()) } - -func TestRunInstallCmdOutputAndErr(t *testing.T) { - // Setup mock to return a specific error and output - expectedError := errors.New("expected error") - expectedOutput := []byte("expected output") - - cmdFactoryMock := testdata.NewEchoCmdFactory() - cmdFactoryMock.CmdOutput = expectedOutput - cmdFactoryMock.CmdError = expectedError - - j := NewJob("file", true, cmdFactoryMock) - - go jobTestdata.WaitStatus(j) - j.Run() - - // Check that the error recorded in j.Errors() matches the error created from the output - assert.Len(t, j.Errors().GetAll(), 1) - assert.Contains(t, j.Errors().GetAll(), errors.New(string(expectedOutput))) -} diff --git a/internal/resolution/pm/nuget/testdata/cmd_factory_mock.go b/internal/resolution/pm/nuget/testdata/cmd_factory_mock.go index 2bec7f13..093ba6b2 100644 --- a/internal/resolution/pm/nuget/testdata/cmd_factory_mock.go +++ b/internal/resolution/pm/nuget/testdata/cmd_factory_mock.go @@ -7,8 +7,6 @@ import ( type CmdFactoryMock struct { InstallCmdName string MakeInstallErr error - CmdOutput []byte - CmdError error } func NewEchoCmdFactory() CmdFactoryMock { @@ -16,19 +14,7 @@ func NewEchoCmdFactory() CmdFactoryMock { InstallCmdName: "echo", } } -func (f CmdFactoryMock) MakeInstallCmd(command string, file string) (*exec.Cmd, error) { - if f.MakeInstallErr != nil { - return nil, f.MakeInstallErr - } - - cmd := exec.Command(f.InstallCmdName) - if f.CmdError != nil { - cmd = exec.Command("sh", "-c", f.InstallCmdName+" && exit 1") - } - if f.CmdOutput != nil { - cmd = exec.Command("sh", "-c", "echo -n \""+string(f.CmdOutput)+"\" && exit 1") - } - - return cmd, nil +func (f CmdFactoryMock) MakeInstallCmd(command string, file string) (*exec.Cmd, error) { + return exec.Command(f.InstallCmdName), f.MakeInstallErr }