Skip to content

Commit

Permalink
[GH-35] testDownloadArtifact
Browse files Browse the repository at this point in the history
  • Loading branch information
030 committed May 14, 2019
1 parent bb622ed commit b636ecc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,23 @@ func createArtifact(d string, f string, content string) error {
}

func (n Nexus3) artifactName(url string) (string, string, error) {
log.Info("Validate whether: '" + url + "' is an URL")
if !govalidator.IsURL(url) {
return "", "", errors.New(url + " is not an URL")
}

re := regexp.MustCompile("^.*/" + n.Repository + "/(.*)/(.+)$")
match := re.FindStringSubmatch(url)
if match == nil {
return "", "", errors.New("URL: '" + url + "' does not seem to contain an artifactName")
}

d := match[1]
log.Info("ArtifactName directory: " + d)

f := match[2]
log.Info(d)
log.Info(f)
log.Info("ArtifactName file: " + f)

return d, f, nil
}

Expand Down
9 changes: 9 additions & 0 deletions cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,12 @@ func TestCreateArtifact(t *testing.T) {
t.Errorf(errMsgTxt, expectedErrorFile, actualErrorFile)
}
}

func TestDownloadArtifact(t *testing.T) {
actualError := n.downloadArtifact("http://releasesoftwaremoreoften.com")
expectedError := "URL: 'http://releasesoftwaremoreoften.com' does not seem to contain an artifactName"

if actualError.Error() != expectedError {
t.Errorf("Error incorrect. Expected: %v. Actual: %v", expectedError, actualError)
}
}

0 comments on commit b636ecc

Please sign in to comment.