fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

Expand Repository.MergeMutable to cover more fields (#684)

There was no test coverage, so I added some.

Closes #683.

author
Ian Kerins
committer
GitHub
date (Mar 14, 2024, 12:39 PM +0200) commit 4448a459 parent cc5e0933
+148 -2
+17 -2
api.go
··· 656 656 // 657 657 // Note: We ignore RawConfig fields which are duplicated into Repository: 658 658 // name and id. 659 - // 660 - // Note: URL, *Template fields are ignored. They are not used by Sourcegraph. 661 659 func (r *Repository) MergeMutable(x *Repository) (mutated bool, err error) { 662 660 if r.ID != x.ID { 663 661 // Sourcegraph: strange behaviour may occur if ID changes but names don't. ··· 686 684 mutated = true 687 685 r.RawConfig[k] = v 688 686 } 687 + } 688 + 689 + if r.URL != x.URL { 690 + mutated = true 691 + r.URL = x.URL 692 + } 693 + if r.CommitURLTemplate != x.CommitURLTemplate { 694 + mutated = true 695 + r.CommitURLTemplate = x.CommitURLTemplate 696 + } 697 + if r.FileURLTemplate != x.FileURLTemplate { 698 + mutated = true 699 + r.FileURLTemplate = x.FileURLTemplate 700 + } 701 + if r.LineFragmentTemplate != x.LineFragmentTemplate { 702 + mutated = true 703 + r.LineFragmentTemplate = x.LineFragmentTemplate 689 704 } 690 705 691 706 return mutated, nil
+131
api_test.go
··· 237 237 } 238 238 } 239 239 } 240 + 241 + func TestRepositoryMergeMutable(t *testing.T) { 242 + a := Repository{ 243 + ID: 0, 244 + Name: "name", 245 + Branches: []RepositoryBranch{ 246 + { 247 + Name: "branchName", 248 + Version: "branchVersion", 249 + }, 250 + }, 251 + RawConfig: nil, 252 + URL: "url", 253 + CommitURLTemplate: "commitUrlTemplate", 254 + FileURLTemplate: "fileUrlTemplate", 255 + LineFragmentTemplate: "lineFragmentTemplate", 256 + } 257 + 258 + t.Run("different ID", func(t *testing.T) { 259 + b := a 260 + b.ID = 1 261 + mutated, err := a.MergeMutable(&b) 262 + if err == nil { 263 + t.Fatalf("want err, got mutated=%t", mutated) 264 + } 265 + }) 266 + t.Run("different Name", func(t *testing.T) { 267 + b := a 268 + b.Name = "otherName" 269 + mutated, err := a.MergeMutable(&b) 270 + if err == nil { 271 + t.Fatalf("want err, got mutated=%t", mutated) 272 + } 273 + }) 274 + t.Run("different Branches", func(t *testing.T) { 275 + b := a 276 + b.Branches = []RepositoryBranch{ 277 + { 278 + Name: "otherBranchName", 279 + Version: "branchVersion", 280 + }, 281 + } 282 + mutated, err := a.MergeMutable(&b) 283 + if err == nil { 284 + t.Fatalf("want err, got mutated=%t", mutated) 285 + } 286 + }) 287 + t.Run("different RawConfig", func(t *testing.T) { 288 + b := a 289 + b.RawConfig = map[string]string{"foo": "bar"} 290 + mutated, err := a.MergeMutable(&b) 291 + if err != nil { 292 + t.Fatalf("got err %v", err) 293 + } 294 + if !mutated { 295 + t.Fatalf("want mutated=true, got false") 296 + } 297 + if !reflect.DeepEqual(a.RawConfig, b.RawConfig) { 298 + t.Fatalf("got different RawConfig, %v vs %v", a.RawConfig, b.RawConfig) 299 + } 300 + }) 301 + t.Run("different URL", func(t *testing.T) { 302 + b := a 303 + b.URL = "otherURL" 304 + mutated, err := a.MergeMutable(&b) 305 + if err != nil { 306 + t.Fatalf("got err %v", err) 307 + } 308 + if !mutated { 309 + t.Fatalf("want mutated=true, got false") 310 + } 311 + if a.URL != b.URL { 312 + t.Fatalf("got different URL, %s vs %s", a.URL, b.URL) 313 + } 314 + }) 315 + t.Run("different CommitURLTemplate", func(t *testing.T) { 316 + b := a 317 + b.CommitURLTemplate = "otherCommitUrlTemplate" 318 + mutated, err := a.MergeMutable(&b) 319 + if err != nil { 320 + t.Fatalf("got err %v", err) 321 + } 322 + if !mutated { 323 + t.Fatalf("want mutated=true, got false") 324 + } 325 + if a.CommitURLTemplate != b.CommitURLTemplate { 326 + t.Fatalf("got different CommitURLTemplate, %s vs %s", a.CommitURLTemplate, b.CommitURLTemplate) 327 + } 328 + }) 329 + t.Run("different FileURLTemplate", func(t *testing.T) { 330 + b := a 331 + b.FileURLTemplate = "otherFileUrlTemplate" 332 + mutated, err := a.MergeMutable(&b) 333 + if err != nil { 334 + t.Fatalf("got err %v", err) 335 + } 336 + if !mutated { 337 + t.Fatalf("want mutated=true, got false") 338 + } 339 + if a.FileURLTemplate != b.FileURLTemplate { 340 + t.Fatalf("got different FileURLTemplate, %s vs %s", a.FileURLTemplate, b.FileURLTemplate) 341 + } 342 + }) 343 + t.Run("different LineFragmentTemplate", func(t *testing.T) { 344 + b := a 345 + b.LineFragmentTemplate = "otherLineFragmentTemplate" 346 + mutated, err := a.MergeMutable(&b) 347 + if err != nil { 348 + t.Fatalf("got err %v", err) 349 + } 350 + if !mutated { 351 + t.Fatalf("want mutated=true, got false") 352 + } 353 + if a.LineFragmentTemplate != b.LineFragmentTemplate { 354 + t.Fatalf("got different LineFragmentTemplate, %s vs %s", a.LineFragmentTemplate, b.LineFragmentTemplate) 355 + } 356 + }) 357 + t.Run("all same", func(t *testing.T) { 358 + b := a 359 + mutated, err := a.MergeMutable(&b) 360 + if err != nil { 361 + t.Fatalf("got err %v", err) 362 + } 363 + if mutated { 364 + t.Fatalf("want mutated=false, got true") 365 + } 366 + if !reflect.DeepEqual(a, b) { 367 + t.Fatalf("got different Repository, %v vs %v", a, b) 368 + } 369 + }) 370 + }