add unit tests for rejection of conflicting namespaces

This commit is contained in:
deads2k
2014-10-08 16:26:57 -04:00
parent 23ce178574
commit 34b5861b60
3 changed files with 111 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ package pod
import (
"fmt"
"reflect"
"strings"
"testing"
"time"
@@ -651,3 +652,39 @@ func TestFillPodInfoNoData(t *testing.T) {
t.Errorf("Expected %s, Got %s", expectedIP, pod.CurrentState.PodIP)
}
}
func TestCreatePodWithConflictingNamespace(t *testing.T) {
storage := REST{}
pod := &api.Pod{
TypeMeta: api.TypeMeta{ID: "test", Namespace: "not-default"},
}
ctx := api.NewDefaultContext()
channel, err := storage.Create(ctx, pod)
if channel != nil {
t.Error("Expected a nil channel, but we got a value")
}
if err == nil {
t.Errorf("Expected an error, but we didn't get one")
} else if strings.Index(err.Error(), "Pod.Namespace does not match the provided context") == -1 {
t.Errorf("Expected 'Pod.Namespace does not match the provided context' error, got '%v'", err.Error())
}
}
func TestUpdatePodWithConflictingNamespace(t *testing.T) {
storage := REST{}
pod := &api.Pod{
TypeMeta: api.TypeMeta{ID: "test", Namespace: "not-default"},
}
ctx := api.NewDefaultContext()
channel, err := storage.Update(ctx, pod)
if channel != nil {
t.Error("Expected a nil channel, but we got a value")
}
if err == nil {
t.Errorf("Expected an error, but we didn't get one")
} else if strings.Index(err.Error(), "Pod.Namespace does not match the provided context") == -1 {
t.Errorf("Expected 'Pod.Namespace does not match the provided context' error, got '%v'", err.Error())
}
}