Commit 43a6876a authored by jackgr's avatar jackgr

Refactor manager/manager

parent e1afffbc
This diff is collapsed.
...@@ -17,13 +17,13 @@ limitations under the License. ...@@ -17,13 +17,13 @@ limitations under the License.
package manager package manager
import ( import (
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/repo"
"errors" "errors"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/registry"
) )
var template = common.Template{Name: "test", Content: "test"} var template = common.Template{Name: "test", Content: "test"}
...@@ -134,9 +134,9 @@ type repositoryStub struct { ...@@ -134,9 +134,9 @@ type repositoryStub struct {
ManifestSet map[string]*common.Manifest ManifestSet map[string]*common.Manifest
Deleted []string Deleted []string
GetValid []string GetValid []string
TypeInstances map[string][]string ChartInstances map[string][]string
TypeInstancesCleared bool ChartInstancesCleared bool
GetTypeInstancesCalled bool GetChartInstancesCalled bool
ListTypesCalled bool ListTypesCalled bool
DeploymentStates []*common.DeploymentState DeploymentStates []*common.DeploymentState
} }
...@@ -148,9 +148,9 @@ func (repository *repositoryStub) reset() { ...@@ -148,9 +148,9 @@ func (repository *repositoryStub) reset() {
repository.ManifestSet = make(map[string]*common.Manifest) repository.ManifestSet = make(map[string]*common.Manifest)
repository.Deleted = make([]string, 0) repository.Deleted = make([]string, 0)
repository.GetValid = make([]string, 0) repository.GetValid = make([]string, 0)
repository.TypeInstances = make(map[string][]string) repository.ChartInstances = make(map[string][]string)
repository.TypeInstancesCleared = false repository.ChartInstancesCleared = false
repository.GetTypeInstancesCalled = false repository.GetChartInstancesCalled = false
repository.ListTypesCalled = false repository.ListTypesCalled = false
repository.DeploymentStates = []*common.DeploymentState{} repository.DeploymentStates = []*common.DeploymentState{}
} }
...@@ -233,26 +233,26 @@ func (repository *repositoryStub) GetLatestManifest(d string) (*common.Manifest, ...@@ -233,26 +233,26 @@ func (repository *repositoryStub) GetLatestManifest(d string) (*common.Manifest,
} }
// Types. // Types.
func (repository *repositoryStub) ListTypes() ([]string, error) { func (repository *repositoryStub) ListCharts() ([]string, error) {
repository.ListTypesCalled = true repository.ListTypesCalled = true
return []string{}, nil return []string{}, nil
} }
func (repository *repositoryStub) GetTypeInstances(t string) ([]*common.TypeInstance, error) { func (repository *repositoryStub) GetChartInstances(t string) ([]*common.ChartInstance, error) {
repository.GetTypeInstancesCalled = true repository.GetChartInstancesCalled = true
return []*common.TypeInstance{}, nil return []*common.ChartInstance{}, nil
} }
func (repository *repositoryStub) ClearTypeInstancesForDeployment(d string) error { func (repository *repositoryStub) ClearChartInstancesForDeployment(d string) error {
repository.TypeInstancesCleared = true repository.ChartInstancesCleared = true
return nil return nil
} }
func (repository *repositoryStub) AddTypeInstances(is map[string][]*common.TypeInstance) error { func (repository *repositoryStub) AddChartInstances(is map[string][]*common.ChartInstance) error {
for t, instances := range is { for t, instances := range is {
for _, instance := range instances { for _, instance := range instances {
d := instance.Deployment d := instance.Deployment
repository.TypeInstances[d] = append(repository.TypeInstances[d], t) repository.ChartInstances[d] = append(repository.ChartInstances[d], t)
} }
} }
...@@ -264,10 +264,10 @@ func (repository *repositoryStub) Close() {} ...@@ -264,10 +264,10 @@ func (repository *repositoryStub) Close() {}
var testExpander = &expanderStub{} var testExpander = &expanderStub{}
var testRepository = newRepositoryStub() var testRepository = newRepositoryStub()
var testDeployer = newDeployerStub() var testDeployer = newDeployerStub()
var testRegistryService = registry.NewInmemRegistryService() var testRepoService = repo.NewInmemRepoService()
var testCredentialProvider = registry.NewInmemCredentialProvider() var testCredentialProvider = repo.NewInmemCredentialProvider()
var testProvider = registry.NewRegistryProvider(nil, registry.NewTestGithubRegistryProvider("", nil), registry.NewTestGCSRegistryProvider("", nil), testCredentialProvider) var testProvider = repo.NewRepoProvider(nil, repo.NewGCSRepoProvider(testCredentialProvider), testCredentialProvider)
var testManager = NewManager(testExpander, testDeployer, testRepository, testProvider, testRegistryService, testCredentialProvider) var testManager = NewManager(testExpander, testDeployer, testRepository, testProvider, testRepoService, testCredentialProvider)
func TestListDeployments(t *testing.T) { func TestListDeployments(t *testing.T) {
testRepository.reset() testRepository.reset()
...@@ -363,12 +363,12 @@ func TestCreateDeployment(t *testing.T) { ...@@ -363,12 +363,12 @@ func TestCreateDeployment(t *testing.T) {
t.Fatal("CreateDeployment success did not mark deployment as deployed") t.Fatal("CreateDeployment success did not mark deployment as deployed")
} }
if !testRepository.TypeInstancesCleared { if !testRepository.ChartInstancesCleared {
t.Fatal("Repository did not clear type instances during creation") t.Fatal("Repository did not clear type instances during creation")
} }
if !reflect.DeepEqual(testRepository.TypeInstances, typeInstMap) { if !reflect.DeepEqual(testRepository.ChartInstances, typeInstMap) {
t.Fatalf("Unexpected type instances after CreateDeployment: %s", testRepository.TypeInstances) t.Fatalf("Unexpected type instances after CreateDeployment: %s", testRepository.ChartInstances)
} }
} }
...@@ -397,7 +397,7 @@ func TestCreateDeploymentCreationFailure(t *testing.T) { ...@@ -397,7 +397,7 @@ func TestCreateDeploymentCreationFailure(t *testing.T) {
"Received: %v, %s. Expected: %s, %s.", d, err, "nil", errTest) "Received: %v, %s. Expected: %s, %s.", d, err, "nil", errTest)
} }
if testRepository.TypeInstancesCleared { if testRepository.ChartInstancesCleared {
t.Fatal("Unexpected change to type instances during CreateDeployment failure.") t.Fatal("Unexpected change to type instances during CreateDeployment failure.")
} }
} }
...@@ -437,7 +437,7 @@ func TestCreateDeploymentCreationResourceFailure(t *testing.T) { ...@@ -437,7 +437,7 @@ func TestCreateDeploymentCreationResourceFailure(t *testing.T) {
"Received: %v, %v. Expected: %v, %v.", d, err, &deployment, "nil") "Received: %v, %v. Expected: %v, %v.", d, err, &deployment, "nil")
} }
if !testRepository.TypeInstancesCleared { if !testRepository.ChartInstancesCleared {
t.Fatal("Repository did not clear type instances during creation") t.Fatal("Repository did not clear type instances during creation")
} }
} }
...@@ -486,7 +486,7 @@ func TestDeleteDeploymentForget(t *testing.T) { ...@@ -486,7 +486,7 @@ func TestDeleteDeploymentForget(t *testing.T) {
} }
} }
if !testRepository.TypeInstancesCleared { if !testRepository.ChartInstancesCleared {
t.Fatal("Expected type instances to be cleared during DeleteDeployment.") t.Fatal("Expected type instances to be cleared during DeleteDeployment.")
} }
} }
...@@ -521,29 +521,29 @@ func TestExpand(t *testing.T) { ...@@ -521,29 +521,29 @@ func TestExpand(t *testing.T) {
func TestListTypes(t *testing.T) { func TestListTypes(t *testing.T) {
testRepository.reset() testRepository.reset()
testManager.ListTypes() testManager.ListCharts()
if !testRepository.ListTypesCalled { if !testRepository.ListTypesCalled {
t.Fatal("expected repository ListTypes() call.") t.Fatal("expected repository ListCharts() call.")
} }
} }
func TestListInstances(t *testing.T) { func TestListInstances(t *testing.T) {
testRepository.reset() testRepository.reset()
testManager.ListInstances("all") testManager.ListChartInstances("all")
if !testRepository.GetTypeInstancesCalled { if !testRepository.GetChartInstancesCalled {
t.Fatal("expected repository GetTypeInstances() call.") t.Fatal("expected repository GetChartInstances() call.")
} }
} }
// TODO(jackgr): Implement TestListRegistryTypes // TODO(jackgr): Implement TestListRepoCharts
func TestListRegistryTypes(t *testing.T) { func TestListRepoCharts(t *testing.T) {
/* /*
types, err := testManager.ListRegistryTypes("", nil) types, err := testManager.ListRepoCharts("", nil)
if err != nil { if err != nil {
t.Fatalf("cannot list registry types: %s", err) t.Fatalf("cannot list repository types: %s", err)
} }
*/ */
} }
...@@ -551,7 +551,7 @@ func TestListRegistryTypes(t *testing.T) { ...@@ -551,7 +551,7 @@ func TestListRegistryTypes(t *testing.T) {
// TODO(jackgr): Implement TestGetDownloadURLs // TODO(jackgr): Implement TestGetDownloadURLs
func TestGetDownloadURLs(t *testing.T) { func TestGetDownloadURLs(t *testing.T) {
/* /*
urls, err := testManager.GetDownloadURLs("", registry.Type{}) urls, err := testManager.GetDownloadURLs("", repo.Type{})
if err != nil { if err != nil {
t.Fatalf("cannot list get download urls: %s", err) t.Fatalf("cannot list get download urls: %s", err)
} }
......
...@@ -170,9 +170,9 @@ type Resource struct { ...@@ -170,9 +170,9 @@ type Resource struct {
State *ResourceState `json:"state,omitempty"` State *ResourceState `json:"state,omitempty"`
} }
// TypeInstance defines the metadata for an instantiation of a template type // ChartInstance defines the metadata for an instantiation of a template type
// in a deployment. // in a deployment.
type TypeInstance struct { type ChartInstance struct {
Name string `json:"name"` // instance name Name string `json:"name"` // instance name
Type string `json:"type"` // instance type Type string `json:"type"` // instance type
Deployment string `json:"deployment"` // deployment name Deployment string `json:"deployment"` // deployment name
......
Markdown is supported
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