Skip to content

Commit

Permalink
Merge pull request #39 from 030/gh35-index-out-of-range
Browse files Browse the repository at this point in the history
Gh35 index out of range
  • Loading branch information
030 authored May 14, 2019
2 parents 8f84938 + c83b2b3 commit 5cc039e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ addons:
script:
- diff -u <(echo -n) <(gofmt -d ./)
- export DELIVERABLE="n3dr-${TRAVIS_OS_NAME}"
- go test -short -cover -v -coverprofile=coverage.out -covermode=atomic ./...
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then go test -short -cover -v -coverprofile=coverage.out -covermode=atomic ./...; fi
- go build -o $DELIVERABLE
- $SHA512_CMD $DELIVERABLE > ${DELIVERABLE}.sha512.txt
- if [ "$TRAVIS_OS_NAME" == "linux" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then sonar-scanner -Dsonar.projectKey=030_n3dr -Dsonar.sources=. -Dsonar.host.url=https://sonarcloud.io -Dsonar.coverage.exclusions=**/*_test.go -Dsonar.go.coverage.reportPaths="coverage.out"; fi
Expand Down
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.2] - 2019-05-15
### Added
- TestDownloadArtifacts.

### Changed
- Restrict testing to linux as docker is omitted on Mac and Windows build in travis.

### Fixed
- Broken Windows build due to formatting solved by enforcing LF using gitattributes.

## [1.0.1] - 2019-05-14
### Fixed
- Publication of artifacts.
Expand All @@ -14,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Download all artifacts from a certain Nexus3 repository.

[Unreleased]: https://github.com/030/n3dr/compare/1.0.1...HEAD
[Unreleased]: https://github.com/030/n3dr/compare/1.0.2...HEAD
[1.0.2]: https://github.com/030/n3dr/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/030/n3dr/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/030/n3dr/compare/1.0.0
[1.0.0]: https://github.com/030/n3dr/releases/tag/1.0.0
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
10 changes: 9 additions & 1 deletion cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var n = Nexus3{
// See https://stackoverflow.com/a/34102842/2777965
func TestMain(m *testing.M) {
setup()
m.Run()
code := m.Run()
shutdown()
os.Exit(code)
Expand Down Expand Up @@ -149,3 +148,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 5cc039e

Please sign in to comment.