backend_test.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 azure
  14. import (
  15. "context"
  16. "testing"
  17. "github.com/docker/api/containers"
  18. "github.com/stretchr/testify/suite"
  19. . "github.com/onsi/gomega"
  20. )
  21. type BackendSuiteTest struct {
  22. suite.Suite
  23. }
  24. func (suite *BackendSuiteTest) TestGetContainerName() {
  25. group, container := getGroupAndContainerName("docker1234")
  26. Expect(group).To(Equal("docker1234"))
  27. Expect(container).To(Equal(singleContainerName))
  28. group, container = getGroupAndContainerName("compose_service1")
  29. Expect(group).To(Equal("compose"))
  30. Expect(container).To(Equal("service1"))
  31. group, container = getGroupAndContainerName("compose_stack_service1")
  32. Expect(group).To(Equal("compose_stack"))
  33. Expect(container).To(Equal("service1"))
  34. }
  35. func (suite *BackendSuiteTest) TestErrorMessageDeletingContainerFromComposeApplication() {
  36. service := aciContainerService{}
  37. err := service.Delete(context.TODO(), "compose-app_service1", false)
  38. Expect(err).NotTo(BeNil())
  39. Expect(err.Error()).To(Equal("cannot delete service \"service1\" from compose application \"compose-app\", you can delete the entire compose app with docker compose down --project-name compose-app"))
  40. }
  41. func (suite *BackendSuiteTest) TestErrorMessageRunSingleContainerNameWithComposeSeparator() {
  42. service := aciContainerService{}
  43. err := service.Run(context.TODO(), containers.ContainerConfig{ID: "container_name"})
  44. Expect(err).NotTo(BeNil())
  45. Expect(err.Error()).To(Equal("invalid container name. ACI container name cannot include \"_\""))
  46. }
  47. func (suite *BackendSuiteTest) TestVerifyCommand() {
  48. err := verifyExecCommand("command") // Command without an argument
  49. Expect(err).To(BeNil())
  50. err = verifyExecCommand("command argument") // Command with argument
  51. Expect(err).NotTo(BeNil())
  52. Expect(err.Error()).To(Equal("ACI exec command does not accept arguments to the command. " +
  53. "Only the binary should be specified"))
  54. }
  55. func TestBackendSuite(t *testing.T) {
  56. RegisterTestingT(t)
  57. suite.Run(t, new(BackendSuiteTest))
  58. }