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
3e61baf3
Commit
3e61baf3
authored
Nov 22, 2016
by
Marcin Wielgus
Committed by
Marcin
Dec 05, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable update tests for federated secret controller
parent
7d1a7eae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
34 deletions
+46
-34
secret_controller_test.go
...kg/federation-controller/secret/secret_controller_test.go
+45
-33
test_helper.go
...ration/pkg/federation-controller/util/test/test_helper.go
+1
-1
No files found.
federation/pkg/federation-controller/secret/secret_controller_test.go
View file @
3e61baf3
...
...
@@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util/wait"
"github.com/golang/glog"
"github.com/stretchr/testify/assert"
)
...
...
@@ -52,7 +53,7 @@ func TestSecretController(t *testing.T) {
cluster1Watch
:=
RegisterFakeWatch
(
"secrets"
,
&
cluster1Client
.
Fake
)
RegisterFakeList
(
"secrets"
,
&
cluster1Client
.
Fake
,
&
apiv1
.
SecretList
{
Items
:
[]
apiv1
.
Secret
{}})
cluster1CreateChan
:=
RegisterFakeCopyOnCreate
(
"secrets"
,
&
cluster1Client
.
Fake
,
cluster1Watch
)
//
cluster1UpdateChan := RegisterFakeCopyOnUpdate("secrets", &cluster1Client.Fake, cluster1Watch)
cluster1UpdateChan
:=
RegisterFakeCopyOnUpdate
(
"secrets"
,
&
cluster1Client
.
Fake
,
cluster1Watch
)
cluster2Client
:=
&
fakekubeclientset
.
Clientset
{}
cluster2Watch
:=
RegisterFakeWatch
(
"secrets"
,
&
cluster2Client
.
Fake
)
...
...
@@ -116,38 +117,45 @@ func TestSecretController(t *testing.T) {
cluster1
.
Name
,
types
.
NamespacedName
{
Namespace
:
secret1
.
Namespace
,
Name
:
secret1
.
Name
}
.
String
(),
wait
.
ForeverTestTimeout
)
assert
.
Nil
(
t
,
err
,
"secret should have appeared in the informer store"
)
/*
// TODO: Uncomment this once we have figured out why this is flaky.
// Test update federated secret.
secret1.Annotations = map[string]string{
"A": "B",
checkAll
:=
func
(
expected
apiv1
.
Secret
)
CheckingFunction
{
return
func
(
obj
runtime
.
Object
)
error
{
glog
.
V
(
4
)
.
Infof
(
"Checking %v"
,
obj
)
s
:=
obj
.
(
*
apiv1
.
Secret
)
if
err
:=
CompareObjectMeta
(
expected
.
ObjectMeta
,
s
.
ObjectMeta
);
err
!=
nil
{
return
err
}
secretWatch.Modify(&secret1)
updatedSecret = GetSecretFromChan(cluster1UpdateChan)
assert.NotNil(t, updatedSecret)
assert.Equal(t, secret1.Name, updatedSecret.Name)
assert.Equal(t, secret1.Namespace, updatedSecret.Namespace)
assert.True(t, secretsEqual(secret1, *updatedSecret),
fmt.Sprintf("expected: %v, actual: %v", secret1, *updatedSecret))
// Wait for the secret to be updated in the informer store.
err = WaitForSecretStoreUpdate(
secretController.secretFederatedInformer.GetTargetStore(),
cluster1.Name, types.NamespacedName{Namespace: secret1.Namespace, Name: secret1.Name}.String(),
updatedSecret, wait.ForeverTestTimeout)
assert.Nil(t, err, "secret should have been updated in the informer store")
// Test update federated secret.
secret1.Data = map[string][]byte{
"config": []byte("myconfigurationfile"),
}
secretWatch.Modify(&secret1)
updatedSecret2 := GetSecretFromChan(cluster1UpdateChan)
assert.NotNil(t, updatedSecret2)
assert.Equal(t, secret1.Name, updatedSecret2.Name)
assert.Equal(t, secret1.Namespace, updatedSecret.Namespace)
assert.True(t, secretsEqual(secret1, *updatedSecret2),
fmt.Sprintf("expected: %v, actual: %v", secret1, *updatedSecret2))
*/
if
!
reflect
.
DeepEqual
(
expected
.
Data
,
s
.
Data
)
{
return
fmt
.
Errorf
(
"Data is different expected:%v actual:%v"
,
expected
.
Data
,
s
.
Data
)
}
if
expected
.
Type
!=
s
.
Type
{
return
fmt
.
Errorf
(
"Type is different expected:%v actual:%v"
,
expected
.
Type
,
s
.
Type
)
}
return
nil
}
}
// Test update federated secret.
secret1
.
Annotations
=
map
[
string
]
string
{
"A"
:
"B"
,
}
secretWatch
.
Modify
(
&
secret1
)
err
=
CheckObjectFromChan
(
cluster1UpdateChan
,
checkAll
(
secret1
))
assert
.
NoError
(
t
,
err
)
// Wait for the secret to be updated in the informer store.
err
=
WaitForSecretStoreUpdate
(
secretController
.
secretFederatedInformer
.
GetTargetStore
(),
cluster1
.
Name
,
types
.
NamespacedName
{
Namespace
:
secret1
.
Namespace
,
Name
:
secret1
.
Name
}
.
String
(),
&
secret1
,
wait
.
ForeverTestTimeout
)
assert
.
NoError
(
t
,
err
,
"secret should have been updated in the informer store"
)
// Test update federated secret.
secret1
.
Data
=
map
[
string
][]
byte
{
"config"
:
[]
byte
(
"myconfigurationfile"
),
}
secretWatch
.
Modify
(
&
secret1
)
err
=
CheckObjectFromChan
(
cluster1UpdateChan
,
checkAll
(
secret1
))
assert
.
NoError
(
t
,
err
)
// Test add cluster
clusterWatch
.
Add
(
cluster2
)
...
...
@@ -183,13 +191,17 @@ func GetSecretFromChan(c chan runtime.Object) *apiv1.Secret {
// Wait till the store is updated with latest secret.
func
WaitForSecretStoreUpdate
(
store
util
.
FederatedReadOnlyStore
,
clusterName
,
key
string
,
desiredSecret
*
apiv1
.
Secret
,
timeout
time
.
Duration
)
error
{
retryInterval
:=
1
00
*
time
.
Millisecond
retryInterval
:=
2
00
*
time
.
Millisecond
err
:=
wait
.
PollImmediate
(
retryInterval
,
timeout
,
func
()
(
bool
,
error
)
{
obj
,
found
,
err
:=
store
.
GetByKey
(
clusterName
,
key
)
if
!
found
||
err
!=
nil
{
glog
.
Infof
(
"%s is not in the store"
,
key
)
return
false
,
err
}
equal
:=
secretsEqual
(
*
obj
.
(
*
apiv1
.
Secret
),
*
desiredSecret
)
if
!
equal
{
glog
.
Infof
(
"wrong content in the store expected:
\n
%v
\n
actual:
\n
%v
\n
"
,
*
desiredSecret
,
*
obj
.
(
*
apiv1
.
Secret
))
}
return
equal
,
err
})
return
err
...
...
federation/pkg/federation-controller/util/test/test_helper.go
View file @
3e61baf3
...
...
@@ -333,6 +333,6 @@ func MetaAndSpecCheckingFunction(expected runtime.Object) CheckingFunction {
if
util
.
ObjectMetaAndSpecEquivalent
(
obj
,
expected
)
{
return
nil
}
return
fmt
.
Errorf
(
"Object different expected=%#v
received=%#v"
,
expected
,
obj
)
return
fmt
.
Errorf
(
"Object different expected=%#v received=%#v"
,
expected
,
obj
)
}
}
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