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
ea61ace8
Commit
ea61ace8
authored
Mar 24, 2017
by
Taylor Thomas
Committed by
GitHub
Mar 24, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2156 from sushilkm/version-tests
Added unit tests
parents
a34f2328
cfd041ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
146 additions
and
0 deletions
+146
-0
repo_test.go
pkg/repo/repo_test.go
+99
-0
version_test.go
pkg/version/version_test.go
+47
-0
No files found.
pkg/repo/repo_test.go
View file @
ea61ace8
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
repo
import
"testing"
import
"io/ioutil"
import
"os"
const
testRepositoriesFile
=
"testdata/repositories.yaml"
...
...
@@ -116,3 +118,100 @@ func TestNewPreV1RepositoriesFile(t *testing.T) {
t
.
Errorf
(
"expected the best charts ever. Got %#v"
,
r
.
Repositories
)
}
}
func
TestRemoveRepository
(
t
*
testing
.
T
)
{
sampleRepository
:=
NewRepoFile
()
sampleRepository
.
Add
(
&
Entry
{
Name
:
"stable"
,
URL
:
"https://example.com/stable/charts"
,
Cache
:
"stable-index.yaml"
,
},
&
Entry
{
Name
:
"incubator"
,
URL
:
"https://example.com/incubator"
,
Cache
:
"incubator-index.yaml"
,
},
)
removeRepository
:=
"stable"
found
:=
sampleRepository
.
Remove
(
removeRepository
)
if
!
found
{
t
.
Errorf
(
"expected repository %s not found"
,
removeRepository
)
}
found
=
sampleRepository
.
Has
(
removeRepository
)
if
found
{
t
.
Errorf
(
"repository %s not deleted"
,
removeRepository
)
}
}
func
TestUpdateRepository
(
t
*
testing
.
T
)
{
sampleRepository
:=
NewRepoFile
()
sampleRepository
.
Add
(
&
Entry
{
Name
:
"stable"
,
URL
:
"https://example.com/stable/charts"
,
Cache
:
"stable-index.yaml"
,
},
&
Entry
{
Name
:
"incubator"
,
URL
:
"https://example.com/incubator"
,
Cache
:
"incubator-index.yaml"
,
},
)
newRepoName
:=
"sample"
sampleRepository
.
Update
(
&
Entry
{
Name
:
newRepoName
,
URL
:
"https://example.com/sample"
,
Cache
:
"sample-index.yaml"
,
})
if
!
sampleRepository
.
Has
(
newRepoName
)
{
t
.
Errorf
(
"expected repository %s not found"
,
newRepoName
)
}
repoCount
:=
len
(
sampleRepository
.
Repositories
)
sampleRepository
.
Update
(
&
Entry
{
Name
:
newRepoName
,
URL
:
"https://example.com/sample"
,
Cache
:
"sample-index.yaml"
,
})
if
repoCount
!=
len
(
sampleRepository
.
Repositories
)
{
t
.
Errorf
(
"invalid number of repositories found %d, expected number of repositories %d"
,
len
(
sampleRepository
.
Repositories
),
repoCount
)
}
}
func
TestWriteFile
(
t
*
testing
.
T
)
{
sampleRepository
:=
NewRepoFile
()
sampleRepository
.
Add
(
&
Entry
{
Name
:
"stable"
,
URL
:
"https://example.com/stable/charts"
,
Cache
:
"stable-index.yaml"
,
},
&
Entry
{
Name
:
"incubator"
,
URL
:
"https://example.com/incubator"
,
Cache
:
"incubator-index.yaml"
,
},
)
repoFile
,
err
:=
ioutil
.
TempFile
(
""
,
"helm-repo"
)
if
err
!=
nil
{
t
.
Errorf
(
"failed to create test-file (%v)"
,
err
)
}
defer
os
.
Remove
(
repoFile
.
Name
())
if
err
:=
sampleRepository
.
WriteFile
(
repoFile
.
Name
(),
744
);
err
!=
nil
{
t
.
Errorf
(
"failed to write file (%v)"
,
err
)
}
repos
,
err
:=
LoadRepositoriesFile
(
repoFile
.
Name
())
if
err
!=
nil
{
t
.
Errorf
(
"failed to load file (%v)"
,
err
)
}
for
_
,
repo
:=
range
sampleRepository
.
Repositories
{
if
!
repos
.
Has
(
repo
.
Name
)
{
t
.
Errorf
(
"expected repository %s not found"
,
repo
.
Name
)
}
}
}
pkg/version/version_test.go
0 → 100644
View file @
ea61ace8
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package version represents the current version of the project.
package
version
// import "k8s.io/helm/pkg/version"
import
"testing"
import
"k8s.io/helm/pkg/proto/hapi/version"
func
TestGetVersionProto
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
version
string
buildMetadata
string
gitCommit
string
gitTreeState
string
expected
version
.
Version
}{
{
""
,
""
,
""
,
""
,
version
.
Version
{
SemVer
:
""
,
GitCommit
:
""
,
GitTreeState
:
""
}},
{
"v1.0.0"
,
""
,
""
,
""
,
version
.
Version
{
SemVer
:
"v1.0.0"
,
GitCommit
:
""
,
GitTreeState
:
""
}},
{
"v1.0.0"
,
"79d5c5f7"
,
""
,
""
,
version
.
Version
{
SemVer
:
"v1.0.0+79d5c5f7"
,
GitCommit
:
""
,
GitTreeState
:
""
}},
{
"v1.0.0"
,
"79d5c5f7"
,
"0d399baec2acda578a217d1aec8d7d707c71e44d"
,
""
,
version
.
Version
{
SemVer
:
"v1.0.0+79d5c5f7"
,
GitCommit
:
"0d399baec2acda578a217d1aec8d7d707c71e44d"
,
GitTreeState
:
""
}},
{
"v1.0.0"
,
"79d5c5f7"
,
"0d399baec2acda578a217d1aec8d7d707c71e44d"
,
"clean"
,
version
.
Version
{
SemVer
:
"v1.0.0+79d5c5f7"
,
GitCommit
:
"0d399baec2acda578a217d1aec8d7d707c71e44d"
,
GitTreeState
:
"clean"
}},
}
for
_
,
tt
:=
range
tests
{
Version
=
tt
.
version
BuildMetadata
=
tt
.
buildMetadata
GitCommit
=
tt
.
gitCommit
GitTreeState
=
tt
.
gitTreeState
if
versionProto
:=
GetVersionProto
();
*
versionProto
!=
tt
.
expected
{
t
.
Errorf
(
"expected Semver(%s), GitCommit(%s) and GitTreeState(%s) to be %v"
,
tt
.
expected
,
tt
.
gitCommit
,
tt
.
gitTreeState
,
*
versionProto
)
}
}
}
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