From 43c444e8900c87a8497b6494fba8c722231dd2e7 Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Thu, 15 Sep 2022 09:53:14 -0400 Subject: [PATCH] Add unit tests for `PrepareVolumes` Signed-off-by: Laura Brehm --- pkg/compose/create_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pkg/compose/create_test.go b/pkg/compose/create_test.go index 4b6140460..93d257956 100644 --- a/pkg/compose/create_test.go +++ b/pkg/compose/create_test.go @@ -96,6 +96,44 @@ func TestPrepareNetworkLabels(t *testing.T) { })) } +func TestPrepareVolumes(t *testing.T) { + t.Run("adds dependency condition if service depends on volume from another service", func(t *testing.T) { + project := composetypes.Project{ + Name: "myProject", + Services: []composetypes.ServiceConfig{ + { + Name: "aService", + VolumesFrom: []string{"anotherService"}, + }, + { + Name: "anotherService", + }, + }, + } + prepareVolumes(&project) + assert.Equal(t, project.Services[0].DependsOn["anotherService"].Condition, composetypes.ServiceConditionStarted) + }) + t.Run("doesn't overwrite existing dependency condition", func(t *testing.T) { + project := composetypes.Project{ + Name: "myProject", + Services: []composetypes.ServiceConfig{ + { + Name: "aService", + VolumesFrom: []string{"anotherService"}, + DependsOn: map[string]composetypes.ServiceDependency{ + "anotherService": {Condition: composetypes.ServiceConditionHealthy}, + }, + }, + { + Name: "anotherService", + }, + }, + } + prepareVolumes(&project) + assert.Equal(t, project.Services[0].DependsOn["anotherService"].Condition, composetypes.ServiceConditionHealthy) + }) +} + func TestBuildContainerMountOptions(t *testing.T) { project := composetypes.Project{ Name: "myProject",