mirror of https://github.com/k3s-io/k3s
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
/*
|
|
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 container
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
|
)
|
|
|
|
func TestFieldPath(t *testing.T) {
|
|
pod := &api.Pod{Spec: api.PodSpec{Containers: []api.Container{
|
|
{Name: "foo"},
|
|
{Name: "bar"},
|
|
{Name: ""},
|
|
{Name: "baz"},
|
|
}}}
|
|
table := map[string]struct {
|
|
pod *api.Pod
|
|
container *api.Container
|
|
path string
|
|
success bool
|
|
}{
|
|
"basic": {pod, &api.Container{Name: "foo"}, "spec.containers{foo}", true},
|
|
"basic2": {pod, &api.Container{Name: "baz"}, "spec.containers{baz}", true},
|
|
"emptyName": {pod, &api.Container{Name: ""}, "spec.containers[2]", true},
|
|
"basicSamePointer": {pod, &pod.Spec.Containers[0], "spec.containers{foo}", true},
|
|
"missing": {pod, &api.Container{Name: "qux"}, "", false},
|
|
}
|
|
|
|
for name, item := range table {
|
|
res, err := fieldPath(item.pod, item.container)
|
|
if item.success == false {
|
|
if err == nil {
|
|
t.Errorf("%v: unexpected non-error", name)
|
|
}
|
|
continue
|
|
}
|
|
if err != nil {
|
|
t.Errorf("%v: unexpected error: %v", name, err)
|
|
continue
|
|
}
|
|
if e, a := item.path, res; e != a {
|
|
t.Errorf("%v: wanted %v, got %v", name, e, a)
|
|
}
|
|
}
|
|
}
|