-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Closes #11: Add update Maven Group repository feature Signed-off-by: Ricardo Zanini <[email protected]> * Increasing code coverage on MavenGroupService Signed-off-by: Ricardo Zanini <[email protected]> * Reconfiguring codecov to use actions and lower threshold :D Signed-off-by: Ricardo Zanini <[email protected]> * Fixing codecov flag Signed-off-by: Ricardo Zanini <[email protected]> * Testing codecov threshold Signed-off-by: Ricardo Zanini <[email protected]> * Fixing renaming and error coverage branch
- Loading branch information
1 parent
9ef6a23
commit e84c204
Showing
11 changed files
with
358 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,6 @@ coverage: | |
project: | ||
aicura: | ||
target: auto | ||
threshold: 3% | ||
threshold: 5% | ||
flags: | ||
- aicura |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2020 Aicura Nexus Client and/or its authors | ||
// | ||
// This file is part of Aicura Nexus Client. | ||
// | ||
// Aicura Nexus Client is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Aicura Nexus Client is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with Aicura Nexus Client. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package nexus | ||
|
||
import "fmt" | ||
|
||
// MavenGroupRepositoryService service to handle all Maven Proxy Repositories operations | ||
type MavenGroupRepositoryService service | ||
|
||
// Update updates a given Maven Group repository | ||
func (m *MavenGroupRepositoryService) Update(repo MavenGroupRepository) error { | ||
req, err := m.client.put(m.client.appendVersion(fmt.Sprintf("/repositories/maven/group/%s", repo.Name)), "", repo) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = m.client.do(req, nil) | ||
return err | ||
} | ||
|
||
// List lists all maven repositories from the Nexus Server | ||
func (m *MavenGroupRepositoryService) List() ([]MavenGroupRepository, error) { | ||
repositories := []MavenGroupRepository{} | ||
err := m.client.mavenRepositoryService.list(RepositoryTypeGroup, &repositories) | ||
return repositories, err | ||
} | ||
|
||
// GetRepoByName gets the repository by name or nil if not found | ||
func (m *MavenGroupRepositoryService) GetRepoByName(name string) (*MavenGroupRepository, error) { | ||
repos, err := m.List() | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, repo := range repos { | ||
if repo.Name == name { | ||
return &repo, nil | ||
} | ||
} | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2020 Aicura Nexus Client and/or its authors | ||
// | ||
// This file is part of Aicura Nexus Client. | ||
// | ||
// Aicura Nexus Client is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Aicura Nexus Client is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with Aicura Nexus Client. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package nexus | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMavenGroupRepositoryService_Update(t *testing.T) { | ||
s := newServerWrapper(t).WithResponse(allRepositoriesMockData).Build() | ||
defer s.teardown() | ||
|
||
repos, err := s.Client().MavenGroupRepositoryService.List() | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, repos) | ||
|
||
if len(repos) > 0 { //sanity check to not panic | ||
s = newServerWrapper(t).Build() | ||
apacheMavenRepoMockData.Name = apacheMavenRepoMockData.Name + "3" | ||
err := s.Client().MavenProxyRepositoryService.Add(apacheMavenRepoMockData) | ||
assert.NoError(t, err) | ||
|
||
repos[0].Group.MemberNames = append(repos[0].Group.MemberNames, apacheMavenRepoMockData.Name) | ||
err = s.Client().MavenGroupRepositoryService.Update(repos[0]) | ||
assert.NoError(t, err) | ||
} | ||
} | ||
|
||
func TestMavenGroupRepositoryService_List(t *testing.T) { | ||
s := newServerWrapper(t).WithResponse(allRepositoriesMockData).Build() | ||
defer s.teardown() | ||
repos, err := s.Client().MavenGroupRepositoryService.List() | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, repos) | ||
for _, repo := range repos { | ||
if repo.Name == "maven-public" { | ||
assert.Equal(t, RepositoryTypeGroup, *repo.Type) | ||
} | ||
} | ||
} | ||
|
||
func TestMavenGroupRepositoryService_GetByName(t *testing.T) { | ||
s := newServerWrapper(t).WithResponse(allRepositoriesMockData).Build() | ||
defer s.teardown() | ||
repo, err := s.Client().MavenGroupRepositoryService.GetRepoByName("maven-public") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "maven-public", repo.Name) | ||
assert.Equal(t, RepositoryTypeGroup, *repo.Type) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2020 Aicura Nexus Client and/or its authors | ||
// | ||
// This file is part of Aicura Nexus Client. | ||
// | ||
// Aicura Nexus Client is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Aicura Nexus Client is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with Aicura Nexus Client. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package nexus | ||
|
||
import ( | ||
"context" | ||
|
||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
// MavenProxyRepositoryService service to handle all Maven Proxy Repositories operations | ||
type MavenProxyRepositoryService service | ||
|
||
// Add adds new Proxy Maven repositories to the Nexus Server | ||
func (m *MavenProxyRepositoryService) Add(repositories ...MavenProxyRepository) error { | ||
if len(repositories) == 0 { | ||
m.logger.Warnf("Called AddRepository with no repositories to add") | ||
return nil | ||
} | ||
errs, _ := errgroup.WithContext(context.Background()) | ||
for _, repo := range repositories { | ||
errs.Go(func() error { | ||
req, err := m.client.post(m.client.appendVersion(repositoriesMavenProxyPath), "", repo) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = m.client.do(req, nil) | ||
return err | ||
}) | ||
} | ||
return errs.Wait() | ||
} | ||
|
||
// List lists all maven repositories from the Nexus Server | ||
func (m *MavenProxyRepositoryService) List() ([]MavenProxyRepository, error) { | ||
repositories := []MavenProxyRepository{} | ||
err := m.client.mavenRepositoryService.list(RepositoryTypeProxy, &repositories) | ||
return repositories, err | ||
} | ||
|
||
// GetRepoByName gets the repository by name or nil if not found | ||
func (m *MavenProxyRepositoryService) GetRepoByName(name string) (*MavenProxyRepository, error) { | ||
repos, err := m.List() | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, repo := range repos { | ||
if repo.Name == name { | ||
return &repo, nil | ||
} | ||
} | ||
return nil, nil | ||
} |
Oops, something went wrong.