mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #1933 from deads2k/dev/deads/add-namespace-unit-tests
add unit tests for rejection of conflicting namespaces
This commit is contained in:
commit
b16a4c0c88
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -363,3 +364,39 @@ func TestFillCurrentState(t *testing.T) {
|
|||||||
t.Errorf("unexpected output: %#v %#v", labels.Set(controller.DesiredState.ReplicaSelector).AsSelector(), fakeLister.s)
|
t.Errorf("unexpected output: %#v %#v", labels.Set(controller.DesiredState.ReplicaSelector).AsSelector(), fakeLister.s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateControllerWithConflictingNamespace(t *testing.T) {
|
||||||
|
storage := REST{}
|
||||||
|
controller := &api.ReplicationController{
|
||||||
|
TypeMeta: api.TypeMeta{ID: "test", Namespace: "not-default"},
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := api.NewDefaultContext()
|
||||||
|
channel, err := storage.Create(ctx, controller)
|
||||||
|
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(), "Controller.Namespace does not match the provided context") == -1 {
|
||||||
|
t.Errorf("Expected 'Controller.Namespace does not match the provided context' error, got '%v'", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateControllerWithConflictingNamespace(t *testing.T) {
|
||||||
|
storage := REST{}
|
||||||
|
controller := &api.ReplicationController{
|
||||||
|
TypeMeta: api.TypeMeta{ID: "test", Namespace: "not-default"},
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := api.NewDefaultContext()
|
||||||
|
channel, err := storage.Update(ctx, controller)
|
||||||
|
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(), "Controller.Namespace does not match the provided context") == -1 {
|
||||||
|
t.Errorf("Expected 'Controller.Namespace does not match the provided context' error, got '%v'", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@ package pod
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -651,3 +652,39 @@ func TestFillPodInfoNoData(t *testing.T) {
|
|||||||
t.Errorf("Expected %s, Got %s", expectedIP, pod.CurrentState.PodIP)
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
@ -598,3 +599,39 @@ func TestServiceRegistryIPReloadFromStorage(t *testing.T) {
|
|||||||
t.Errorf("Unexpected PortalIP: %s", created_service.PortalIP)
|
t.Errorf("Unexpected PortalIP: %s", created_service.PortalIP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateServiceWithConflictingNamespace(t *testing.T) {
|
||||||
|
storage := REST{}
|
||||||
|
service := &api.Service{
|
||||||
|
TypeMeta: api.TypeMeta{ID: "test", Namespace: "not-default"},
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := api.NewDefaultContext()
|
||||||
|
channel, err := storage.Create(ctx, service)
|
||||||
|
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(), "Service.Namespace does not match the provided context") == -1 {
|
||||||
|
t.Errorf("Expected 'Service.Namespace does not match the provided context' error, got '%v'", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateServiceWithConflictingNamespace(t *testing.T) {
|
||||||
|
storage := REST{}
|
||||||
|
service := &api.Service{
|
||||||
|
TypeMeta: api.TypeMeta{ID: "test", Namespace: "not-default"},
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := api.NewDefaultContext()
|
||||||
|
channel, err := storage.Update(ctx, service)
|
||||||
|
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(), "Service.Namespace does not match the provided context") == -1 {
|
||||||
|
t.Errorf("Expected 'Service.Namespace does not match the provided context' error, got '%v'", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user