MCPcopy
hub / github.com/docker/compose / TestLoadProject_ProjectNameInference

Function TestLoadProject_ProjectNameInference

pkg/compose/loader_test.go:225–258  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

223}
224
225func TestLoadProject_ProjectNameInference(t *testing.T) {
226 tmpDir := t.TempDir()
227 composeFile := filepath.Join(tmpDir, "compose.yaml")
228 composeContent := `
229services:
230 web:
231 image: nginx:latest
232`
233 err := os.WriteFile(composeFile, []byte(composeContent), 0o644)
234 assert.NilError(t, err)
235
236 service, err := NewComposeService(nil)
237 assert.NilError(t, err)
238
239 // Without explicit project name
240 t.Run("InferredName", func(t *testing.T) {
241 project, err := service.LoadProject(t.Context(), api.ProjectLoadOptions{
242 ConfigPaths: []string{composeFile},
243 })
244 assert.NilError(t, err)
245 // Project name should be inferred from directory
246 assert.Assert(t, project.Name != "")
247 })
248
249 // With explicit project name
250 t.Run("ExplicitName", func(t *testing.T) {
251 project, err := service.LoadProject(t.Context(), api.ProjectLoadOptions{
252 ConfigPaths: []string{composeFile},
253 ProjectName: "my-custom-project",
254 })
255 assert.NilError(t, err)
256 assert.Equal(t, "my-custom-project", project.Name)
257 })
258}
259
260func TestLoadProject_Compatibility(t *testing.T) {
261 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 4

NewComposeServiceFunction · 0.85
TempDirMethod · 0.80
WriteFileMethod · 0.80
LoadProjectMethod · 0.65

Tested by

no test coverage detected