forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out API defaulting from validation logic
Currently, the validation logic validates fields in an object and supply default values wherever applies. This change factors out defaulting to a set of defaulting callback functions for decoding (see kubernetes#1502 for more discussion). * This change is based on pull request 2587. * Most defaulting has been migrated to defaults.go where the defaulting functions are added. * validation_test.go and converter_test.go have been adapted to not testing the default values. * Fixed all tests with that create invalid objects with the absence of defaulting logic.
- Loading branch information
Showing
40 changed files
with
1,058 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright 2015 Google Inc. 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 v1beta1_test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1" | ||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" | ||
) | ||
|
||
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object { | ||
data, err := current.Codec.Encode(obj) | ||
if err != nil { | ||
t.Errorf("%v\n %#v", err, obj) | ||
return nil | ||
} | ||
obj2 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object) | ||
err = current.Codec.DecodeInto(data, obj2) | ||
if err != nil { | ||
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj) | ||
return nil | ||
} | ||
return obj2 | ||
} | ||
|
||
func TestSetDefaultService(t *testing.T) { | ||
svc := ¤t.Service{} | ||
obj2 := roundTrip(t, runtime.Object(svc)) | ||
svc2 := obj2.(*current.Service) | ||
if svc2.Protocol != current.ProtocolTCP { | ||
t.Errorf("Expected default protocol :%s, got: %s", current.ProtocolTCP, svc2.Protocol) | ||
} | ||
if svc2.SessionAffinity != current.AffinityTypeNone { | ||
t.Errorf("Expected default sesseion affinity type:%s, got: %s", current.AffinityTypeNone, svc2.SessionAffinity) | ||
} | ||
} | ||
|
||
func TestSetDefaulPodSpec(t *testing.T) { | ||
bp := ¤t.BoundPod{} | ||
obj2 := roundTrip(t, runtime.Object(bp)) | ||
bp2 := obj2.(*current.BoundPod) | ||
if bp2.Spec.DNSPolicy != current.DNSClusterFirst { | ||
t.Errorf("Expected default dns policy :%s, got: %s", current.DNSClusterFirst, bp2.Spec.DNSPolicy) | ||
} | ||
policy := bp2.Spec.RestartPolicy | ||
if policy.Never != nil || policy.OnFailure != nil || policy.Always == nil { | ||
t.Errorf("Expected only policy.Aways is set, got: %s", policy) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.