Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b16a4c0c
Commit
b16a4c0c
authored
Oct 21, 2014
by
Dawn Chen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1933 from deads2k/dev/deads/add-namespace-unit-tests
add unit tests for rejection of conflicting namespaces
parents
a8b55e09
34b5861b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
0 deletions
+111
-0
rest_test.go
pkg/registry/controller/rest_test.go
+37
-0
rest_test.go
pkg/registry/pod/rest_test.go
+37
-0
rest_test.go
pkg/registry/service/rest_test.go
+37
-0
No files found.
pkg/registry/controller/rest_test.go
View file @
b16a4c0c
...
@@ -21,6 +21,7 @@ import (
...
@@ -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) {
...
@@ -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
())
}
}
pkg/registry/pod/rest_test.go
View file @
b16a4c0c
...
@@ -19,6 +19,7 @@ package pod
...
@@ -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) {
...
@@ -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
())
}
}
pkg/registry/service/rest_test.go
View file @
b16a4c0c
...
@@ -20,6 +20,7 @@ import (
...
@@ -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) {
...
@@ -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
())
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment