backend_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Copyright 2020 Docker, Inc.
  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 aci
  14. import (
  15. "context"
  16. "testing"
  17. "github.com/docker/api/containers"
  18. "gotest.tools/v3/assert"
  19. )
  20. func TestGetContainerName(t *testing.T) {
  21. group, container := getGroupAndContainerName("docker1234")
  22. assert.Equal(t, group, "docker1234")
  23. assert.Equal(t, container, "docker1234")
  24. group, container = getGroupAndContainerName("compose_service1")
  25. assert.Equal(t, group, "compose")
  26. assert.Equal(t, container, "service1")
  27. group, container = getGroupAndContainerName("compose_stack_service1")
  28. assert.Equal(t, group, "compose_stack")
  29. assert.Equal(t, container, "service1")
  30. }
  31. func TestErrorMessageDeletingContainerFromComposeApplication(t *testing.T) {
  32. service := aciContainerService{}
  33. err := service.Delete(context.TODO(), "compose-app_service1", false)
  34. assert.Error(t, err, "cannot delete service \"service1\" from compose application \"compose-app\", you can delete the entire compose app with docker compose down --project-name compose-app")
  35. }
  36. func TestErrorMessageRunSingleContainerNameWithComposeSeparator(t *testing.T) {
  37. service := aciContainerService{}
  38. err := service.Run(context.TODO(), containers.ContainerConfig{ID: "container_name"})
  39. assert.Error(t, err, "invalid container name. ACI container name cannot include \"_\"")
  40. }
  41. func TestVerifyCommand(t *testing.T) {
  42. err := verifyExecCommand("command") // Command without an argument
  43. assert.NilError(t, err)
  44. err = verifyExecCommand("command argument") // Command with argument
  45. assert.Error(t, err, "ACI exec command does not accept arguments to the command. "+
  46. "Only the binary should be specified")
  47. }