project_test.go 1.6 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 compose
  14. import (
  15. "os"
  16. "testing"
  17. . "github.com/onsi/gomega"
  18. "github.com/stretchr/testify/suite"
  19. )
  20. type ComposeTest struct {
  21. suite.Suite
  22. }
  23. func (suite *ComposeTest) TestParseComposeFile() {
  24. files := []string{"../tests/composefiles/aci-demo/aci_demo_port.yaml"}
  25. config, err := parseConfigs(files)
  26. Expect(err).To(BeNil())
  27. services := config[0].Config["services"].(map[string]interface{})
  28. Expect(len(services)).To(Equal(3))
  29. }
  30. func (suite *ComposeTest) TestParseComposeStdin() {
  31. files := []string{"-"}
  32. f, err := os.Open("../tests/composefiles/aci-demo/aci_demo_port.yaml")
  33. Expect(err).To(BeNil())
  34. defer func() {
  35. err := f.Close()
  36. Expect(err).To(BeNil())
  37. }()
  38. oldStdin := os.Stdin
  39. defer func() { os.Stdin = oldStdin }() // Restore original Stdin
  40. os.Stdin = f
  41. config, err := parseConfigs(files)
  42. Expect(err).To(BeNil())
  43. services := config[0].Config["services"].(map[string]interface{})
  44. Expect(len(services)).To(Equal(3))
  45. }
  46. func TestComposeProject(t *testing.T) {
  47. RegisterTestingT(t)
  48. suite.Run(t, new(ComposeTest))
  49. }