Commit e4c910a3 authored by Dawn Chen's avatar Dawn Chen

Merge pull request #15362 from wojtek-t/refactor_test_objects

Refactor test objects to a separate package
parents 0f22551e 3d88a63b
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package testing
import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
)
type Simple struct {
unversioned.TypeMeta `json:",inline"`
api.ObjectMeta `json:"metadata"`
Other string `json:"other,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
func (*Simple) IsAnAPIObject() {}
type SimpleRoot struct {
unversioned.TypeMeta `json:",inline"`
api.ObjectMeta `json:"metadata"`
Other string `json:"other,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
func (*SimpleRoot) IsAnAPIObject() {}
type SimpleGetOptions struct {
unversioned.TypeMeta `json:",inline"`
Param1 string `json:"param1"`
Param2 string `json:"param2"`
Path string `json:"atAPath"`
}
func (SimpleGetOptions) SwaggerDoc() map[string]string {
return map[string]string{
"param1": "description for param1",
"param2": "description for param2",
}
}
func (*SimpleGetOptions) IsAnAPIObject() {}
type SimpleList struct {
unversioned.TypeMeta `json:",inline"`
unversioned.ListMeta `json:"metadata,inline"`
Items []Simple `json:"items,omitempty"`
}
func (*SimpleList) IsAnAPIObject() {}
...@@ -30,6 +30,7 @@ import ( ...@@ -30,6 +30,7 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/rest" "k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/api/unversioned"
apiservertesting "k8s.io/kubernetes/pkg/apiserver/testing"
"k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/runtime"
...@@ -47,9 +48,9 @@ var watchTestTable = []struct { ...@@ -47,9 +48,9 @@ var watchTestTable = []struct {
t watch.EventType t watch.EventType
obj runtime.Object obj runtime.Object
}{ }{
{watch.Added, &Simple{ObjectMeta: api.ObjectMeta{Name: "foo"}}}, {watch.Added, &apiservertesting.Simple{ObjectMeta: api.ObjectMeta{Name: "foo"}}},
{watch.Modified, &Simple{ObjectMeta: api.ObjectMeta{Name: "bar"}}}, {watch.Modified, &apiservertesting.Simple{ObjectMeta: api.ObjectMeta{Name: "bar"}}},
{watch.Deleted, &Simple{ObjectMeta: api.ObjectMeta{Name: "bar"}}}, {watch.Deleted, &apiservertesting.Simple{ObjectMeta: api.ObjectMeta{Name: "bar"}}},
} }
func TestWatchWebsocket(t *testing.T) { func TestWatchWebsocket(t *testing.T) {
...@@ -363,7 +364,7 @@ func TestWatchHTTPTimeout(t *testing.T) { ...@@ -363,7 +364,7 @@ func TestWatchHTTPTimeout(t *testing.T) {
req, _ := http.NewRequest("GET", dest.String(), nil) req, _ := http.NewRequest("GET", dest.String(), nil)
client := http.Client{} client := http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
watcher.Add(&Simple{TypeMeta: unversioned.TypeMeta{APIVersion: newVersion}}) watcher.Add(&apiservertesting.Simple{TypeMeta: unversioned.TypeMeta{APIVersion: newVersion}})
// Make sure we can actually watch an endpoint // Make sure we can actually watch an endpoint
decoder := json.NewDecoder(resp.Body) decoder := json.NewDecoder(resp.Body)
......
...@@ -31,6 +31,7 @@ import ( ...@@ -31,6 +31,7 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/extensions"
kubectltesting "k8s.io/kubernetes/pkg/kubectl/testing"
"k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/sets" "k8s.io/kubernetes/pkg/util/sets"
...@@ -38,23 +39,12 @@ import ( ...@@ -38,23 +39,12 @@ import (
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
) )
type testStruct struct {
unversioned.TypeMeta `json:",inline"`
api.ObjectMeta `json:"metadata,omitempty"`
Key string `json:"Key"`
Map map[string]int `json:"Map"`
StringList []string `json:"StringList"`
IntList []int `json:"IntList"`
}
func (ts *testStruct) IsAnAPIObject() {}
func init() { func init() {
api.Scheme.AddKnownTypes("", &testStruct{}) api.Scheme.AddKnownTypes("", &kubectltesting.TestStruct{})
api.Scheme.AddKnownTypes(testapi.Default.Version(), &testStruct{}) api.Scheme.AddKnownTypes(testapi.Default.Version(), &kubectltesting.TestStruct{})
} }
var testData = testStruct{ var testData = kubectltesting.TestStruct{
Key: "testValue", Key: "testValue",
Map: map[string]int{"TestSubkey": 1}, Map: map[string]int{"TestSubkey": 1},
StringList: []string{"a", "b", "c"}, StringList: []string{"a", "b", "c"},
...@@ -62,13 +52,13 @@ var testData = testStruct{ ...@@ -62,13 +52,13 @@ var testData = testStruct{
} }
func TestVersionedPrinter(t *testing.T) { func TestVersionedPrinter(t *testing.T) {
original := &testStruct{Key: "value"} original := &kubectltesting.TestStruct{Key: "value"}
p := NewVersionedPrinter( p := NewVersionedPrinter(
ResourcePrinterFunc(func(obj runtime.Object, w io.Writer) error { ResourcePrinterFunc(func(obj runtime.Object, w io.Writer) error {
if obj == original { if obj == original {
t.Fatalf("object should not be identical: %#v", obj) t.Fatalf("object should not be identical: %#v", obj)
} }
if obj.(*testStruct).Key != "value" { if obj.(*kubectltesting.TestStruct).Key != "value" {
t.Fatalf("object was not converted: %#v", obj) t.Fatalf("object was not converted: %#v", obj)
} }
return nil return nil
...@@ -177,14 +167,14 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data ...@@ -177,14 +167,14 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
var poutput testStruct var poutput kubectltesting.TestStruct
// Verify that given function runs without error. // Verify that given function runs without error.
err = unmarshalFunc(buf.Bytes(), &poutput) err = unmarshalFunc(buf.Bytes(), &poutput)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
// Use real decode function to undo the versioning process. // Use real decode function to undo the versioning process.
poutput = testStruct{} poutput = kubectltesting.TestStruct{}
err = runtime.YAMLDecoder(testapi.Default.Codec()).DecodeInto(buf.Bytes(), &poutput) err = runtime.YAMLDecoder(testapi.Default.Codec()).DecodeInto(buf.Bytes(), &poutput)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
......
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package testing
import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
)
type TestStruct struct {
unversioned.TypeMeta `json:",inline"`
api.ObjectMeta `json:"metadata,omitempty"`
Key string `json:"Key"`
Map map[string]int `json:"Map"`
StringList []string `json:"StringList"`
IntList []int `json:"IntList"`
}
func (ts *TestStruct) IsAnAPIObject() {}
...@@ -22,17 +22,18 @@ import ( ...@@ -22,17 +22,18 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/api/unversioned"
storagetesting "k8s.io/kubernetes/pkg/storage/testing"
) )
func TestObjectVersioner(t *testing.T) { func TestObjectVersioner(t *testing.T) {
v := APIObjectVersioner{} v := APIObjectVersioner{}
if ver, err := v.ObjectResourceVersion(&TestResource{ObjectMeta: api.ObjectMeta{ResourceVersion: "5"}}); err != nil || ver != 5 { if ver, err := v.ObjectResourceVersion(&storagetesting.TestResource{ObjectMeta: api.ObjectMeta{ResourceVersion: "5"}}); err != nil || ver != 5 {
t.Errorf("unexpected version: %d %v", ver, err) t.Errorf("unexpected version: %d %v", ver, err)
} }
if ver, err := v.ObjectResourceVersion(&TestResource{ObjectMeta: api.ObjectMeta{ResourceVersion: "a"}}); err == nil || ver != 0 { if ver, err := v.ObjectResourceVersion(&storagetesting.TestResource{ObjectMeta: api.ObjectMeta{ResourceVersion: "a"}}); err == nil || ver != 0 {
t.Errorf("unexpected version: %d %v", ver, err) t.Errorf("unexpected version: %d %v", ver, err)
} }
obj := &TestResource{ObjectMeta: api.ObjectMeta{ResourceVersion: "a"}} obj := &storagetesting.TestResource{ObjectMeta: api.ObjectMeta{ResourceVersion: "a"}}
if err := v.UpdateObject(obj, nil, 5); err != nil { if err := v.UpdateObject(obj, nil, 5); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -40,7 +41,7 @@ func TestObjectVersioner(t *testing.T) { ...@@ -40,7 +41,7 @@ func TestObjectVersioner(t *testing.T) {
t.Errorf("unexpected resource version: %#v", obj) t.Errorf("unexpected resource version: %#v", obj)
} }
now := unversioned.Time{Time: time.Now()} now := unversioned.Time{Time: time.Now()}
obj = &TestResource{ObjectMeta: api.ObjectMeta{ResourceVersion: "a"}} obj = &storagetesting.TestResource{ObjectMeta: api.ObjectMeta{ResourceVersion: "a"}}
if err := v.UpdateObject(obj, &now.Time, 5); err != nil { if err := v.UpdateObject(obj, &now.Time, 5); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
......
...@@ -40,30 +40,23 @@ import ( ...@@ -40,30 +40,23 @@ import (
"k8s.io/kubernetes/pkg/conversion" "k8s.io/kubernetes/pkg/conversion"
"k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage" "k8s.io/kubernetes/pkg/storage"
storagetesting "k8s.io/kubernetes/pkg/storage/testing"
"k8s.io/kubernetes/pkg/tools" "k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/tools/etcdtest" "k8s.io/kubernetes/pkg/tools/etcdtest"
) )
const validEtcdVersion = "etcd 2.0.9" const validEtcdVersion = "etcd 2.0.9"
type TestResource struct {
unversioned.TypeMeta `json:",inline"`
api.ObjectMeta `json:"metadata"`
Value int `json:"value"`
}
func (*TestResource) IsAnAPIObject() {}
var scheme *runtime.Scheme var scheme *runtime.Scheme
var codec runtime.Codec var codec runtime.Codec
func init() { func init() {
scheme = runtime.NewScheme() scheme = runtime.NewScheme()
scheme.AddKnownTypes("", &TestResource{}) scheme.AddKnownTypes("", &storagetesting.TestResource{})
scheme.AddKnownTypes(testapi.Default.Version(), &TestResource{}) scheme.AddKnownTypes(testapi.Default.Version(), &storagetesting.TestResource{})
codec = runtime.CodecFor(scheme, testapi.Default.Version()) codec = runtime.CodecFor(scheme, testapi.Default.Version())
scheme.AddConversionFuncs( scheme.AddConversionFuncs(
func(in *TestResource, out *TestResource, s conversion.Scope) error { func(in *storagetesting.TestResource, out *storagetesting.TestResource, s conversion.Scope) error {
*out = *in *out = *in
return nil return nil
}, },
...@@ -568,8 +561,8 @@ func TestGuaranteedUpdate(t *testing.T) { ...@@ -568,8 +561,8 @@ func TestGuaranteedUpdate(t *testing.T) {
// Create a new node. // Create a new node.
fakeClient.ExpectNotFoundGet(key) fakeClient.ExpectNotFoundGet(key)
obj := &TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 1} obj := &storagetesting.TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 1}
err := helper.GuaranteedUpdate(context.TODO(), "/some/key", &TestResource{}, true, storage.SimpleUpdate(func(in runtime.Object) (runtime.Object, error) { err := helper.GuaranteedUpdate(context.TODO(), "/some/key", &storagetesting.TestResource{}, true, storage.SimpleUpdate(func(in runtime.Object) (runtime.Object, error) {
return obj, nil return obj, nil
})) }))
if err != nil { if err != nil {
...@@ -587,11 +580,11 @@ func TestGuaranteedUpdate(t *testing.T) { ...@@ -587,11 +580,11 @@ func TestGuaranteedUpdate(t *testing.T) {
// Update an existing node. // Update an existing node.
callbackCalled := false callbackCalled := false
objUpdate := &TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 2} objUpdate := &storagetesting.TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 2}
err = helper.GuaranteedUpdate(context.TODO(), "/some/key", &TestResource{}, true, storage.SimpleUpdate(func(in runtime.Object) (runtime.Object, error) { err = helper.GuaranteedUpdate(context.TODO(), "/some/key", &storagetesting.TestResource{}, true, storage.SimpleUpdate(func(in runtime.Object) (runtime.Object, error) {
callbackCalled = true callbackCalled = true
if in.(*TestResource).Value != 1 { if in.(*storagetesting.TestResource).Value != 1 {
t.Errorf("Callback input was not current set value") t.Errorf("Callback input was not current set value")
} }
...@@ -623,8 +616,8 @@ func TestGuaranteedUpdateTTL(t *testing.T) { ...@@ -623,8 +616,8 @@ func TestGuaranteedUpdateTTL(t *testing.T) {
// Create a new node. // Create a new node.
fakeClient.ExpectNotFoundGet(key) fakeClient.ExpectNotFoundGet(key)
obj := &TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 1} obj := &storagetesting.TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 1}
err := helper.GuaranteedUpdate(context.TODO(), "/some/key", &TestResource{}, true, func(in runtime.Object, res storage.ResponseMeta) (runtime.Object, *uint64, error) { err := helper.GuaranteedUpdate(context.TODO(), "/some/key", &storagetesting.TestResource{}, true, func(in runtime.Object, res storage.ResponseMeta) (runtime.Object, *uint64, error) {
if res.TTL != 0 { if res.TTL != 0 {
t.Fatalf("unexpected response meta: %#v", res) t.Fatalf("unexpected response meta: %#v", res)
} }
...@@ -649,14 +642,14 @@ func TestGuaranteedUpdateTTL(t *testing.T) { ...@@ -649,14 +642,14 @@ func TestGuaranteedUpdateTTL(t *testing.T) {
// Update an existing node. // Update an existing node.
callbackCalled := false callbackCalled := false
objUpdate := &TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 2} objUpdate := &storagetesting.TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 2}
err = helper.GuaranteedUpdate(context.TODO(), "/some/key", &TestResource{}, true, func(in runtime.Object, res storage.ResponseMeta) (runtime.Object, *uint64, error) { err = helper.GuaranteedUpdate(context.TODO(), "/some/key", &storagetesting.TestResource{}, true, func(in runtime.Object, res storage.ResponseMeta) (runtime.Object, *uint64, error) {
if res.TTL != 10 { if res.TTL != 10 {
t.Fatalf("unexpected response meta: %#v", res) t.Fatalf("unexpected response meta: %#v", res)
} }
callbackCalled = true callbackCalled = true
if in.(*TestResource).Value != 1 { if in.(*storagetesting.TestResource).Value != 1 {
t.Errorf("Callback input was not current set value") t.Errorf("Callback input was not current set value")
} }
...@@ -681,14 +674,14 @@ func TestGuaranteedUpdateTTL(t *testing.T) { ...@@ -681,14 +674,14 @@ func TestGuaranteedUpdateTTL(t *testing.T) {
// Update an existing node and change ttl // Update an existing node and change ttl
callbackCalled = false callbackCalled = false
objUpdate = &TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 3} objUpdate = &storagetesting.TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 3}
err = helper.GuaranteedUpdate(context.TODO(), "/some/key", &TestResource{}, true, func(in runtime.Object, res storage.ResponseMeta) (runtime.Object, *uint64, error) { err = helper.GuaranteedUpdate(context.TODO(), "/some/key", &storagetesting.TestResource{}, true, func(in runtime.Object, res storage.ResponseMeta) (runtime.Object, *uint64, error) {
if res.TTL != 10 { if res.TTL != 10 {
t.Fatalf("unexpected response meta: %#v", res) t.Fatalf("unexpected response meta: %#v", res)
} }
callbackCalled = true callbackCalled = true
if in.(*TestResource).Value != 2 { if in.(*storagetesting.TestResource).Value != 2 {
t.Errorf("Callback input was not current set value") t.Errorf("Callback input was not current set value")
} }
...@@ -724,8 +717,8 @@ func TestGuaranteedUpdateNoChange(t *testing.T) { ...@@ -724,8 +717,8 @@ func TestGuaranteedUpdateNoChange(t *testing.T) {
// Create a new node. // Create a new node.
fakeClient.ExpectNotFoundGet(key) fakeClient.ExpectNotFoundGet(key)
obj := &TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 1} obj := &storagetesting.TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 1}
err := helper.GuaranteedUpdate(context.TODO(), "/some/key", &TestResource{}, true, storage.SimpleUpdate(func(in runtime.Object) (runtime.Object, error) { err := helper.GuaranteedUpdate(context.TODO(), "/some/key", &storagetesting.TestResource{}, true, storage.SimpleUpdate(func(in runtime.Object) (runtime.Object, error) {
return obj, nil return obj, nil
})) }))
if err != nil { if err != nil {
...@@ -734,8 +727,8 @@ func TestGuaranteedUpdateNoChange(t *testing.T) { ...@@ -734,8 +727,8 @@ func TestGuaranteedUpdateNoChange(t *testing.T) {
// Update an existing node with the same data // Update an existing node with the same data
callbackCalled := false callbackCalled := false
objUpdate := &TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 1} objUpdate := &storagetesting.TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 1}
err = helper.GuaranteedUpdate(context.TODO(), "/some/key", &TestResource{}, true, storage.SimpleUpdate(func(in runtime.Object) (runtime.Object, error) { err = helper.GuaranteedUpdate(context.TODO(), "/some/key", &storagetesting.TestResource{}, true, storage.SimpleUpdate(func(in runtime.Object) (runtime.Object, error) {
fakeClient.Err = errors.New("should not be called") fakeClient.Err = errors.New("should not be called")
callbackCalled = true callbackCalled = true
return objUpdate, nil return objUpdate, nil
...@@ -756,20 +749,20 @@ func TestGuaranteedUpdateKeyNotFound(t *testing.T) { ...@@ -756,20 +749,20 @@ func TestGuaranteedUpdateKeyNotFound(t *testing.T) {
// Create a new node. // Create a new node.
fakeClient.ExpectNotFoundGet(key) fakeClient.ExpectNotFoundGet(key)
obj := &TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 1} obj := &storagetesting.TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: 1}
f := storage.SimpleUpdate(func(in runtime.Object) (runtime.Object, error) { f := storage.SimpleUpdate(func(in runtime.Object) (runtime.Object, error) {
return obj, nil return obj, nil
}) })
ignoreNotFound := false ignoreNotFound := false
err := helper.GuaranteedUpdate(context.TODO(), "/some/key", &TestResource{}, ignoreNotFound, f) err := helper.GuaranteedUpdate(context.TODO(), "/some/key", &storagetesting.TestResource{}, ignoreNotFound, f)
if err == nil { if err == nil {
t.Errorf("Expected error for key not found.") t.Errorf("Expected error for key not found.")
} }
ignoreNotFound = true ignoreNotFound = true
err = helper.GuaranteedUpdate(context.TODO(), "/some/key", &TestResource{}, ignoreNotFound, f) err = helper.GuaranteedUpdate(context.TODO(), "/some/key", &storagetesting.TestResource{}, ignoreNotFound, f)
if err != nil { if err != nil {
t.Errorf("Unexpected error %v.", err) t.Errorf("Unexpected error %v.", err)
} }
...@@ -790,12 +783,12 @@ func TestGuaranteedUpdate_CreateCollision(t *testing.T) { ...@@ -790,12 +783,12 @@ func TestGuaranteedUpdate_CreateCollision(t *testing.T) {
wgForceCollision.Add(concurrency) wgForceCollision.Add(concurrency)
for i := 0; i < concurrency; i++ { for i := 0; i < concurrency; i++ {
// Increment TestResource.Value by 1 // Increment storagetesting.TestResource.Value by 1
go func() { go func() {
defer wgDone.Done() defer wgDone.Done()
firstCall := true firstCall := true
err := helper.GuaranteedUpdate(context.TODO(), "/some/key", &TestResource{}, true, storage.SimpleUpdate(func(in runtime.Object) (runtime.Object, error) { err := helper.GuaranteedUpdate(context.TODO(), "/some/key", &storagetesting.TestResource{}, true, storage.SimpleUpdate(func(in runtime.Object) (runtime.Object, error) {
defer func() { firstCall = false }() defer func() { firstCall = false }()
if firstCall { if firstCall {
...@@ -804,8 +797,8 @@ func TestGuaranteedUpdate_CreateCollision(t *testing.T) { ...@@ -804,8 +797,8 @@ func TestGuaranteedUpdate_CreateCollision(t *testing.T) {
wgForceCollision.Wait() wgForceCollision.Wait()
} }
currValue := in.(*TestResource).Value currValue := in.(*storagetesting.TestResource).Value
obj := &TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: currValue + 1} obj := &storagetesting.TestResource{ObjectMeta: api.ObjectMeta{Name: "foo"}, Value: currValue + 1}
return obj, nil return obj, nil
})) }))
if err != nil { if err != nil {
...@@ -815,9 +808,9 @@ func TestGuaranteedUpdate_CreateCollision(t *testing.T) { ...@@ -815,9 +808,9 @@ func TestGuaranteedUpdate_CreateCollision(t *testing.T) {
} }
wgDone.Wait() wgDone.Wait()
// Check that stored TestResource has received all updates. // Check that stored storagetesting.TestResource has received all updates.
body := fakeClient.Data[key].R.Node.Value body := fakeClient.Data[key].R.Node.Value
stored := &TestResource{} stored := &storagetesting.TestResource{}
if err := codec.DecodeInto([]byte(body), stored); err != nil { if err := codec.DecodeInto([]byte(body), stored); err != nil {
t.Errorf("Error decoding stored value: %v", body) t.Errorf("Error decoding stored value: %v", body)
} }
......
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package testing
import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
)
type TestResource struct {
unversioned.TypeMeta `json:",inline"`
api.ObjectMeta `json:"metadata"`
Value int `json:"value"`
}
func (*TestResource) IsAnAPIObject() {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment