From 940dd56d98c75eb93da3b5de598882754cb74fc7 Mon Sep 17 00:00:00 2001 From: Jesse Suen Date: Tue, 2 Jan 2018 12:48:04 -0800 Subject: [PATCH] Fix artifactory unit test and linting issues --- workflow/artifacts/artifactory/artifactory.go | 32 +++++++++++-------- .../artifacts/artifactory/artifactory_test.go | 7 ++-- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/workflow/artifacts/artifactory/artifactory.go b/workflow/artifacts/artifactory/artifactory.go index 4f46a2468eac..1ab058499458 100644 --- a/workflow/artifacts/artifactory/artifactory.go +++ b/workflow/artifacts/artifactory/artifactory.go @@ -1,11 +1,12 @@ package artifactory import ( - wfv1 "github.com/argoproj/argo/api/workflow/v1alpha1" + "io" "net/http" "os" + + wfv1 "github.com/argoproj/argo/api/workflow/v1alpha1" "github.com/argoproj/argo/errors" - "io" ) type ArtifactoryArtifactDriver struct { @@ -13,7 +14,6 @@ type ArtifactoryArtifactDriver struct { Password string } - // Download artifact from an artifactory URL func (a *ArtifactoryArtifactDriver) Load(artifact *wfv1.Artifact, path string) error { @@ -21,23 +21,27 @@ func (a *ArtifactoryArtifactDriver) Load(artifact *wfv1.Artifact, path string) e if err != nil { return err } - defer lf.Close() + defer func() { + _ = lf.Close() + }() - req,err := http.NewRequest(http.MethodGet,artifact.Artifactory.URL,nil) + req, err := http.NewRequest(http.MethodGet, artifact.Artifactory.URL, nil) if err != nil { return err } - req.SetBasicAuth(a.Username,a.Password) + req.SetBasicAuth(a.Username, a.Password) res, err := (&http.Client{}).Do(req) if err != nil { return err } - defer res.Body.Close() + defer func() { + _ = res.Body.Close() + }() if res.StatusCode < 200 || res.StatusCode >= 300 { - return errors.InternalErrorf("loading file from artifactory failed with reason:%s",res.Status) + return errors.InternalErrorf("loading file from artifactory failed with reason:%s", res.Status) } - _,err = io.Copy(lf,res.Body) + _, err = io.Copy(lf, res.Body) return err } @@ -49,18 +53,20 @@ func (a *ArtifactoryArtifactDriver) Save(path string, artifact *wfv1.Artifact) e if err != nil { return err } - req, err := http.NewRequest(http.MethodPut,artifact.Artifactory.URL,f) + req, err := http.NewRequest(http.MethodPut, artifact.Artifactory.URL, f) if err != nil { return err } - req.SetBasicAuth(a.Username,a.Password) + req.SetBasicAuth(a.Username, a.Password) res, err := (&http.Client{}).Do(req) if err != nil { return err } - defer res.Body.Close() + defer func() { + _ = res.Body.Close() + }() if res.StatusCode < 200 || res.StatusCode >= 300 { - return errors.InternalErrorf("saving file %s to artifactory failed with reason:%s",path,res.Status) + return errors.InternalErrorf("saving file %s to artifactory failed with reason:%s", path, res.Status) } return nil } diff --git a/workflow/artifacts/artifactory/artifactory_test.go b/workflow/artifacts/artifactory/artifactory_test.go index 4d180a6a4b80..f46fbed6c10c 100644 --- a/workflow/artifacts/artifactory/artifactory_test.go +++ b/workflow/artifacts/artifactory/artifactory_test.go @@ -1,13 +1,14 @@ package artifactory_test import ( - art "../artifactory" - wfv1 "github.com/argoproj/argo/api/workflow/v1alpha1" - "github.com/stretchr/testify/assert" "io/ioutil" "os" "testing" "time" + + wfv1 "github.com/argoproj/argo/api/workflow/v1alpha1" + art "github.com/argoproj/argo/workflow/artifacts/artifactory" + "github.com/stretchr/testify/assert" ) const (