dependencies_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. Copyright 2020 Docker Compose CLI 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 compose
  14. import (
  15. "context"
  16. "testing"
  17. "github.com/compose-spec/compose-go/types"
  18. "gotest.tools/v3/assert"
  19. )
  20. var project = types.Project{
  21. Services: []types.ServiceConfig{
  22. {
  23. Name: "test1",
  24. DependsOn: map[string]types.ServiceDependency{
  25. "test2": {},
  26. },
  27. },
  28. {
  29. Name: "test2",
  30. DependsOn: map[string]types.ServiceDependency{
  31. "test3": {},
  32. },
  33. },
  34. {
  35. Name: "test3",
  36. },
  37. },
  38. }
  39. func TestInDependencyUpCommandOrder(t *testing.T) {
  40. order := make(chan string)
  41. //nolint:errcheck, unparam
  42. go InDependencyOrder(context.TODO(), &project, func(ctx context.Context, config string) error {
  43. order <- config
  44. return nil
  45. })
  46. assert.Equal(t, <-order, "test3")
  47. assert.Equal(t, <-order, "test2")
  48. assert.Equal(t, <-order, "test1")
  49. }
  50. func TestInDependencyReverseDownCommandOrder(t *testing.T) {
  51. order := make(chan string)
  52. //nolint:errcheck, unparam
  53. go InReverseDependencyOrder(context.TODO(), &project, func(ctx context.Context, config string) error {
  54. order <- config
  55. return nil
  56. })
  57. assert.Equal(t, <-order, "test1")
  58. assert.Equal(t, <-order, "test2")
  59. assert.Equal(t, <-order, "test3")
  60. }