|
|
|
@ -37,8 +37,7 @@ var resourcesWithFailureState = Configuration{
|
|
|
|
|
Type: "test",
|
|
|
|
|
State: &ResourceState{
|
|
|
|
|
Status: Failed,
|
|
|
|
|
Errors:[]string{"test induced error",
|
|
|
|
|
},
|
|
|
|
|
Errors: []string{"test induced error"},
|
|
|
|
|
},
|
|
|
|
|
}},
|
|
|
|
|
}
|
|
|
|
@ -48,24 +47,15 @@ var expandedConfig = ExpandedTemplate{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var deploymentName = "deployment"
|
|
|
|
|
var deploymentNoManifestName = "deploymentNoManifest"
|
|
|
|
|
|
|
|
|
|
var manifestName = "manifest-2"
|
|
|
|
|
var manifest = Manifest{Name: manifestName, ExpandedConfig: &configuration, Layout: &layout}
|
|
|
|
|
var manifestMap = map[string]*Manifest{manifest.Name: &manifest}
|
|
|
|
|
|
|
|
|
|
var deploymentNoManifest = Deployment{
|
|
|
|
|
Name: "test",
|
|
|
|
|
}
|
|
|
|
|
var deployment = Deployment{
|
|
|
|
|
Name: "test",
|
|
|
|
|
Manifests: manifestMap,
|
|
|
|
|
}
|
|
|
|
|
var deploymentWithConfiguration = Deployment{
|
|
|
|
|
Name: "test",
|
|
|
|
|
Manifests: manifestMap,
|
|
|
|
|
Current: &configuration,
|
|
|
|
|
Name: "test",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var deploymentList = []Deployment{deployment, {Name: "test2"}}
|
|
|
|
|
|
|
|
|
|
var typeInstMap = map[string][]string{"test": []string{"test"}}
|
|
|
|
@ -83,10 +73,10 @@ func (expander *expanderStub) ExpandTemplate(t Template) (*ExpandedTemplate, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type deployerStub struct {
|
|
|
|
|
FailCreate bool
|
|
|
|
|
Created []*Configuration
|
|
|
|
|
FailDelete bool
|
|
|
|
|
Deleted []*Configuration
|
|
|
|
|
FailCreate bool
|
|
|
|
|
Created []*Configuration
|
|
|
|
|
FailDelete bool
|
|
|
|
|
Deleted []*Configuration
|
|
|
|
|
FailCreateResource bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -174,16 +164,12 @@ func (repository *repositoryStub) GetDeployment(d string) (*Deployment, error) {
|
|
|
|
|
return &deployment, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d == deploymentNoManifestName {
|
|
|
|
|
return &deploymentNoManifest, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, errTest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (repository *repositoryStub) GetValidDeployment(d string) (*Deployment, error) {
|
|
|
|
|
repository.GetValid = append(repository.GetValid, d)
|
|
|
|
|
return &deploymentWithConfiguration, nil
|
|
|
|
|
return &deployment, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (repository *repositoryStub) SetDeploymentStatus(name string, status DeploymentStatus) error {
|
|
|
|
@ -193,12 +179,12 @@ func (repository *repositoryStub) SetDeploymentStatus(name string, status Deploy
|
|
|
|
|
|
|
|
|
|
func (repository *repositoryStub) CreateDeployment(d string) (*Deployment, error) {
|
|
|
|
|
repository.Created = append(repository.Created, d)
|
|
|
|
|
return &deploymentWithConfiguration, nil
|
|
|
|
|
return &deployment, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (repository *repositoryStub) DeleteDeployment(d string, forget bool) (*Deployment, error) {
|
|
|
|
|
repository.Deleted = append(repository.Deleted, d)
|
|
|
|
|
return &deploymentWithConfiguration, nil
|
|
|
|
|
return &deployment, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (repository *repositoryStub) AddManifest(d string, manifest *Manifest) error {
|
|
|
|
@ -206,6 +192,14 @@ func (repository *repositoryStub) AddManifest(d string, manifest *Manifest) erro
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (repository *repositoryStub) GetLatestManifest(d string) (*Manifest, error) {
|
|
|
|
|
if d == deploymentName {
|
|
|
|
|
return repository.ManifestAdd[d], nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, errTest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (repository *repositoryStub) ListManifests(d string) (map[string]*Manifest, error) {
|
|
|
|
|
if d == deploymentName {
|
|
|
|
|
return manifestMap, nil
|
|
|
|
@ -250,8 +244,12 @@ var testManager = NewManager(testExpander, testDeployer, testRepository)
|
|
|
|
|
func TestListDeployments(t *testing.T) {
|
|
|
|
|
testRepository.reset()
|
|
|
|
|
d, err := testManager.ListDeployments()
|
|
|
|
|
if !reflect.DeepEqual(d, deploymentList) || err != nil {
|
|
|
|
|
t.FailNow()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf(err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(d, deploymentList) {
|
|
|
|
|
t.Fatalf("invalid deployment list")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -259,40 +257,48 @@ func TestListDeploymentsFail(t *testing.T) {
|
|
|
|
|
testRepository.reset()
|
|
|
|
|
testRepository.FailListDeployments = true
|
|
|
|
|
d, err := testManager.ListDeployments()
|
|
|
|
|
if d != nil || err != errTest {
|
|
|
|
|
t.FailNow()
|
|
|
|
|
if err != errTest {
|
|
|
|
|
t.Fatalf(err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d != nil {
|
|
|
|
|
t.Fatalf("deployment list is not empty")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetDeployment(t *testing.T) {
|
|
|
|
|
testRepository.reset()
|
|
|
|
|
d, err := testManager.GetDeployment(deploymentName)
|
|
|
|
|
if !reflect.DeepEqual(d, &deploymentWithConfiguration) || err != nil {
|
|
|
|
|
t.FailNow()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf(err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetDeploymentNoManifest(t *testing.T) {
|
|
|
|
|
testRepository.reset()
|
|
|
|
|
d, err := testManager.GetDeployment(deploymentNoManifestName)
|
|
|
|
|
if !reflect.DeepEqual(d, &deploymentNoManifest) || err != nil {
|
|
|
|
|
t.FailNow()
|
|
|
|
|
if !reflect.DeepEqual(d, &deployment) {
|
|
|
|
|
t.Fatalf("invalid deployment")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestListManifests(t *testing.T) {
|
|
|
|
|
testRepository.reset()
|
|
|
|
|
m, err := testManager.ListManifests(deploymentName)
|
|
|
|
|
if !reflect.DeepEqual(m, manifestMap) || err != nil {
|
|
|
|
|
t.FailNow()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf(err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(m, manifestMap) {
|
|
|
|
|
t.Fatalf("invalid manifest map")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetManifest(t *testing.T) {
|
|
|
|
|
testRepository.reset()
|
|
|
|
|
m, err := testManager.GetManifest(deploymentName, manifestName)
|
|
|
|
|
if !reflect.DeepEqual(m, &manifest) || err != nil {
|
|
|
|
|
t.FailNow()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf(err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(m, &manifest) {
|
|
|
|
|
t.Fatalf("invalid manifest")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -300,36 +306,36 @@ func TestCreateDeployment(t *testing.T) {
|
|
|
|
|
testRepository.reset()
|
|
|
|
|
testDeployer.reset()
|
|
|
|
|
d, err := testManager.CreateDeployment(&template)
|
|
|
|
|
if !reflect.DeepEqual(d, &deploymentWithConfiguration) || err != nil {
|
|
|
|
|
t.Errorf("Expected a different set of response values from invoking CreateDeployment."+
|
|
|
|
|
"Received: %s, %s. Expected: %s, %s.", d, err, &deploymentWithConfiguration, "nil")
|
|
|
|
|
if !reflect.DeepEqual(d, &deployment) || err != nil {
|
|
|
|
|
t.Fatalf("Expected a different set of response values from invoking CreateDeployment."+
|
|
|
|
|
"Received: %s, %s. Expected: %s, %s.", d, err, &deployment, "nil")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if testRepository.Created[0] != template.Name {
|
|
|
|
|
t.Errorf("Repository CreateDeployment was called with %s but expected %s.",
|
|
|
|
|
t.Fatalf("Repository CreateDeployment was called with %s but expected %s.",
|
|
|
|
|
testRepository.Created[0], template.Name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !strings.HasPrefix(testRepository.ManifestAdd[template.Name].Name, "manifest-") {
|
|
|
|
|
t.Errorf("Repository AddManifest was called with %s but expected manifest name"+
|
|
|
|
|
t.Fatalf("Repository AddManifest was called with %s but expected manifest name"+
|
|
|
|
|
"to begin with manifest-.", testRepository.ManifestAdd[template.Name].Name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(*testDeployer.Created[0], configuration) || err != nil {
|
|
|
|
|
t.Errorf("Deployer CreateConfiguration was called with %s but expected %s.",
|
|
|
|
|
t.Fatalf("Deployer CreateConfiguration was called with %s but expected %s.",
|
|
|
|
|
testDeployer.Created[0], configuration)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if testRepository.DeploymentStatuses[0] != DeployedStatus {
|
|
|
|
|
t.Error("CreateDeployment success did not mark deployment as deployed")
|
|
|
|
|
t.Fatal("CreateDeployment success did not mark deployment as deployed")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !testRepository.TypeInstancesCleared {
|
|
|
|
|
t.Error("Repository did not clear type instances during creation")
|
|
|
|
|
t.Fatal("Repository did not clear type instances during creation")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(testRepository.TypeInstances, typeInstMap) {
|
|
|
|
|
t.Errorf("Unexpected type instances after CreateDeployment: %s", testRepository.TypeInstances)
|
|
|
|
|
t.Fatalf("Unexpected type instances after CreateDeployment: %s", testRepository.TypeInstances)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -340,26 +346,26 @@ func TestCreateDeploymentCreationFailure(t *testing.T) {
|
|
|
|
|
d, err := testManager.CreateDeployment(&template)
|
|
|
|
|
|
|
|
|
|
if testRepository.Created[0] != template.Name {
|
|
|
|
|
t.Errorf("Repository CreateDeployment was called with %s but expected %s.",
|
|
|
|
|
t.Fatalf("Repository CreateDeployment was called with %s but expected %s.",
|
|
|
|
|
testRepository.Created[0], template.Name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(testRepository.Deleted) != 0 {
|
|
|
|
|
t.Errorf("DeleteDeployment was called with %s but not expected",
|
|
|
|
|
t.Fatalf("DeleteDeployment was called with %s but not expected",
|
|
|
|
|
testRepository.Created[0])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if testRepository.DeploymentStatuses[0] != FailedStatus {
|
|
|
|
|
t.Error("CreateDeployment failure did not mark deployment as failed")
|
|
|
|
|
t.Fatal("CreateDeployment failure did not mark deployment as failed")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err != errTest || d != nil {
|
|
|
|
|
t.Errorf("Expected a different set of response values from invoking CreateDeployment."+
|
|
|
|
|
t.Fatalf("Expected a different set of response values from invoking CreateDeployment."+
|
|
|
|
|
"Received: %s, %s. Expected: %s, %s.", d, err, "nil", errTest)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if testRepository.TypeInstancesCleared {
|
|
|
|
|
t.Error("Unexpected change to type instances during CreateDeployment failure.")
|
|
|
|
|
t.Fatal("Unexpected change to type instances during CreateDeployment failure.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -370,32 +376,31 @@ func TestCreateDeploymentCreationResourceFailure(t *testing.T) {
|
|
|
|
|
d, err := testManager.CreateDeployment(&template)
|
|
|
|
|
|
|
|
|
|
if testRepository.Created[0] != template.Name {
|
|
|
|
|
t.Errorf("Repository CreateDeployment was called with %s but expected %s.",
|
|
|
|
|
t.Fatalf("Repository CreateDeployment was called with %s but expected %s.",
|
|
|
|
|
testRepository.Created[0], template.Name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(testRepository.Deleted) != 0 {
|
|
|
|
|
t.Errorf("DeleteDeployment was called with %s but not expected",
|
|
|
|
|
t.Fatalf("DeleteDeployment was called with %s but not expected",
|
|
|
|
|
testRepository.Created[0])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if testRepository.DeploymentStatuses[0] != FailedStatus {
|
|
|
|
|
t.Error("CreateDeployment failure did not mark deployment as failed")
|
|
|
|
|
t.Fatal("CreateDeployment failure did not mark deployment as failed")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !strings.HasPrefix(testRepository.ManifestAdd[template.Name].Name, "manifest-") {
|
|
|
|
|
t.Errorf("Repository AddManifest was called with %s but expected manifest name"+
|
|
|
|
|
t.Fatalf("Repository AddManifest was called with %s but expected manifest name"+
|
|
|
|
|
"to begin with manifest-.", testRepository.ManifestAdd[template.Name].Name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if err != errTest || d != nil {
|
|
|
|
|
if d == nil {
|
|
|
|
|
t.Errorf("Expected a different set of response values from invoking CreateDeployment."+
|
|
|
|
|
"Received: %s, %s. Expected: %s, %s.", d, err, "nil", errTest)
|
|
|
|
|
if err != nil || !reflect.DeepEqual(d, &deployment) {
|
|
|
|
|
t.Fatalf("Expected a different set of response values from invoking CreateDeployment.\n"+
|
|
|
|
|
"Received: %v, %v. Expected: %v, %v.", d, err, &deployment, "nil")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !testRepository.TypeInstancesCleared {
|
|
|
|
|
t.Error("Repository did not clear type instances during creation")
|
|
|
|
|
t.Fatal("Repository did not clear type instances during creation")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -403,71 +408,69 @@ func TestDeleteDeploymentForget(t *testing.T) {
|
|
|
|
|
testRepository.reset()
|
|
|
|
|
testDeployer.reset()
|
|
|
|
|
d, err := testManager.CreateDeployment(&template)
|
|
|
|
|
if !reflect.DeepEqual(d, &deploymentWithConfiguration) || err != nil {
|
|
|
|
|
t.Errorf("Expected a different set of response values from invoking CreateDeployment."+
|
|
|
|
|
"Received: %s, %s. Expected: %s, %s.", d, err, &deploymentWithConfiguration, "nil")
|
|
|
|
|
if !reflect.DeepEqual(d, &deployment) || err != nil {
|
|
|
|
|
t.Fatalf("Expected a different set of response values from invoking CreateDeployment."+
|
|
|
|
|
"Received: %s, %s. Expected: %s, %s.", d, err, &deployment, "nil")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if testRepository.Created[0] != template.Name {
|
|
|
|
|
t.Errorf("Repository CreateDeployment was called with %s but expected %s.",
|
|
|
|
|
t.Fatalf("Repository CreateDeployment was called with %s but expected %s.",
|
|
|
|
|
testRepository.Created[0], template.Name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !strings.HasPrefix(testRepository.ManifestAdd[template.Name].Name, "manifest-") {
|
|
|
|
|
t.Errorf("Repository AddManifest was called with %s but expected manifest name"+
|
|
|
|
|
t.Fatalf("Repository AddManifest was called with %s but expected manifest name"+
|
|
|
|
|
"to begin with manifest-.", testRepository.ManifestAdd[template.Name].Name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(*testDeployer.Created[0], configuration) || err != nil {
|
|
|
|
|
t.Errorf("Deployer CreateConfiguration was called with %s but expected %s.",
|
|
|
|
|
t.Fatalf("Deployer CreateConfiguration was called with %s but expected %s.",
|
|
|
|
|
testDeployer.Created[0], configuration)
|
|
|
|
|
}
|
|
|
|
|
oldManifestName := testRepository.ManifestAdd[template.Name].Name
|
|
|
|
|
d, err = testManager.DeleteDeployment("test", true)
|
|
|
|
|
d, err = testManager.DeleteDeployment(deploymentName, true)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("DeleteDeployment failed with %v", err)
|
|
|
|
|
}
|
|
|
|
|
if testRepository.ManifestAdd[template.Name].Name == oldManifestName {
|
|
|
|
|
t.Errorf("New manifest was not created, is still: %s", oldManifestName)
|
|
|
|
|
}
|
|
|
|
|
if testRepository.ManifestAdd[template.Name].InputConfig != nil {
|
|
|
|
|
t.Errorf("New manifest has non-nil config, is still: %v", testRepository.ManifestAdd[template.Name].InputConfig)
|
|
|
|
|
t.Fatalf("DeleteDeployment failed with %v", err)
|
|
|
|
|
}
|
|
|
|
|
// Make sure the resources were deleted through deployer.
|
|
|
|
|
if !reflect.DeepEqual(*testDeployer.Deleted[0], configuration) || err != nil {
|
|
|
|
|
t.Errorf("Deployer DeleteConfiguration was called with %s but expected %s.",
|
|
|
|
|
testDeployer.Created[0], configuration)
|
|
|
|
|
if len(testDeployer.Deleted) > 0 {
|
|
|
|
|
c := testDeployer.Deleted[0]
|
|
|
|
|
if c != nil {
|
|
|
|
|
if !reflect.DeepEqual(*c, configuration) || err != nil {
|
|
|
|
|
t.Fatalf("Deployer DeleteConfiguration was called with %s but expected %s.",
|
|
|
|
|
testDeployer.Created[0], configuration)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !testRepository.TypeInstancesCleared {
|
|
|
|
|
t.Error("Expected type instances to be cleared during DeleteDeployment.")
|
|
|
|
|
t.Fatal("Expected type instances to be cleared during DeleteDeployment.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExpand(t *testing.T) {
|
|
|
|
|
m, err := testManager.Expand(&template)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error("Failed to expand template into manifest.")
|
|
|
|
|
t.Fatal("Failed to expand template into manifest.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.Name != "" {
|
|
|
|
|
t.Errorf("Name was not empty: %v", *m)
|
|
|
|
|
t.Fatalf("Name was not empty: %v", *m)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.Deployment != "" {
|
|
|
|
|
t.Errorf("Deployment was not empty: %v", *m)
|
|
|
|
|
t.Fatalf("Deployment was not empty: %v", *m)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.InputConfig != nil {
|
|
|
|
|
t.Errorf("Input config not nil: %v", *m)
|
|
|
|
|
t.Fatalf("Input config not nil: %v", *m)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(*m.ExpandedConfig, configuration) {
|
|
|
|
|
t.Errorf("Expanded config not correct in output manifest: %v", *m)
|
|
|
|
|
t.Fatalf("Expanded config not correct in output manifest: %v", *m)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(*m.Layout, layout) {
|
|
|
|
|
t.Errorf("Layout not correct in output manifest: %v", *m)
|
|
|
|
|
t.Fatalf("Layout not correct in output manifest: %v", *m)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -477,7 +480,7 @@ func TestListTypes(t *testing.T) {
|
|
|
|
|
testManager.ListTypes()
|
|
|
|
|
|
|
|
|
|
if !testRepository.ListTypesCalled {
|
|
|
|
|
t.Error("expected repository ListTypes() call.")
|
|
|
|
|
t.Fatal("expected repository ListTypes() call.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -487,6 +490,6 @@ func TestListInstances(t *testing.T) {
|
|
|
|
|
testManager.ListInstances("all")
|
|
|
|
|
|
|
|
|
|
if !testRepository.GetTypeInstancesCalled {
|
|
|
|
|
t.Error("expected repository GetTypeInstances() call.")
|
|
|
|
|
t.Fatal("expected repository GetTypeInstances() call.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|