From b636ecc233699e059cb51be6984610edf75baa0c Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 15 May 2019 00:48:12 +0200 Subject: [PATCH] [GH-35] testDownloadArtifact --- cli/cli.go | 11 +++++++++-- cli/cli_test.go | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 485d9873..d0639743 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -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 } diff --git a/cli/cli_test.go b/cli/cli_test.go index bfaddf47..cba99ca9 100644 --- a/cli/cli_test.go +++ b/cli/cli_test.go @@ -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) + } +}