Skip to content

Commit dda9de8

Browse files
committed
Fix module package matching and add test
1 parent ed07905 commit dda9de8

File tree

3 files changed

+134
-3
lines changed

3 files changed

+134
-3
lines changed

package.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,13 @@ func (c *ModPackageClassifier) Classify(pkg *Package) PackageClass {
265265
return ClassMain
266266
}
267267

268-
if strings.HasPrefix(pkg.Filepath, c.modInfo.Main.Path) {
268+
if strings.HasPrefix(pkg.Filepath, c.modInfo.Main.Path) || strings.HasPrefix(pkg.Name, c.modInfo.Main.Path) {
269269
return ClassMain
270270
}
271271

272272
// Check if the package is a direct dependency.
273273
for _, dep := range c.modInfo.Deps {
274-
if strings.HasPrefix(pkg.Filepath, dep.Path) {
274+
if strings.HasPrefix(pkg.Filepath, dep.Path) || strings.HasPrefix(pkg.Name, dep.Path) {
275275
return ClassVendor
276276
}
277277
}

package_test.go

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"bytes"
2222
"fmt"
2323
"path/filepath"
24+
"sort"
2425
"testing"
2526

2627
"github.com/stretchr/testify/assert"
@@ -506,3 +507,133 @@ func TestSubSubSubPackage(t *testing.T) {
506507
})
507508
}
508509
}
510+
511+
func TestModInfoPackageClassification(t *testing.T) {
512+
r := require.New(t)
513+
a := require.New(t)
514+
515+
fp, err := getGoldTestResourcePath("dolt")
516+
r.NoError(err)
517+
518+
f, err := Open(fp)
519+
r.NoError(err)
520+
521+
// Check build and mod info
522+
r.NotNil(f.BuildInfo)
523+
r.NotNil(f.BuildInfo.ModInfo)
524+
525+
// Get the packages in the main module.
526+
pkgs, err := f.GetPackages()
527+
r.NoError(err)
528+
529+
// Check that the correct number of packages was found.
530+
r.Len(pkgs, 96, fmt.Sprintf("Number of packages: %d", len(pkgs)))
531+
532+
// Check that the correct packages were found.
533+
mainPackages := []string{
534+
"github.com/dolthub/dolt/go/cmd/dolt/cli",
535+
"github.com/dolthub/dolt/go/cmd/dolt/commands",
536+
"github.com/dolthub/dolt/go/cmd/dolt/commands/cnfcmds",
537+
"github.com/dolthub/dolt/go/cmd/dolt/commands/credcmds",
538+
"github.com/dolthub/dolt/go/cmd/dolt/commands/cvcmds",
539+
"github.com/dolthub/dolt/go/cmd/dolt/commands/indexcmds",
540+
"github.com/dolthub/dolt/go/cmd/dolt/commands/schcmds",
541+
"github.com/dolthub/dolt/go/cmd/dolt/commands/sqlserver",
542+
"github.com/dolthub/dolt/go/cmd/dolt/commands/tblcmds",
543+
"github.com/dolthub/dolt/go/cmd/dolt/errhand",
544+
"github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1",
545+
"github.com/dolthub/dolt/go/gen/proto/dolt/services/remotesapi/v1alpha1",
546+
"github.com/dolthub/dolt/go/libraries/doltcore/creds",
547+
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory",
548+
"github.com/dolthub/dolt/go/libraries/doltcore/diff",
549+
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb",
550+
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs",
551+
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils",
552+
"github.com/dolthub/dolt/go/libraries/doltcore/env",
553+
"github.com/dolthub/dolt/go/libraries/doltcore/env/actions",
554+
"github.com/dolthub/dolt/go/libraries/doltcore/env/actions/commitwalk",
555+
"github.com/dolthub/dolt/go/libraries/doltcore/merge",
556+
"github.com/dolthub/dolt/go/libraries/doltcore/mvdata",
557+
"github.com/dolthub/dolt/go/libraries/doltcore/rebase",
558+
"github.com/dolthub/dolt/go/libraries/doltcore/ref",
559+
"github.com/dolthub/dolt/go/libraries/doltcore/remotestorage",
560+
"github.com/dolthub/dolt/go/libraries/doltcore/row",
561+
"github.com/dolthub/dolt/go/libraries/doltcore/rowconv",
562+
"github.com/dolthub/dolt/go/libraries/doltcore/schema",
563+
"github.com/dolthub/dolt/go/libraries/doltcore/schema/alterschema",
564+
"github.com/dolthub/dolt/go/libraries/doltcore/schema/encoding",
565+
"github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo",
566+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle",
567+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions",
568+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess",
569+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables",
570+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/expreval",
571+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/globalstate",
572+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/json",
573+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/json.(*NomsJSON).github.com/dolthub/dolt/go/store/types",
574+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/json.NomsJSON.github.com/dolthub/dolt/go/store/types",
575+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/lookup",
576+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/setalgebra",
577+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlfmt",
578+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlutil",
579+
"github.com/dolthub/dolt/go/libraries/doltcore/table",
580+
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor",
581+
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor/creation",
582+
"github.com/dolthub/dolt/go/libraries/doltcore/table/pipeline",
583+
"github.com/dolthub/dolt/go/libraries/doltcore/table/typed/json",
584+
"github.com/dolthub/dolt/go/libraries/doltcore/table/typed/noms",
585+
"github.com/dolthub/dolt/go/libraries/doltcore/table/untyped",
586+
"github.com/dolthub/dolt/go/libraries/doltcore/table/untyped/csv",
587+
"github.com/dolthub/dolt/go/libraries/doltcore/table/untyped/fwt",
588+
"github.com/dolthub/dolt/go/libraries/doltcore/table/untyped/nullprinter",
589+
"github.com/dolthub/dolt/go/libraries/doltcore/table/untyped/sqlexport",
590+
"github.com/dolthub/dolt/go/libraries/doltcore/table/untyped/tabular",
591+
"github.com/dolthub/dolt/go/libraries/doltcore/table/untyped/xlsx",
592+
"github.com/dolthub/dolt/go/libraries/events",
593+
"github.com/dolthub/dolt/go/libraries/utils/argparser",
594+
"github.com/dolthub/dolt/go/libraries/utils/async",
595+
"github.com/dolthub/dolt/go/libraries/utils/config",
596+
"github.com/dolthub/dolt/go/libraries/utils/earl",
597+
"github.com/dolthub/dolt/go/libraries/utils/editor",
598+
"github.com/dolthub/dolt/go/libraries/utils/file",
599+
"github.com/dolthub/dolt/go/libraries/utils/filesys",
600+
"github.com/dolthub/dolt/go/libraries/utils/funcitr",
601+
"github.com/dolthub/dolt/go/libraries/utils/iohelp",
602+
"github.com/dolthub/dolt/go/libraries/utils/mathutil",
603+
"github.com/dolthub/dolt/go/libraries/utils/pipeline",
604+
"github.com/dolthub/dolt/go/libraries/utils/set",
605+
"github.com/dolthub/dolt/go/libraries/utils/strhelp",
606+
"github.com/dolthub/dolt/go/libraries/utils/tracing",
607+
"github.com/dolthub/dolt/go/libraries/utils/valutil",
608+
"github.com/dolthub/dolt/go/store/atomicerr",
609+
"github.com/dolthub/dolt/go/store/blobstore",
610+
"github.com/dolthub/dolt/go/store/chunks",
611+
"github.com/dolthub/dolt/go/store/constants",
612+
"github.com/dolthub/dolt/go/store/d",
613+
"github.com/dolthub/dolt/go/store/datas",
614+
"github.com/dolthub/dolt/go/store/diff",
615+
"github.com/dolthub/dolt/go/store/hash",
616+
"github.com/dolthub/dolt/go/store/marshal",
617+
"github.com/dolthub/dolt/go/store/metrics",
618+
"github.com/dolthub/dolt/go/store/nbs",
619+
"github.com/dolthub/dolt/go/store/nomdl",
620+
"github.com/dolthub/dolt/go/store/sloppy",
621+
"github.com/dolthub/dolt/go/store/spec",
622+
"github.com/dolthub/dolt/go/store/types",
623+
"github.com/dolthub/dolt/go/store/types/edits",
624+
"github.com/dolthub/dolt/go/store/util/datetime",
625+
"github.com/dolthub/dolt/go/store/util/random",
626+
"github.com/dolthub/dolt/go/store/util/sizecache",
627+
"github.com/dolthub/dolt/go/store/util/tempfiles",
628+
"github.com/dolthub/dolt/go/store/util/verbose",
629+
"main",
630+
}
631+
632+
sort.Slice(pkgs, func(i, j int) bool {
633+
return pkgs[i].Name < pkgs[j].Name
634+
})
635+
636+
for i, expected := range mainPackages {
637+
a.Equal(expected, pkgs[i].Name, fmt.Sprintf("Index %d is incorrect.", i))
638+
}
639+
}

testdata/gold

Submodule gold updated 1 file

0 commit comments

Comments
 (0)