docker_sandbox_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. Copyright 2016 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 dockershim
  14. import (
  15. "testing"
  16. dockertypes "github.com/docker/engine-api/types"
  17. runtimeApi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
  18. )
  19. func TestCreateSandbox(t *testing.T) {
  20. ds, fakeDocker := newTestDockerSevice()
  21. name := "FOO"
  22. namespace := "BAR"
  23. uid := "1"
  24. config := &runtimeApi.PodSandboxConfig{
  25. Metadata: &runtimeApi.PodSandboxMetadata{
  26. Name: &name,
  27. Namespace: &namespace,
  28. Uid: &uid,
  29. },
  30. }
  31. id, err := ds.CreatePodSandbox(config)
  32. if err != nil {
  33. t.Errorf("Unexpected error: %v", err)
  34. }
  35. if err := fakeDocker.AssertStarted([]string{id}); err != nil {
  36. t.Errorf("%v", err)
  37. }
  38. // List running containers and verify that there is one (and only one)
  39. // running container that we just created.
  40. containers, err := fakeDocker.ListContainers(dockertypes.ContainerListOptions{All: false})
  41. if err != nil {
  42. t.Errorf("Unexpected error: %v", err)
  43. }
  44. if len(containers) != 1 {
  45. t.Errorf("More than one running containers: %+v", containers)
  46. }
  47. if containers[0].ID != id {
  48. t.Errorf("Expected id %q, got %v", id, containers[0].ID)
  49. }
  50. }