(t *testing.T)
| 672 | } |
| 673 | |
| 674 | func TestDepsDetectModule(t *testing.T) { |
| 675 | tests := []struct { |
| 676 | name string |
| 677 | goModBody string |
| 678 | writeGoMod bool |
| 679 | want string |
| 680 | }{ |
| 681 | { |
| 682 | name: "module found", |
| 683 | goModBody: strings.Join([]string{ |
| 684 | "module example.com/project", |
| 685 | "", |
| 686 | "go 1.22", |
| 687 | }, "\n"), |
| 688 | writeGoMod: true, |
| 689 | want: "example.com/project", |
| 690 | }, |
| 691 | { |
| 692 | name: "missing go.mod", |
| 693 | writeGoMod: false, |
| 694 | want: "", |
| 695 | }, |
| 696 | { |
| 697 | name: "go.mod without module", |
| 698 | goModBody: strings.Join([]string{ |
| 699 | "go 1.22", |
| 700 | }, "\n"), |
| 701 | writeGoMod: true, |
| 702 | want: "", |
| 703 | }, |
| 704 | } |
| 705 | |
| 706 | for _, tt := range tests { |
| 707 | t.Run(tt.name, func(t *testing.T) { |
| 708 | dir := t.TempDir() |
| 709 | if tt.writeGoMod { |
| 710 | err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte(tt.goModBody), 0o644) |
| 711 | if err != nil { |
| 712 | t.Fatalf("write go.mod: %v", err) |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | got := detectModule(dir) |
| 717 | if got != tt.want { |
| 718 | t.Fatalf("detectModule(): want %q, got %q", tt.want, got) |
| 719 | } |
| 720 | }) |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | func TestDepsFileGraphHubAndConnectedFiles(t *testing.T) { |
| 725 | fg := &FileGraph{ |
nothing calls this directly
no test coverage detected