Skip to content

Commit

Permalink
Fix artifactory unit test and linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesuen committed Jan 2, 2018
1 parent e7ba2b4 commit 940dd56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
32 changes: 19 additions & 13 deletions workflow/artifacts/artifactory/artifactory.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,47 @@
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 {
Username string
Password string
}


// Download artifact from an artifactory URL
func (a *ArtifactoryArtifactDriver) Load(artifact *wfv1.Artifact, path string) error {

lf, err := os.Create(path)
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
}
Expand All @@ -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
}
7 changes: 4 additions & 3 deletions workflow/artifacts/artifactory/artifactory_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down

0 comments on commit 940dd56

Please sign in to comment.