func TestShortGithubUrl(t *testing.T) { finalImports := []*common.ImportFile{ &common.ImportFile{ Name: "github.com/kubernetes/application-dm-templates/common/replicatedservice:v1", Path: "https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v1/replicatedservice.py", Content: "my-content"}, &common.ImportFile{ Name: "github.com/kubernetes/application-dm-templates/common/replicatedservice:v2", Path: "https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v2/replicatedservice.py", Content: "my-content-2"}, } responses := map[string]responseAndError{ "https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v1/replicatedservice.py": responseAndError{nil, http.StatusOK, "my-content"}, "https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v1/replicatedservice.py.schema": responseAndError{nil, http.StatusNotFound, ""}, "https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v2/replicatedservice.py": responseAndError{nil, http.StatusOK, "my-content-2"}, "https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v2/replicatedservice.py.schema": responseAndError{nil, http.StatusNotFound, ""}, } githubUrlMaps := map[registry.Type]registry.TestURLAndError{ registry.NewTypeOrDie("common", "replicatedservice", "v1"): registry.TestURLAndError{"https://raw.githubusercontent.com/kubernetes/application-dm-templates/master/common/replicatedservice/v1/replicatedservice.py", nil}, 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", githubUrlMaps) test := resolverTestCase{ config: templateShortGithubTemplate, importOut: finalImports, urlcount: 4, responses: responses, registryProvider: registry.NewRegistryProvider(nil, grp, registry.NewInmemCredentialProvider()), } testDriver(test, t) }
func getRegistryProvider() registry.RegistryProvider { if registryProvider == nil { rs := registry.NewInmemRegistryService() _, err := rs.GetByURL(*template_registry) if err != nil { r := newRegistry(*template_registry) if err := rs.Create(r); err != nil { panic(fmt.Errorf("cannot configure registry at %s: %s", r.URL, err)) } } cp := registry.NewInmemCredentialProvider() if *apitoken == "" { *apitoken = os.Getenv("DM_GITHUB_API_TOKEN") } if *apitoken != "" { credential := common.RegistryCredential{ APIToken: common.APITokenCredential(*apitoken), } if err := cp.SetCredential("default", &credential); err != nil { panic(fmt.Errorf("cannot set credential at %s: %s", "default", err)) } } registryProvider = registry.NewRegistryProvider(rs, nil, cp) } return registryProvider }
d := instance.Deployment repository.TypeInstances[d] = append(repository.TypeInstances[d], t) } } return nil } func (repository *repositoryStub) Close() {} var testExpander = &expanderStub{} var testRepository = newRepositoryStub() var testDeployer = newDeployerStub() var testRegistryService = registry.NewInmemRegistryService() var testCredentialProvider = registry.NewInmemCredentialProvider() var testProvider = registry.NewRegistryProvider(nil, registry.NewTestGithubRegistryProvider("", nil), registry.NewTestGCSRegistryProvider("", nil), testCredentialProvider) var testManager = NewManager(testExpander, testDeployer, testRepository, testProvider, testRegistryService, testCredentialProvider) func TestListDeployments(t *testing.T) { testRepository.reset() d, err := testManager.ListDeployments() if err != nil { t.Fatalf(err.Error()) } if !reflect.DeepEqual(d, deploymentList) { t.Fatalf("invalid deployment list") } } func TestListDeploymentsFail(t *testing.T) {