mirror_client_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package pod
  14. import (
  15. "testing"
  16. kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
  17. )
  18. func TestParsePodFullName(t *testing.T) {
  19. type nameTuple struct {
  20. Name string
  21. Namespace string
  22. }
  23. successfulCases := map[string]nameTuple{
  24. "bar_foo": {Name: "bar", Namespace: "foo"},
  25. "bar.org_foo.com": {Name: "bar.org", Namespace: "foo.com"},
  26. "bar-bar_foo": {Name: "bar-bar", Namespace: "foo"},
  27. }
  28. failedCases := []string{"barfoo", "bar_foo_foo", "", "bar_", "_foo"}
  29. for podFullName, expected := range successfulCases {
  30. name, namespace, err := kubecontainer.ParsePodFullName(podFullName)
  31. if err != nil {
  32. t.Errorf("unexpected error when parsing the full name: %v", err)
  33. continue
  34. }
  35. if name != expected.Name || namespace != expected.Namespace {
  36. t.Errorf("expected name %q, namespace %q; got name %q, namespace %q",
  37. expected.Name, expected.Namespace, name, namespace)
  38. }
  39. }
  40. for _, podFullName := range failedCases {
  41. _, _, err := kubecontainer.ParsePodFullName(podFullName)
  42. if err == nil {
  43. t.Errorf("expected error when parsing the full name, got none")
  44. }
  45. }
  46. }