MCPcopy Create free account
hub / github.com/docker/compose / TestCombinedConfigFiles

Function TestCombinedConfigFiles

pkg/compose/ls_test.go:71–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func TestCombinedConfigFiles(t *testing.T) {
72 containersByLabel := map[string][]container.Summary{
73 "project1": {
74 {
75 ID: "service1",
76 State: "running",
77 Labels: map[string]string{api.ProjectLabel: "project1", api.ConfigFilesLabel: "/home/docker-compose.yaml"},
78 },
79 {
80 ID: "service2",
81 State: "running",
82 Labels: map[string]string{api.ProjectLabel: "project1", api.ConfigFilesLabel: "/home/docker-compose.yaml"},
83 },
84 },
85 "project2": {
86 {
87 ID: "service3",
88 State: "running",
89 Labels: map[string]string{api.ProjectLabel: "project2", api.ConfigFilesLabel: "/home/project2-docker-compose.yaml"},
90 },
91 },
92 "project3": {
93 {
94 ID: "service4",
95 State: "running",
96 Labels: map[string]string{api.ProjectLabel: "project3"},
97 },
98 },
99 }
100
101 testData := map[string]struct {
102 ConfigFiles string
103 Error error
104 }{
105 "project1": {ConfigFiles: "/home/docker-compose.yaml", Error: nil},
106 "project2": {ConfigFiles: "/home/project2-docker-compose.yaml", Error: nil},
107 "project3": {ConfigFiles: "", Error: fmt.Errorf("no label %q set on container %q of compose project", api.ConfigFilesLabel, "service4")},
108 }
109
110 for project, containers := range containersByLabel {
111 configFiles, err := combinedConfigFiles(containers)
112
113 expected := testData[project]
114
115 if expected.Error != nil {
116 assert.Error(t, err, expected.Error.Error())
117 } else {
118 assert.Equal(t, err, expected.Error)
119 }
120 assert.Equal(t, configFiles, expected.ConfigFiles)
121 }
122}

Callers

nothing calls this directly

Calls 2

combinedConfigFilesFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected