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
07adf0f9
Commit
07adf0f9
authored
Feb 03, 2016
by
Ville Aikas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability for the test github registry to handle Do methods. Fix the test to use this.
parent
bd99ae82
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
14 deletions
+35
-14
typeresolver_test.go
manager/manager/typeresolver_test.go
+13
-13
testhelper.go
registry/testhelper.go
+22
-1
No files found.
manager/manager/typeresolver_test.go
View file @
07adf0f9
...
...
@@ -18,7 +18,6 @@ package manager
import
(
"errors"
"log"
"net/http"
"reflect"
"strings"
...
...
@@ -51,16 +50,17 @@ type testGetter struct {
test
*
testing
.
T
}
var
count
=
0
func
(
tg
testGetter
)
Get
(
url
string
)
(
body
string
,
code
int
,
err
error
)
{
tg
.
count
=
tg
.
count
+
1
count
=
count
+
1
ret
:=
tg
.
responses
[
url
]
log
.
Printf
(
"GET RETURNING: '%s' '%d'"
,
ret
.
resp
,
tg
.
count
)
return
ret
.
resp
,
ret
.
code
,
ret
.
err
}
func
testDriver
(
c
resolverTestCase
,
t
*
testing
.
T
)
{
g
:=
&
testGetter
{
test
:
t
,
responses
:
c
.
responses
}
log
.
Printf
(
"getter: %#v"
,
g
)
count
=
0
r
:=
&
typeResolver
{
maxUrls
:
5
,
rp
:
c
.
registryProvider
,
...
...
@@ -75,7 +75,7 @@ func testDriver(c resolverTestCase, t *testing.T) {
result
,
err
:=
r
.
ResolveTypes
(
conf
,
c
.
imports
)
if
g
.
count
!=
c
.
urlcount
{
if
count
!=
c
.
urlcount
{
t
.
Errorf
(
"Expected %d url GETs but only %d found %#v"
,
c
.
urlcount
,
g
.
count
,
g
)
}
...
...
@@ -297,11 +297,11 @@ func TestShortGithubUrl(t *testing.T) {
Content
:
"my-content-2"
},
}
responses
:=
map
[
string
]
responseAndError
{
"https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v1/replicatedservice.py"
:
re
sponseAndError
{
nil
,
http
.
StatusOK
,
"my-content"
},
"https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v1/replicatedservice.py.schema"
:
re
sponseAndError
{
nil
,
http
.
StatusNotFound
,
""
},
"https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v2/replicatedservice.py"
:
re
sponseAndError
{
nil
,
http
.
StatusOK
,
"my-content-2"
},
"https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v2/replicatedservice.py.schema"
:
re
sponseAndError
{
nil
,
http
.
StatusNotFound
,
""
},
downloadResponses
:=
map
[
string
]
registry
.
DownloadResponse
{
"https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v1/replicatedservice.py"
:
re
gistry
.
DownloadResponse
{
nil
,
http
.
StatusOK
,
"my-content"
},
"https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v1/replicatedservice.py.schema"
:
re
gistry
.
DownloadResponse
{
nil
,
http
.
StatusNotFound
,
""
},
"https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v2/replicatedservice.py"
:
re
gistry
.
DownloadResponse
{
nil
,
http
.
StatusOK
,
"my-content-2"
},
"https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v2/replicatedservice.py.schema"
:
re
gistry
.
DownloadResponse
{
nil
,
http
.
StatusNotFound
,
""
},
}
githubUrlMaps
:=
map
[
registry
.
Type
]
registry
.
TestURLAndError
{
...
...
@@ -314,13 +314,13 @@ func TestShortGithubUrl(t *testing.T) {
registry
.
NewTypeOrDie
(
"common"
,
"replicatedservice"
,
"v2"
)
:
registry
.
TestURLAndError
{
"https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v2/replicatedservice.py"
,
nil
},
}
grp
:=
registry
.
NewTestGithubRegistryProvider
(
"github.com/kubernetes/application-dm-templates"
,
githubUrlMap
s
)
grp
:=
registry
.
NewTestGithubRegistryProvider
WithDownloads
(
"github.com/kubernetes/application-dm-templates"
,
githubUrlMaps
,
downloadResponse
s
)
gcsrp
:=
registry
.
NewTestGCSRegistryProvider
(
"gs://charts"
,
gcsUrlMaps
)
test
:=
resolverTestCase
{
config
:
templateShortGithubTemplate
,
importOut
:
finalImports
,
urlcount
:
4
,
responses
:
responses
,
urlcount
:
0
,
responses
:
map
[
string
]
responseAndError
{}
,
registryProvider
:
registry
.
NewRegistryProvider
(
nil
,
grp
,
gcsrp
,
registry
.
NewInmemCredentialProvider
()),
}
...
...
registry/testhelper.go
View file @
07adf0f9
...
...
@@ -19,6 +19,9 @@ package registry
// TODO(jackgr): Mock github repository service to test package and template registry implementations.
import
(
"bytes"
"io/ioutil"
"github.com/kubernetes/deployment-manager/common"
"github.com/kubernetes/deployment-manager/util"
...
...
@@ -34,14 +37,22 @@ type TestURLAndError struct {
Err
error
}
type
DownloadResponse
struct
{
Err
error
Code
int
Body
string
}
type
testGithubRegistryProvider
struct
{
shortURL
string
responses
map
[
Type
]
TestURLAndError
downloadResponses
map
[
string
]
DownloadResponse
}
type
testGithubRegistry
struct
{
githubRegistry
responses
map
[
Type
]
TestURLAndError
downloadResponses
map
[
string
]
DownloadResponse
}
func
NewTestGithubRegistryProvider
(
shortURL
string
,
responses
map
[
Type
]
TestURLAndError
)
GithubRegistryProvider
{
...
...
@@ -51,6 +62,14 @@ func NewTestGithubRegistryProvider(shortURL string, responses map[Type]TestURLAn
}
}
func
NewTestGithubRegistryProviderWithDownloads
(
shortURL
string
,
responses
map
[
Type
]
TestURLAndError
,
downloadResponses
map
[
string
]
DownloadResponse
)
GithubRegistryProvider
{
return
testGithubRegistryProvider
{
shortURL
:
util
.
TrimURLScheme
(
shortURL
),
responses
:
responses
,
downloadResponses
:
downloadResponses
,
}
}
func
(
tgrp
testGithubRegistryProvider
)
GetGithubRegistry
(
cr
common
.
Registry
)
(
GithubRegistry
,
error
)
{
trimmed
:=
util
.
TrimURLScheme
(
cr
.
URL
)
if
strings
.
HasPrefix
(
trimmed
,
tgrp
.
shortURL
)
{
...
...
@@ -62,6 +81,7 @@ func (tgrp testGithubRegistryProvider) GetGithubRegistry(cr common.Registry) (Gi
return
&
testGithubRegistry
{
githubRegistry
:
*
ghr
,
responses
:
tgrp
.
responses
,
downloadResponses
:
tgrp
.
downloadResponses
,
},
nil
}
...
...
@@ -83,7 +103,8 @@ func (tgr testGithubRegistry) GetDownloadURLs(t Type) ([]*url.URL, error) {
}
func
(
g
testGithubRegistry
)
Do
(
req
*
http
.
Request
)
(
resp
*
http
.
Response
,
err
error
)
{
return
nil
,
fmt
.
Errorf
(
"Not implemented yet"
)
response
:=
g
.
downloadResponses
[
req
.
URL
.
String
()]
return
&
http
.
Response
{
StatusCode
:
response
.
Code
,
Body
:
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
response
.
Body
))},
response
.
Err
}
type
testGCSRegistryProvider
struct
{
...
...
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