mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-10-05 10:05:47 +00:00
add unit tests for rejection of conflicting namespaces
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
@@ -598,3 +599,39 @@ func TestServiceRegistryIPReloadFromStorage(t *testing.T) {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user