Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
fccd1ba5
Commit
fccd1ba5
authored
Mar 21, 2016
by
Jack Greenfield
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #422 from jackgr/repo-service
Add locking and duplicate detection
parents
64f9fb66
7e96c27e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
1 deletion
+36
-1
inmem_repo_service.go
pkg/repo/inmem_repo_service.go
+24
-1
inmem_repo_service_test.go
pkg/repo/inmem_repo_service_test.go
+12
-0
No files found.
pkg/repo/inmem_repo_service.go
View file @
fccd1ba5
...
...
@@ -19,9 +19,11 @@ package repo
import
(
"fmt"
"strings"
"sync"
)
type
inmemRepoService
struct
{
sync
.
RWMutex
repositories
map
[
string
]
Repo
}
...
...
@@ -41,6 +43,9 @@ func NewInmemRepoService() Service {
// List returns the list of all known chart repositories
func
(
rs
*
inmemRepoService
)
List
()
([]
Repo
,
error
)
{
rs
.
RLock
()
defer
rs
.
RUnlock
()
ret
:=
[]
Repo
{}
for
_
,
r
:=
range
rs
.
repositories
{
ret
=
append
(
ret
,
r
)
...
...
@@ -51,12 +56,24 @@ func (rs *inmemRepoService) List() ([]Repo, error) {
// Create adds a known repository to the list
func
(
rs
*
inmemRepoService
)
Create
(
repository
Repo
)
error
{
rs
.
repositories
[
repository
.
GetName
()]
=
repository
rs
.
Lock
()
defer
rs
.
Unlock
()
name
:=
repository
.
GetName
()
_
,
ok
:=
rs
.
repositories
[
name
]
if
ok
{
return
fmt
.
Errorf
(
"Repository named %s already exists"
,
name
)
}
rs
.
repositories
[
name
]
=
repository
return
nil
}
// Get returns the repository with the given name
func
(
rs
*
inmemRepoService
)
Get
(
name
string
)
(
Repo
,
error
)
{
rs
.
RLock
()
defer
rs
.
RUnlock
()
r
,
ok
:=
rs
.
repositories
[
name
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"Failed to find repository named %s"
,
name
)
...
...
@@ -67,6 +84,9 @@ func (rs *inmemRepoService) Get(name string) (Repo, error) {
// GetByURL returns the repository that backs the given URL
func
(
rs
*
inmemRepoService
)
GetByURL
(
URL
string
)
(
Repo
,
error
)
{
rs
.
RLock
()
defer
rs
.
RUnlock
()
var
found
Repo
for
_
,
r
:=
range
rs
.
repositories
{
rURL
:=
r
.
GetURL
()
...
...
@@ -86,6 +106,9 @@ func (rs *inmemRepoService) GetByURL(URL string) (Repo, error) {
// Delete removes a known repository from the list
func
(
rs
*
inmemRepoService
)
Delete
(
name
string
)
error
{
rs
.
Lock
()
defer
rs
.
Unlock
()
_
,
ok
:=
rs
.
repositories
[
name
]
if
!
ok
{
return
fmt
.
Errorf
(
"Failed to find repository named %s"
,
name
)
...
...
pkg/repo/inmem_repo_service_test.go
View file @
fccd1ba5
...
...
@@ -64,6 +64,18 @@ func TestService(t *testing.T) {
}
}
func
TestCreateRepoWithDuplicateName
(
t
*
testing
.
T
)
{
rs
:=
NewInmemRepoService
()
r
,
err
:=
newRepo
(
GCSPublicRepoName
,
GCSPublicRepoURL
,
""
,
GCSRepoFormat
,
GCSRepoType
)
if
err
!=
nil
{
t
.
Fatalf
(
"cannot create test repo: %s"
,
err
)
}
if
err
:=
rs
.
Create
(
r
);
err
==
nil
{
t
.
Fatalf
(
"created repo with duplicate name: %s"
,
GCSPublicRepoName
)
}
}
func
TestGetRepoWithInvalidName
(
t
*
testing
.
T
)
{
invalidName
:=
"InvalidRepoName"
rs
:=
NewInmemRepoService
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment