|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "os/exec" |
| 6 | + "path/filepath" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/codefly-dev/core/resources" |
| 10 | + "github.com/stretchr/testify/require" |
| 11 | + "gopkg.in/yaml.v3" |
| 12 | +) |
| 13 | + |
| 14 | +func TestConformanceUsesExistingPythonSource(t *testing.T) { |
| 15 | + data, err := os.ReadFile("agent.codefly.yaml") |
| 16 | + require.NoError(t, err) |
| 17 | + var manifest struct { |
| 18 | + Conformance struct { |
| 19 | + Mode string `yaml:"mode"` |
| 20 | + Fixture string `yaml:"fixture"` |
| 21 | + } `yaml:"conformance"` |
| 22 | + } |
| 23 | + require.NoError(t, yaml.Unmarshal(data, &manifest)) |
| 24 | + require.Equal(t, "attach-existing-source", manifest.Conformance.Mode) |
| 25 | + require.True(t, filepath.IsLocal(manifest.Conformance.Fixture)) |
| 26 | + workspace, err := resources.LoadWorkspaceFromDir(t.Context(), manifest.Conformance.Fixture) |
| 27 | + require.NoError(t, err) |
| 28 | + module, err := workspace.RootModule(t.Context()) |
| 29 | + require.NoError(t, err) |
| 30 | + service, err := module.LoadServiceFromName(t.Context(), "subject") |
| 31 | + require.NoError(t, err) |
| 32 | + require.Equal(t, "codefly.dev", service.Agent.Publisher) |
| 33 | + require.Equal(t, "python", service.Agent.Name) |
| 34 | + require.Equal(t, "latest", service.Agent.Version, "the isolated release gate must exercise its candidate") |
| 35 | + command := exec.CommandContext(t.Context(), "uv", "run", "--frozen", "python", "-m", "unittest", "discover") |
| 36 | + command.Dir = filepath.Join(manifest.Conformance.Fixture, "services", "subject", "code") |
| 37 | + command.Env = append(os.Environ(), "UV_PROJECT_ENVIRONMENT="+filepath.Join(t.TempDir(), "venv"), "PYTHONDONTWRITEBYTECODE=1") |
| 38 | + output, err := command.CombinedOutput() |
| 39 | + require.NoError(t, err, string(output)) |
| 40 | + require.Contains(t, string(output), "Ran 1 test") |
| 41 | +} |
0 commit comments