(t *testing.T)
| 139 | } |
| 140 | |
| 141 | func Test_processFile_optional_env_file_missing(t *testing.T) { |
| 142 | dir := t.TempDir() |
| 143 | composePath := filepath.Join(dir, "compose.yaml") |
| 144 | composeContent := `name: test |
| 145 | services: |
| 146 | web: |
| 147 | image: nginx |
| 148 | env_file: |
| 149 | - path: missing.env |
| 150 | required: false |
| 151 | ` |
| 152 | assert.NilError(t, os.WriteFile(composePath, []byte(composeContent), 0o600)) |
| 153 | |
| 154 | project, err := loader.LoadWithContext(t.Context(), types.ConfigDetails{ |
| 155 | WorkingDir: dir, |
| 156 | Environment: types.Mapping{}, |
| 157 | ConfigFiles: []types.ConfigFile{{Filename: composePath}}, |
| 158 | }) |
| 159 | assert.NilError(t, err) |
| 160 | |
| 161 | extFiles := map[string]string{} |
| 162 | envFiles := map[string]string{} |
| 163 | data, err := processFile(t.Context(), composePath, project, extFiles, envFiles) |
| 164 | assert.NilError(t, err, "optional missing env file should not cause error") |
| 165 | |
| 166 | // The file is absent so nothing is registered for upload, but its path is still |
| 167 | // rewritten to the opaque <hash>.env placeholder so the published artifact never leaks |
| 168 | // the publisher's local path and stays consistent with the file-present case. The hash |
| 169 | // derives from the path string alone, so it is deterministic regardless of existence. |
| 170 | assert.Equal(t, len(envFiles), 0, "missing optional env file is not registered for upload") |
| 171 | envPath := project.Services["web"].EnvFiles[0].Path |
| 172 | hash := fmt.Sprintf("%x.env", sha256.Sum256([]byte(envPath))) |
| 173 | assert.Assert(t, strings.Contains(string(data), hash), "published YAML should reference the hash placeholder") |
| 174 | assert.Assert(t, !strings.Contains(string(data), "path: missing.env"), "published YAML must not leak the local path") |
| 175 | assert.Assert(t, strings.Contains(string(data), "required: false"), "optional flag must be preserved") |
| 176 | } |
| 177 | |
| 178 | func Test_processFile_optional_env_file_present(t *testing.T) { |
| 179 | dir := t.TempDir() |
nothing calls this directly
no test coverage detected