Add custom conversion function system.
As an example, demonstrate how Env.Key's deprecation ought to work.
This commit is contained in:
@@ -17,9 +17,11 @@ limitations under the License.
|
||||
package api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
@@ -105,16 +107,6 @@ func TestValidateEnv(t *testing.T) {
|
||||
t.Errorf("expected success: %v", errs)
|
||||
}
|
||||
|
||||
nonCanonicalCase := []EnvVar{
|
||||
{Key: "EV"},
|
||||
}
|
||||
if errs := validateEnv(nonCanonicalCase); len(errs) != 0 {
|
||||
t.Errorf("expected success: %v", errs)
|
||||
}
|
||||
if nonCanonicalCase[0].Name != "EV" || nonCanonicalCase[0].Value != "" {
|
||||
t.Errorf("expected default values: %+v", nonCanonicalCase[0])
|
||||
}
|
||||
|
||||
errorCases := map[string][]EnvVar{
|
||||
"zero-length name": {{Name: ""}},
|
||||
"name not a C identifier": {{Name: "a.b.c"}},
|
||||
@@ -126,6 +118,27 @@ func TestValidateEnv(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnvConversion(t *testing.T) {
|
||||
nonCanonical := []v1beta1.EnvVar{
|
||||
{Key: "EV"},
|
||||
{Key: "EV", Name: "EX"},
|
||||
}
|
||||
cannonical := []EnvVar{
|
||||
{Name: "EV"},
|
||||
{Name: "EX"},
|
||||
}
|
||||
for i := range nonCanonical {
|
||||
var got EnvVar
|
||||
err := Convert(&nonCanonical[i], &got)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if e, a := cannonical[i], got; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("expected %v, got %v", e, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateVolumeMounts(t *testing.T) {
|
||||
volumes := util.NewStringSet("abc", "123", "abc-123")
|
||||
|
||||
@@ -225,7 +238,7 @@ func TestValidateManifest(t *testing.T) {
|
||||
Env: []EnvVar{
|
||||
{Name: "ev1", Value: "val1"},
|
||||
{Name: "ev2", Value: "val2"},
|
||||
{Key: "EV3", Value: "val3"},
|
||||
{Name: "EV3", Value: "val3"},
|
||||
},
|
||||
VolumeMounts: []VolumeMount{
|
||||
{Name: "vol1", MountPath: "/foo"},
|
||||
|
||||
Reference in New Issue
Block a user