From aa737c5691aeebf32e2a4b871f1d0a28af36a8b8 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Mon, 4 Sep 2023 09:53:06 +0200 Subject: [PATCH] keep depends_on config for services explicitly selected Signed-off-by: Nicolas De Loof --- types/project.go | 9 ++++++++- types/project_test.go | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/types/project.go b/types/project.go index 3d773c5d..713b2074 100644 --- a/types/project.go +++ b/types/project.go @@ -423,7 +423,14 @@ func (p *Project) ForServices(names []string, options ...DependencyOption) error if _, ok := set[s.Name]; ok { for _, option := range options { if option == IgnoreDependencies { - s.DependsOn = nil + // remove all dependencies but those implied by explicitly selected services + dependencies := s.DependsOn + for d := range dependencies { + if _, ok := set[d]; !ok { + delete(dependencies, d) + } + } + s.DependsOn = dependencies } } enabled = append(enabled, s) diff --git a/types/project_test.go b/types/project_test.go index d475e846..8bf7e899 100644 --- a/types/project_test.go +++ b/types/project_test.go @@ -115,6 +115,28 @@ func Test_ForServices(t *testing.T) { assert.Equal(t, p.DisabledServices[4].Name, "service_5") } +func Test_ForServicesIgnoreDependencies(t *testing.T) { + p := makeProject() + err := p.ForServices([]string{"service_2"}, IgnoreDependencies) + assert.NilError(t, err) + + assert.Equal(t, len(p.DisabledServices), 5) + service, err := p.GetService("service_2") + assert.NilError(t, err) + assert.Equal(t, len(service.DependsOn), 0) + + p = makeProject() + err = p.ForServices([]string{"service_2", "service_3"}, IgnoreDependencies) + assert.NilError(t, err) + + assert.Equal(t, len(p.DisabledServices), 4) + service, err = p.GetService("service_3") + assert.NilError(t, err) + assert.Equal(t, len(service.DependsOn), 1) + _, dependsOn := service.DependsOn["service_2"] + assert.Check(t, dependsOn) +} + func Test_ForServicesCycle(t *testing.T) { p := makeProject() p.Services[0].Links = []string{"service_2"}