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

Function TestLoadProject_Basic

pkg/compose/loader_test.go:31–69  ·  pkg/compose/loader_test.go::TestLoadProject_Basic
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestLoadProject_Basic(t *testing.T) {
32 // Create a temporary compose file
33 tmpDir := t.TempDir()
34 composeFile := filepath.Join(tmpDir, "compose.yaml")
35 composeContent := `
36name: test-project
37services:
38 web:
39 image: nginx:latest
40 ports:
41 - "8080:80"
42 db:
43 image: postgres:latest
44 environment:
45 POSTGRES_PASSWORD: secret
46`
47 err := os.WriteFile(composeFile, []byte(composeContent), 0o644)
48 assert.NilError(t, err)
49
50 service, err := NewComposeService(nil)
51 assert.NilError(t, err)
52
53 // Load the project
54 project, err := service.LoadProject(t.Context(), api.ProjectLoadOptions{
55 ConfigPaths: []string{composeFile},
56 })
57
58 // Assertions
59 assert.NilError(t, err)
60 assert.Equal(t, "test-project", project.Name)
61 assert.Assert(t, is.Len(project.Services, 2))
62 assert.Check(t, is.Contains(project.Services, "web"))
63 assert.Check(t, is.Contains(project.Services, "db"))
64
65 // Check labels were applied
66 webService := project.Services["web"]
67 assert.Equal(t, "test-project", webService.CustomLabels[api.ProjectLabel])
68 assert.Equal(t, "web", webService.CustomLabels[api.ServiceLabel])
69}
70
71func TestLoadProject_WithEnvironmentResolution(t *testing.T) {
72 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected