MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / TestAuthSliceToMap

Function TestAuthSliceToMap

internal/watcher/watcher_test.go:465–534  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

463}
464
465func TestAuthSliceToMap(t *testing.T) {
466 t.Parallel()
467
468 valid1 := &coreauth.Auth{ID: "a"}
469 valid2 := &coreauth.Auth{ID: "b"}
470 dupOld := &coreauth.Auth{ID: "dup", Label: "old"}
471 dupNew := &coreauth.Auth{ID: "dup", Label: "new"}
472 empty := &coreauth.Auth{ID: " "}
473
474 tests := []struct {
475 name string
476 in []*coreauth.Auth
477 want map[string]*coreauth.Auth
478 }{
479 {
480 name: "nil input",
481 in: nil,
482 want: map[string]*coreauth.Auth{},
483 },
484 {
485 name: "empty input",
486 in: []*coreauth.Auth{},
487 want: map[string]*coreauth.Auth{},
488 },
489 {
490 name: "filters invalid auths",
491 in: []*coreauth.Auth{nil, empty},
492 want: map[string]*coreauth.Auth{},
493 },
494 {
495 name: "keeps valid auths",
496 in: []*coreauth.Auth{valid1, nil, valid2},
497 want: map[string]*coreauth.Auth{"a": valid1, "b": valid2},
498 },
499 {
500 name: "last duplicate wins",
501 in: []*coreauth.Auth{dupOld, dupNew},
502 want: map[string]*coreauth.Auth{"dup": dupNew},
503 },
504 }
505
506 for _, tc := range tests {
507 tc := tc
508 t.Run(tc.name, func(t *testing.T) {
509 t.Parallel()
510 got := authSliceToMap(tc.in)
511 if len(tc.want) == 0 {
512 if got == nil {
513 t.Fatal("expected empty map, got nil")
514 }
515 if len(got) != 0 {
516 t.Fatalf("expected empty map, got %#v", got)
517 }
518 return
519 }
520 if len(got) != len(tc.want) {
521 t.Fatalf("unexpected map length: got %d, want %d", len(got), len(tc.want))
522 }

Callers

nothing calls this directly

Calls 3

authSliceToMapFunction · 0.85
authEqualFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected