mirror of https://github.com/helm/helm
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
341 lines
8.4 KiB
341 lines
8.4 KiB
9 years ago
|
/*
|
||
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||
9 years ago
|
|
||
9 years ago
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
you may not use this file except in compliance with the License.
|
||
|
You may obtain a copy of the License at
|
||
9 years ago
|
|
||
9 years ago
|
http://www.apache.org/licenses/LICENSE-2.0
|
||
9 years ago
|
|
||
9 years ago
|
Unless required by applicable law or agreed to in writing, software
|
||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
See the License for the specific language governing permissions and
|
||
|
limitations under the License.
|
||
|
*/
|
||
|
|
||
|
package repository
|
||
|
|
||
|
import (
|
||
9 years ago
|
"github.com/kubernetes/deployment-manager/common"
|
||
9 years ago
|
|
||
9 years ago
|
"fmt"
|
||
9 years ago
|
"testing"
|
||
|
)
|
||
|
|
||
9 years ago
|
// TestRepositoryListEmpty checks that listing an empty repository works.
|
||
|
func TestRepositoryListEmpty(t *testing.T, r Repository) {
|
||
9 years ago
|
d, err := r.ListDeployments()
|
||
|
if err != nil {
|
||
|
t.Fatal("List Deployments failed")
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
if len(d) != 0 {
|
||
|
t.Fatal("Returned non zero list")
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
// TestRepositoryGetFailsWithNonExistentDeployment checks that getting a non-existent deployment fails.
|
||
|
func TestRepositoryGetFailsWithNonExistentDeployment(t *testing.T, r Repository) {
|
||
9 years ago
|
_, err := r.GetDeployment("nothere")
|
||
|
if err == nil {
|
||
|
t.Fatal("GetDeployment didn't fail with non-existent deployment")
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
func testCreateDeploymentWithManifests(t *testing.T, r Repository, count int) {
|
||
9 years ago
|
var deploymentName = "mydeployment"
|
||
9 years ago
|
|
||
9 years ago
|
d, err := r.CreateDeployment(deploymentName)
|
||
|
if err != nil {
|
||
|
t.Fatalf("CreateDeployment failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
l, err := r.ListDeployments()
|
||
|
if err != nil {
|
||
|
t.Fatalf("ListDeployments failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
if len(l) != 1 {
|
||
9 years ago
|
t.Fatalf("Number of deployments listed is not 1: %d", len(l))
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
dNew, err := r.GetDeployment(deploymentName)
|
||
|
if err != nil {
|
||
|
t.Fatalf("GetDeployment failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
if dNew.Name != d.Name {
|
||
|
t.Fatalf("Deployment Names don't match, got: %v, expected %v", dNew, d)
|
||
|
}
|
||
9 years ago
|
|
||
|
mList, err := r.ListManifests(deploymentName)
|
||
9 years ago
|
if err != nil {
|
||
|
t.Fatalf("ListManifests failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
if len(mList) != 0 {
|
||
|
t.Fatalf("Deployment has non-zero manifest count: %d", len(mList))
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
for i := 0; i < count; i++ {
|
||
|
var manifestName = fmt.Sprintf("manifest-%d", i)
|
||
9 years ago
|
manifest := common.Manifest{Deployment: deploymentName, Name: manifestName}
|
||
9 years ago
|
err := r.AddManifest(&manifest)
|
||
9 years ago
|
if err != nil {
|
||
|
t.Fatalf("AddManifest failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
d, err = r.GetDeployment(deploymentName)
|
||
9 years ago
|
if err != nil {
|
||
|
t.Fatalf("GetDeployment failed: %v", err)
|
||
|
}
|
||
|
|
||
9 years ago
|
if d.LatestManifest != manifestName {
|
||
|
t.Fatalf("AddManifest did not update LatestManifest: %#v", d)
|
||
|
}
|
||
|
|
||
9 years ago
|
mListNew, err := r.ListManifests(deploymentName)
|
||
|
if err != nil {
|
||
|
t.Fatalf("ListManifests failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
if len(mListNew) != i+1 {
|
||
|
t.Fatalf("Deployment has unexpected manifest count: want %d, have %d", i+1, len(mListNew))
|
||
|
}
|
||
|
|
||
|
m, err := r.GetManifest(deploymentName, manifestName)
|
||
|
if err != nil {
|
||
|
t.Fatalf("GetManifest failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
if m.Name != manifestName {
|
||
|
t.Fatalf("Unexpected manifest name: want %s, have %s", manifestName, m.Name)
|
||
|
}
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
// TestRepositoryCreateDeploymentWorks checks that creating a deployment works.
|
||
|
func TestRepositoryCreateDeploymentWorks(t *testing.T, r Repository) {
|
||
|
testCreateDeploymentWithManifests(t, r, 1)
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// TestRepositoryMultipleManifestsWorks checks that creating a deploymente with multiple manifests works.
|
||
|
func TestRepositoryMultipleManifestsWorks(t *testing.T, r Repository) {
|
||
|
testCreateDeploymentWithManifests(t, r, 7)
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// TestRepositoryDeleteFailsWithNonExistentDeployment checks that deleting a non-existent deployment fails.
|
||
|
func TestRepositoryDeleteFailsWithNonExistentDeployment(t *testing.T, r Repository) {
|
||
9 years ago
|
var deploymentName = "mydeployment"
|
||
|
d, err := r.DeleteDeployment(deploymentName, false)
|
||
|
if err == nil {
|
||
|
t.Fatalf("DeleteDeployment didn't fail with non existent deployment")
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
if d != nil {
|
||
|
t.Fatalf("DeleteDeployment returned non-nil for non existent deployment")
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
// TestRepositoryDeleteWorksWithNoLatestManifest checks that deleting a deployment with no latest manifest works.
|
||
|
func TestRepositoryDeleteWorksWithNoLatestManifest(t *testing.T, r Repository) {
|
||
9 years ago
|
var deploymentName = "mydeployment"
|
||
|
_, err := r.CreateDeployment(deploymentName)
|
||
|
if err != nil {
|
||
|
t.Fatalf("CreateDeployment failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
dDeleted, err := r.DeleteDeployment(deploymentName, false)
|
||
|
if err != nil {
|
||
|
t.Fatalf("DeleteDeployment failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
if dDeleted.State.Status != common.DeletedStatus {
|
||
9 years ago
|
t.Fatalf("Deployment Status is not deleted")
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
if _, err := r.ListManifests(deploymentName); err == nil {
|
||
|
t.Fatalf("Manifests are not deleted")
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
// TestRepositoryDeleteDeploymentWorksNoForget checks that deleting a deployment without forgetting it works.
|
||
|
func TestRepositoryDeleteDeploymentWorksNoForget(t *testing.T, r Repository) {
|
||
9 years ago
|
var deploymentName = "mydeployment"
|
||
|
var manifestName = "manifest-0"
|
||
9 years ago
|
manifest := common.Manifest{Deployment: deploymentName, Name: manifestName}
|
||
9 years ago
|
_, err := r.CreateDeployment(deploymentName)
|
||
|
if err != nil {
|
||
|
t.Fatalf("CreateDeployment failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
|
err = r.AddManifest(&manifest)
|
||
9 years ago
|
if err != nil {
|
||
|
t.Fatalf("AddManifest failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
dDeleted, err := r.DeleteDeployment(deploymentName, false)
|
||
|
if err != nil {
|
||
|
t.Fatalf("DeleteDeployment failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
if dDeleted.State.Status != common.DeletedStatus {
|
||
9 years ago
|
t.Fatalf("Deployment Status is not deleted")
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
// TestRepositoryDeleteDeploymentWorksForget checks that deleting and forgetting a deployment works.
|
||
|
func TestRepositoryDeleteDeploymentWorksForget(t *testing.T, r Repository) {
|
||
9 years ago
|
var deploymentName = "mydeployment"
|
||
|
var manifestName = "manifest-0"
|
||
9 years ago
|
manifest := common.Manifest{Deployment: deploymentName, Name: manifestName}
|
||
9 years ago
|
_, err := r.CreateDeployment(deploymentName)
|
||
|
if err != nil {
|
||
|
t.Fatalf("CreateDeployment failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
|
err = r.AddManifest(&manifest)
|
||
9 years ago
|
if err != nil {
|
||
|
t.Fatalf("AddManifest failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
dDeleted, err := r.DeleteDeployment(deploymentName, true)
|
||
|
if err != nil {
|
||
|
t.Fatalf("DeleteDeployment failed: %v", err)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
if dDeleted.State.Status != common.CreatedStatus {
|
||
9 years ago
|
t.Fatalf("Deployment Status is not created")
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
// TestRepositoryTypeInstances checks that type instances can be listed and retrieved successfully.
|
||
|
func TestRepositoryTypeInstances(t *testing.T, r Repository) {
|
||
9 years ago
|
d1Map := map[string][]*common.TypeInstance{
|
||
|
"t1": []*common.TypeInstance{
|
||
|
&common.TypeInstance{
|
||
9 years ago
|
Name: "i1",
|
||
|
Type: "t1",
|
||
|
Deployment: "d1",
|
||
|
Manifest: "m1",
|
||
|
Path: "p1",
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
9 years ago
|
d2Map := map[string][]*common.TypeInstance{
|
||
|
"t2": []*common.TypeInstance{
|
||
|
&common.TypeInstance{
|
||
9 years ago
|
Name: "i2",
|
||
|
Type: "t2",
|
||
|
Deployment: "d2",
|
||
|
Manifest: "m2",
|
||
|
Path: "p2",
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
9 years ago
|
d3Map := map[string][]*common.TypeInstance{
|
||
|
"t2": []*common.TypeInstance{
|
||
|
&common.TypeInstance{
|
||
9 years ago
|
Name: "i3",
|
||
|
Type: "t2",
|
||
|
Deployment: "d3",
|
||
|
Manifest: "m3",
|
||
|
Path: "p3",
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
9 years ago
|
instances, err := r.GetTypeInstances("noinstances")
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if len(instances) != 0 {
|
||
9 years ago
|
t.Fatalf("expected no instances: %v", instances)
|
||
|
}
|
||
|
|
||
9 years ago
|
types, err := r.ListTypes()
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if len(types) != 0 {
|
||
9 years ago
|
t.Fatalf("expected no types: %v", types)
|
||
|
}
|
||
|
|
||
9 years ago
|
r.AddTypeInstances(d1Map)
|
||
|
r.AddTypeInstances(d2Map)
|
||
|
r.AddTypeInstances(d3Map)
|
||
9 years ago
|
|
||
9 years ago
|
instances, err = r.GetTypeInstances("unknowntype")
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if len(instances) != 0 {
|
||
9 years ago
|
t.Fatalf("expected no instances: %v", instances)
|
||
|
}
|
||
|
|
||
9 years ago
|
instances, err = r.GetTypeInstances("t1")
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if len(instances) != 1 {
|
||
9 years ago
|
t.Fatalf("expected one instance: %v", instances)
|
||
|
}
|
||
|
|
||
9 years ago
|
instances, err = r.GetTypeInstances("t2")
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if len(instances) != 2 {
|
||
9 years ago
|
t.Fatalf("expected two instances: %v", instances)
|
||
|
}
|
||
|
|
||
9 years ago
|
instances, err = r.GetTypeInstances("all")
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if len(instances) != 3 {
|
||
9 years ago
|
t.Fatalf("expected three total instances: %v", instances)
|
||
|
}
|
||
|
|
||
9 years ago
|
types, err = r.ListTypes()
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if len(types) != 2 {
|
||
9 years ago
|
t.Fatalf("expected two total types: %v", types)
|
||
|
}
|
||
|
|
||
9 years ago
|
err = r.ClearTypeInstancesForDeployment("d1")
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
instances, err = r.GetTypeInstances("t1")
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if len(instances) != 0 {
|
||
9 years ago
|
t.Fatalf("expected no instances after clear: %v", instances)
|
||
|
}
|
||
|
|
||
9 years ago
|
types, err = r.ListTypes()
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if len(types) != 1 {
|
||
9 years ago
|
t.Fatalf("expected one total type: %v", types)
|
||
|
}
|
||
|
}
|