Skip to content

Commit

Permalink
Merge pull request #454 from ndeloof/depends_on_filter
Browse files Browse the repository at this point in the history
keep depends_on config for services explicitly selected
  • Loading branch information
glours authored Sep 4, 2023
2 parents 9325945 + aa737c5 commit c8ee8d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion types/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions types/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit c8ee8d4

Please sign in to comment.