(t *testing.T)
| 546 | } |
| 547 | |
| 548 | func TestDepsResolveRelative(t *testing.T) { |
| 549 | handlerPath := filepath.FromSlash("pkg/api/handler.go") |
| 550 | typesPath := filepath.FromSlash("pkg/common/types.go") |
| 551 | loggerPath := filepath.FromSlash("pkg/log/logger.go") |
| 552 | |
| 553 | files := []FileInfo{ |
| 554 | {Path: handlerPath}, |
| 555 | {Path: typesPath}, |
| 556 | {Path: loggerPath}, |
| 557 | } |
| 558 | idx := buildFileIndex(files, "") |
| 559 | |
| 560 | tests := []struct { |
| 561 | name string |
| 562 | imp string |
| 563 | fromDir string |
| 564 | want []string |
| 565 | }{ |
| 566 | {name: "same directory file", imp: "./handler", fromDir: filepath.FromSlash("pkg/api"), want: []string{handlerPath}}, |
| 567 | {name: "parent directory file", imp: "../common/types", fromDir: filepath.FromSlash("pkg/api"), want: []string{typesPath}}, |
| 568 | {name: "two levels up", imp: "../../log/logger", fromDir: filepath.FromSlash("pkg/api/internal"), want: []string{loggerPath}}, |
| 569 | {name: "missing file", imp: "./missing", fromDir: "pkg/api", want: nil}, |
| 570 | } |
| 571 | |
| 572 | for _, tt := range tests { |
| 573 | t.Run(tt.name, func(t *testing.T) { |
| 574 | got := resolveRelative(tt.imp, tt.fromDir, idx) |
| 575 | if !reflect.DeepEqual(got, tt.want) { |
| 576 | t.Fatalf("resolveRelative(%q, %q): want %v, got %v", tt.imp, tt.fromDir, tt.want, got) |
| 577 | } |
| 578 | }) |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | func TestDepsFuzzyResolve(t *testing.T) { |
| 583 | goHandler := filepath.FromSlash("pkg/service/handler.go") |
nothing calls this directly
no test coverage detected