Skip to content
Snippets Groups Projects
Unverified Commit 652d7c4c authored by bryanl's avatar bryanl
Browse files

removing need for github access for registry tests


Signed-off-by: default avatarbryanl <bryanliles@gmail.com>
parent 6f63da73
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,7 @@ func RunInit(fs afero.Fs, name, rootPath, k8sSpecFlag, serverURI, namespace stri
}
type appInitFn func(fs afero.Fs, name, rootPath, k8sSpecFlag, serverURI, namespace string, registries []registry.Registry) error
type initIncubatorFn func() (registry.Registry, error)
// Init creates a component namespace
type Init struct {
......@@ -48,19 +49,21 @@ type Init struct {
serverURI string
namespace string
appInitFn appInitFn
appInitFn appInitFn
initIncubatorFn initIncubatorFn
}
// NewInit creates an instance of Init.
func NewInit(fs afero.Fs, name, rootPath, k8sSpecFlag, serverURI, namespace string) (*Init, error) {
i := &Init{
fs: fs,
name: name,
rootPath: rootPath,
k8sSpecFlag: k8sSpecFlag,
serverURI: serverURI,
namespace: namespace,
appInitFn: appinit.Init,
fs: fs,
name: name,
rootPath: rootPath,
k8sSpecFlag: k8sSpecFlag,
serverURI: serverURI,
namespace: namespace,
appInitFn: appinit.Init,
initIncubatorFn: initIncubator,
}
return i, nil
......@@ -68,11 +71,7 @@ func NewInit(fs afero.Fs, name, rootPath, k8sSpecFlag, serverURI, namespace stri
// Run runs that ns create action.
func (i *Init) Run() error {
gh, err := registry.NewGitHub(&app.RegistryRefSpec{
Name: "incubator",
Protocol: registry.ProtocolGitHub,
URI: defaultIncubatorURI,
})
gh, err := i.initIncubatorFn()
if err != nil {
return err
}
......@@ -88,5 +87,12 @@ func (i *Init) Run() error {
i.namespace,
registries,
)
}
func initIncubator() (registry.Registry, error) {
return registry.NewGitHub(&app.RegistryRefSpec{
Name: "incubator",
Protocol: registry.ProtocolGitHub,
URI: defaultIncubatorURI,
})
}
......@@ -20,6 +20,7 @@ import (
amocks "github.com/ksonnet/ksonnet/metadata/app/mocks"
"github.com/ksonnet/ksonnet/pkg/registry"
rmocks "github.com/ksonnet/ksonnet/pkg/registry/mocks"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
......@@ -55,6 +56,14 @@ func TestInit(t *testing.T) {
return nil
}
a.initIncubatorFn = func() (registry.Registry, error) {
r := &rmocks.Registry{}
r.On("Protocol").Return("github")
r.On("URI").Return("github.com/ksonnet/parts/tree/master/incubator")
r.On("Name").Return("incubator")
return r, nil
}
err = a.Run()
require.NoError(t, err)
})
......
......@@ -60,18 +60,30 @@ func Test_Package(t *testing.T) {
}
func Test_List(t *testing.T) {
specs := app.RegistryRefSpecs{
"incubator": &app.RegistryRefSpec{
Protocol: ProtocolGitHub,
URI: "github.com/ksonnet/parts/tree/master/incubator",
},
}
withApp(t, func(a *mocks.App, fs afero.Fs) {
c := &ghmocks.GitHub{}
c.On("CommitSHA1", mock.Anything, github.Repo{Org: "ksonnet", Repo: "parts"}, mock.AnythingOfType("string")).
Return("12345", nil)
appMock := &mocks.App{}
appMock.On("Registries").Return(specs, nil)
ghcOpt := GitHubClient(c)
githubFactory = func(spec *app.RegistryRefSpec) (*GitHub, error) {
return NewGitHub(spec, ghcOpt)
}
registries, err := List(appMock)
require.NoError(t, err)
specs := app.RegistryRefSpecs{
"incubator": &app.RegistryRefSpec{
Protocol: ProtocolGitHub,
URI: "github.com/ksonnet/parts/tree/master/incubator",
},
}
require.Len(t, registries, 1)
appMock := &mocks.App{}
appMock.On("Registries").Return(specs, nil)
registries, err := List(appMock)
require.NoError(t, err)
require.Len(t, registries, 1)
})
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment