| 204 | } |
| 205 | |
| 206 | func TestGetConfig_RemoteTrustedHostsMerge(t *testing.T) { //nolint:paralleltest // cannot run in parallel |
| 207 | t.Run("file-based merge precedence", func(t *testing.T) { //nolint:paralleltest // parent test cannot run in parallel |
| 208 | xdgConfigDir, homeDir, localDir := setupDirs(t) |
| 209 | |
| 210 | // XDG config has github.com and gitlab.com |
| 211 | xdgConfig := ` |
| 212 | remote: |
| 213 | trusted-hosts: |
| 214 | - github.com |
| 215 | - gitlab.com |
| 216 | timeout: "30s" |
| 217 | ` |
| 218 | writeFile(t, xdgConfigDir, "taskrc.yml", xdgConfig) |
| 219 | |
| 220 | // Home config has example.com (should be combined with XDG) |
| 221 | homeConfig := ` |
| 222 | remote: |
| 223 | trusted-hosts: |
| 224 | - example.com |
| 225 | ` |
| 226 | writeFile(t, homeDir, ".taskrc.yml", homeConfig) |
| 227 | |
| 228 | cfg, err := GetConfig(localDir) |
| 229 | assert.NoError(t, err) |
| 230 | assert.NotNil(t, cfg) |
| 231 | // Home config entries come first, then XDG |
| 232 | assert.Equal(t, []string{"example.com", "github.com", "gitlab.com"}, cfg.Remote.TrustedHosts) |
| 233 | |
| 234 | // Test with local config too |
| 235 | localConfig := ` |
| 236 | remote: |
| 237 | trusted-hosts: |
| 238 | - local.dev |
| 239 | ` |
| 240 | writeFile(t, localDir, ".taskrc.yml", localConfig) |
| 241 | |
| 242 | cfg, err = GetConfig(localDir) |
| 243 | assert.NoError(t, err) |
| 244 | assert.NotNil(t, cfg) |
| 245 | // Local config entries come first |
| 246 | assert.Equal(t, []string{"example.com", "github.com", "gitlab.com", "local.dev"}, cfg.Remote.TrustedHosts) |
| 247 | }) |
| 248 | |
| 249 | t.Run("merge edge cases", func(t *testing.T) { //nolint:paralleltest // parent test cannot run in parallel |
| 250 | tests := []struct { |
| 251 | name string |
| 252 | base *ast.TaskRC |
| 253 | other *ast.TaskRC |
| 254 | expected []string |
| 255 | }{ |
| 256 | { |
| 257 | name: "merge hosts into empty", |
| 258 | base: &ast.TaskRC{}, |
| 259 | other: &ast.TaskRC{ |
| 260 | Remote: ast.Remote{ |
| 261 | TrustedHosts: []string{"github.com"}, |
| 262 | }, |
| 263 | }, |