From 3201ef6a3442d3167cd54fdae5b31b039caf08bf Mon Sep 17 00:00:00 2001 From: sam boyer Date: Wed, 11 Jul 2018 00:34:02 -0400 Subject: [PATCH 01/12] dep: Introduce dep check subcommand dep check is a read-only command that verifies dep's sync invariants are met. It's primarily intended for automated use (e.g. CI or git pre-commit hooks). We may expand it later to include more comprehensive checks. --- cmd/dep/check.go | 177 +++++++++++++++++++++++++++++++++++++++++ cmd/dep/ensure.go | 15 +--- cmd/dep/main.go | 22 ++++- gps/verify/digest.go | 15 +++- gps/verify/lockdiff.go | 39 +++++---- project.go | 6 -- txn_writer.go | 13 ++- 7 files changed, 245 insertions(+), 42 deletions(-) create mode 100644 cmd/dep/check.go diff --git a/cmd/dep/check.go b/cmd/dep/check.go new file mode 100644 index 0000000000..caa45e3fe4 --- /dev/null +++ b/cmd/dep/check.go @@ -0,0 +1,177 @@ +package main + +import ( + "bytes" + "flag" + "fmt" + "io/ioutil" + "log" + "os" + "path/filepath" + "strings" + + "github.com/golang/dep" + "github.com/golang/dep/gps" + "github.com/golang/dep/gps/verify" + "github.com/pkg/errors" +) + +const checkShortHelp = `Check if imports, Gopkg.toml, and Gopkg.lock are in sync` +const checkLongHelp = ` +Check determines if your project is in a good state. If problems are found, it +prints a description of each issue, then exits 1. Passing -q suppresses output. + +Flags control which specific checks will be run. By default,dep check verifies +that Gopkg.lock is in sync with Gopkg.toml and the imports in your project's .go +files, and that the vendor directory is in sync with Gopkg.lock. These checks +can be disabled with -skip-lock and -skip-vendor, respectively. + +(See https://golang.github.io/dep/docs/ensure-mechanics.html#staying-in-sync for +more information on what it means to be "in sync.") +` + +type checkCommand struct { + quiet bool + skiplock, skipvendor bool +} + +func (cmd *checkCommand) Name() string { return "check" } +func (cmd *checkCommand) Args() string { + return "[-q] [-skip-lock] [-skip-vendor]" +} +func (cmd *checkCommand) ShortHelp() string { return checkShortHelp } +func (cmd *checkCommand) LongHelp() string { return checkLongHelp } +func (cmd *checkCommand) Hidden() bool { return false } + +func (cmd *checkCommand) Register(fs *flag.FlagSet) { + fs.BoolVar(&cmd.skiplock, "skip-lock", false, "Skip checking that imports and Gopkg.toml are in sync with Gopkg.lock") + fs.BoolVar(&cmd.skipvendor, "skip-vendor", false, "Skip checking that vendor is in sync with Gopkg.lock") + fs.BoolVar(&cmd.quiet, "q", false, "Suppress non-error output") +} + +func (cmd *checkCommand) Run(ctx *dep.Ctx, args []string) error { + logger := ctx.Out + if cmd.quiet { + logger = log.New(ioutil.Discard, "", 0) + } + + p, err := ctx.LoadProject() + if err != nil { + return err + } + + sm, err := ctx.SourceManager() + if err != nil { + return err + } + + sm.UseDefaultSignalHandling() + defer sm.Release() + + var fail bool + if !cmd.skiplock { + if p.Lock == nil { + return errors.New("Gopkg.lock does not exist, cannot check it against imports and Gopkg.toml") + } + + lsat := verify.LockSatisfiesInputs(p.Lock, p.Manifest, p.RootPackageTree) + delta := verify.DiffLocks(p.Lock, p.ChangedLock) + sat, changed := lsat.Satisfied(), delta.Changed(verify.PruneOptsChanged|verify.HashVersionChanged) + + if changed || !sat { + fail = true + logger.Println("# Gopkg.lock is out of sync:") + if !sat { + logger.Printf("%s\n", sprintLockUnsat(lsat)) + } + if changed { + for pr, lpd := range delta.ProjectDeltas { + // Only two possible changes right now are prune opts + // changing or a missing hash digest (for old Gopkg.lock + // files) + if lpd.PruneOptsChanged() { + // Override what's on the lockdiff with the extra info we have; + // this lets us excise PruneNestedVendorDirs and get the real + // value from the input param in place. + old := lpd.PruneOptsBefore & ^gps.PruneNestedVendorDirs + new := lpd.PruneOptsAfter & ^gps.PruneNestedVendorDirs + logger.Printf("%s: prune options changed (%s -> %s)\n", pr, old, new) + } + if lpd.HashVersionWasZero() { + logger.Printf("%s: no hash digest in lock\n", pr) + } + } + } + } + } + + if !cmd.skipvendor { + if p.Lock == nil { + return errors.New("Gopkg.lock does not exist, cannot check vendor against it") + } + + statuses, err := p.VerifyVendor() + if err != nil { + return errors.Wrap(err, "error while verifying vendor") + } + + if fail { + logger.Println() + } + // One full pass through, to see if we need to print the header. + for _, status := range statuses { + if status != verify.NoMismatch { + fail = true + logger.Println("# vendor is out of sync:") + break + } + } + + for pr, status := range statuses { + switch status { + case verify.NotInTree: + logger.Printf("%s: missing from vendor\n", pr) + case verify.NotInLock: + fi, err := os.Stat(filepath.Join(p.AbsRoot, "vendor", pr)) + if err != nil { + return errors.Wrap(err, "could not stat file that VerifyVendor claimed existed") + } + + if fi.IsDir() { + logger.Printf("%s: unused project\n", pr) + } else { + logger.Printf("%s: orphaned file\n", pr) + } + case verify.DigestMismatchInLock: + logger.Printf("%s: hash of vendored tree didn't match digest in Gopkg.lock\n", pr) + case verify.HashVersionMismatch: + // This will double-print if the hash version is zero, but + // that's a rare case that really only occurs before the first + // run with a version of dep >=0.5.0, so it's fine. + logger.Printf("%s: hash algorithm mismatch, want version %v\n", pr, verify.HashVersion) + } + } + } + + if fail { + return silentfail{} + } + return nil +} + +func sprintLockUnsat(lsat verify.LockSatisfaction) string { + var buf bytes.Buffer + for _, missing := range lsat.MissingImports { + fmt.Fprintf(&buf, "%s: missing from input-imports\n", missing) + } + for _, excess := range lsat.ExcessImports { + fmt.Fprintf(&buf, "%s: in input-imports, but not imported\n", excess) + } + for pr, unmatched := range lsat.UnmetOverrides { + fmt.Fprintf(&buf, "%s@%s: not allowed by override %s\n", pr, unmatched.V, unmatched.C) + } + for pr, unmatched := range lsat.UnmetConstraints { + fmt.Fprintf(&buf, "%s@%s: not allowed by constraint %s\n", pr, unmatched.V, unmatched.C) + } + return strings.TrimSpace(buf.String()) +} diff --git a/cmd/dep/ensure.go b/cmd/dep/ensure.go index 3c5d2dbc3d..23015ed71f 100644 --- a/cmd/dep/ensure.go +++ b/cmd/dep/ensure.go @@ -261,20 +261,7 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project lsat := verify.LockSatisfiesInputs(p.Lock, p.Manifest, params.RootPackageTree) if !lsat.Satisfied() { if ctx.Verbose { - ctx.Out.Println("# Gopkg.lock is out of sync with Gopkg.toml and project code:") - for _, missing := range lsat.MissingImports { - ctx.Out.Printf("%s: missing from input-imports\n", missing) - } - for _, excess := range lsat.ExcessImports { - ctx.Out.Printf("%s: in input-imports, but isn't imported\n", excess) - } - for pr, unmatched := range lsat.UnmetOverrides { - ctx.Out.Printf("%s@%s: not allowed by override %s\n", pr, unmatched.V, unmatched.C) - } - for pr, unmatched := range lsat.UnmetConstraints { - ctx.Out.Printf("%s@%s: not allowed by constraint %s\n", pr, unmatched.V, unmatched.C) - } - ctx.Out.Println() + ctx.Out.Printf("# Gopkg.lock is out of sync with Gopkg.toml and project imports:\n%s\n\n", sprintLockUnsat(lsat)) } solve = true } else if cmd.noVendor { diff --git a/cmd/dep/main.go b/cmd/dep/main.go index c247530179..4a9658068f 100644 --- a/cmd/dep/main.go +++ b/cmd/dep/main.go @@ -39,6 +39,14 @@ type command interface { Run(*dep.Ctx, []string) error } +// Helper type so that commands can fail without generating any additional +// ouptut. +type silentfail struct{} + +func (silentfail) Error() string { + return "" +} + func main() { p := &profile{} @@ -139,7 +147,12 @@ func (c *Config) Run() int { // Build flag set with global flags in there. flags := flag.NewFlagSet(cmdName, flag.ContinueOnError) flags.SetOutput(c.Stderr) - verbose := flags.Bool("v", false, "enable verbose logging") + + var verbose bool + // No verbose for verify + if cmdName != "check" { + flags.BoolVar(&verbose, "v", false, "enable verbose logging") + } // Register the subcommand flags in there, too. cmd.Register(flags) @@ -186,7 +199,7 @@ func (c *Config) Run() int { ctx := &dep.Ctx{ Out: outLogger, Err: errLogger, - Verbose: *verbose, + Verbose: verbose, DisableLocking: getEnv(c.Env, "DEPNOLOCK") != "", Cachedir: cachedir, CacheAge: cacheAge, @@ -197,7 +210,9 @@ func (c *Config) Run() int { // Run the command with the post-flag-processing args. if err := cmd.Run(ctx, flags.Args()); err != nil { - errLogger.Printf("%v\n", err) + if _, ok := err.(silentfail); !ok { + errLogger.Printf("%v\n", err) + } return errorExitCode } @@ -222,6 +237,7 @@ func commandList() []command { &ensureCommand{}, &pruneCommand{}, &versionCommand{}, + &checkCommand{}, } } diff --git a/gps/verify/digest.go b/gps/verify/digest.go index a424f50daf..413879fe5a 100644 --- a/gps/verify/digest.go +++ b/gps/verify/digest.go @@ -386,11 +386,23 @@ func ParseVersionedDigest(input string) (VersionedDigest, error) { func CheckDepTree(osDirname string, wantDigests map[string]VersionedDigest) (map[string]VendorStatus, error) { osDirname = filepath.Clean(osDirname) + // Create associative array to store the results of calling this function. + slashStatus := make(map[string]VendorStatus) + // Ensure top level pathname is a directory fi, err := os.Stat(osDirname) if err != nil { + // If the dir doesn't exist at all, that's OK - just consider all the + // wanted paths absent. + if os.IsNotExist(err) { + for path := range wantDigests { + slashStatus[path] = NotInTree + } + return slashStatus, nil + } return nil, errors.Wrap(err, "cannot Stat") } + if !fi.IsDir() { return nil, errors.Errorf("cannot verify non directory: %q", osDirname) } @@ -438,9 +450,6 @@ func CheckDepTree(osDirname string, wantDigests map[string]VersionedDigest) (map // `NotInLock`. nodes := []*fsnode{currentNode} - // Create associative array to store the results of calling this function. - slashStatus := make(map[string]VendorStatus) - // Mark directories of expected projects as required. When each respective // project is later found while traversing the vendor root hierarchy, its // status will be updated to reflect whether its digest is empty, or, diff --git a/gps/verify/lockdiff.go b/gps/verify/lockdiff.go index 60928d0876..525a46db0e 100644 --- a/gps/verify/lockdiff.go +++ b/gps/verify/lockdiff.go @@ -53,12 +53,13 @@ type LockedProjectDelta struct { // properties of two LockedProjects. It can represent deltas for // VerifiableProject properties, as well. type LockedProjectPropertiesDelta struct { - PackagesAdded, PackagesRemoved []string - VersionBefore, VersionAfter gps.UnpairedVersion - RevisionBefore, RevisionAfter gps.Revision - SourceBefore, SourceAfter string - PruneOptsBefore, PruneOptsAfter gps.PruneOptions - HashChanged, HashVersionChanged bool + PackagesAdded, PackagesRemoved []string + VersionBefore, VersionAfter gps.UnpairedVersion + RevisionBefore, RevisionAfter gps.Revision + SourceBefore, SourceAfter string + PruneOptsBefore, PruneOptsAfter gps.PruneOptions + HashVersionBefore, HashVersionAfter int + HashChanged bool } // DiffLocks compares two locks and computes a semantically rich delta between @@ -200,20 +201,18 @@ func DiffLockedProjectProperties(lp1, lp2 gps.LockedProject) LockedProjectProper if ok1 && ok2 { ld.PruneOptsBefore, ld.PruneOptsAfter = vp1.PruneOpts, vp2.PruneOpts + ld.HashVersionBefore, ld.HashVersionAfter = vp1.Digest.HashVersion, vp2.Digest.HashVersion - if vp1.Digest.HashVersion != vp2.Digest.HashVersion { - ld.HashVersionChanged = true - } if !bytes.Equal(vp1.Digest.Digest, vp2.Digest.Digest) { ld.HashChanged = true } } else if ok1 { ld.PruneOptsBefore = vp1.PruneOpts - ld.HashVersionChanged = true + ld.HashVersionBefore = vp1.Digest.HashVersion ld.HashChanged = true } else if ok2 { ld.PruneOptsAfter = vp2.PruneOpts - ld.HashVersionChanged = true + ld.HashVersionAfter = vp2.Digest.HashVersion ld.HashChanged = true } @@ -322,7 +321,7 @@ func (ld LockedProjectPropertiesDelta) Changed(dims DeltaDimension) bool { if dims&HashChanged != 0 && ld.HashChanged { return true } - if dims&HashVersionChanged != 0 && ld.HashVersionChanged { + if dims&HashVersionChanged != 0 && ld.HashVersionChanged() { return true } if dims&VersionChanged != 0 && ld.VersionChanged() { @@ -351,7 +350,7 @@ func (ld LockedProjectPropertiesDelta) Changes() DeltaDimension { if ld.HashChanged { dd |= HashChanged } - if ld.HashVersionChanged { + if ld.HashVersionChanged() { dd |= HashVersionChanged } if ld.VersionChanged() { @@ -400,11 +399,23 @@ func (ld LockedProjectPropertiesDelta) PackagesChanged() bool { } // PruneOptsChanged returns true if the pruning flags for the project changed -// between teh first and second locks. +// between the first and second locks. func (ld LockedProjectPropertiesDelta) PruneOptsChanged() bool { return ld.PruneOptsBefore != ld.PruneOptsAfter } +// HashVersionChanged returns true if the version of the hashing algorithm +// changed between the first and second locks. +func (ld LockedProjectPropertiesDelta) HashVersionChanged() bool { + return ld.HashVersionBefore != ld.HashVersionAfter +} + +// HashVersionWasZero returns true if the first lock had a zero hash version, +// which can only mean it was uninitialized. +func (ld LockedProjectPropertiesDelta) HashVersionWasZero() bool { + return ld.HashVersionBefore == 0 +} + // sortLockedProjects returns a sorted copy of lps, or itself if already sorted. func sortLockedProjects(lps []gps.LockedProject) []gps.LockedProject { if len(lps) <= 1 || sort.SliceIsSorted(lps, func(i, j int) bool { diff --git a/project.go b/project.go index 913744e1ec..e54744d315 100644 --- a/project.go +++ b/project.go @@ -140,12 +140,6 @@ func (p *Project) VerifyVendor() (map[string]verify.VendorStatus, error) { lps = p.Lock.Projects() } - err := os.MkdirAll(vendorDir, os.FileMode(0777)) - if err != nil { - p.CheckVendorErr = err - return - } - sums := make(map[string]verify.VersionedDigest) for _, lp := range lps { sums[string(lp.Ident().ProjectRoot)] = lp.(verify.VerifiableProject).Digest diff --git a/txn_writer.go b/txn_writer.go index 3c3ba5831b..5df2f26047 100644 --- a/txn_writer.go +++ b/txn_writer.go @@ -527,7 +527,7 @@ func (dw *DeltaWriter) Write(path string, sm gps.SourceManager, examples bool, l i := 0 tot := len(dw.changed) if len(dw.changed) > 0 { - logger.Println("\n# Bringing vendor into sync") + logger.Println("# Bringing vendor into sync") } for pr, reason := range dw.changed { if reason == projectRemoved { @@ -604,7 +604,16 @@ func (dw *DeltaWriter) Write(path string, sm gps.SourceManager, examples bool, l for i, pr := range dropped { // Kind of a lie to print this. ¯\_(ツ)_/¯ - logger.Printf("(%d/%d) Removed unused project %s", tot-(len(dropped)-i-1), tot, pr) + fi, err := os.Stat(filepath.Join(vpath, string(pr))) + if err != nil { + return errors.Wrap(err, "could not stat file that VerifyVendor claimed existed") + } + + if fi.IsDir() { + logger.Printf("(%d/%d) Removed unused project %s", tot-(len(dropped)-i-1), tot, pr) + } else { + logger.Printf("(%d/%d) Removed orphaned file %s", tot-(len(dropped)-i-1), tot, pr) + } } // Ensure vendor/.git is preserved if present From e709116bb08c3d96386fd60ad4a89d0fa1687ae5 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Wed, 11 Jul 2018 01:25:45 -0400 Subject: [PATCH 02/12] Update CHANGELOG --- CHANGELOG.md | 2 ++ cmd/dep/check.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52e6fbb97c..80e6b52c1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ NEW FEATURES: * `dep ensure` now explains what changes to the code or Gopkg.toml have induced solving ([#1912](https://github.com/golang/dep/pull/1912)). * Hash digests of vendor contents are now stored in `Gopkg.lock`, and the contents of vendor are only rewritten on change or hash mismatch ([#1912](https://github.com/golang/dep/pull/1912)). * Added support for ppc64/ppc64le. +* New subcommand `dep check` quickly reports if imports, Gopkg.toml, Gopkg.lock, and vendor are out of sync ([#1932](https://github.com/golang/dep/pull/1932)). BUG FIXES: @@ -23,6 +24,7 @@ IMPROVEMENTS: * Reduce network access by trusting local source information and only pulling from upstream when necessary ([#1250](https://github.com/golang/dep/pull/1250)). * Update our dependency on Masterminds/semver to follow upstream again now that [Masterminds/semver#67](https://github.com/Masterminds/semver/pull/67) is merged([#1792](https://github.com/golang/dep/pull/1792)). * `inputs-digest` was removed from `Gopkg.lock` ([#1912](https://github.com/golang/dep/pull/1912)). +* Hash digests of vendor contents are now stored in `Gopkg.lock`, and the contents of vendor are only rewritten on change or hash mismatch ([#1912](https://github.com/golang/dep/pull/1912)). * Don't exclude `Godeps` folder ([#1822](https://github.com/golang/dep/issues/1822)). WIP: diff --git a/cmd/dep/check.go b/cmd/dep/check.go index caa45e3fe4..b2ce444df9 100644 --- a/cmd/dep/check.go +++ b/cmd/dep/check.go @@ -21,7 +21,7 @@ const checkLongHelp = ` Check determines if your project is in a good state. If problems are found, it prints a description of each issue, then exits 1. Passing -q suppresses output. -Flags control which specific checks will be run. By default,dep check verifies +Flags control which specific checks will be run. By default, dep check verifies that Gopkg.lock is in sync with Gopkg.toml and the imports in your project's .go files, and that the vendor directory is in sync with Gopkg.lock. These checks can be disabled with -skip-lock and -skip-vendor, respectively. From fbd4877f402b36986229eea93038b5c24e125609 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Thu, 12 Jul 2018 21:58:49 -0400 Subject: [PATCH 03/12] dep: Add license header to check.go --- cmd/dep/check.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/dep/check.go b/cmd/dep/check.go index b2ce444df9..7266ddb8bf 100644 --- a/cmd/dep/check.go +++ b/cmd/dep/check.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package main import ( From 74eac2bb2b0a5a94a498b52ff8d7a2eeaca9317f Mon Sep 17 00:00:00 2001 From: sam boyer Date: Fri, 20 Jul 2018 15:50:36 -0700 Subject: [PATCH 04/12] test: Don't add -v to dep check tests --- internal/test/integration/testproj.go | 6 +++++- internal/test/test.go | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/test/integration/testproj.go b/internal/test/integration/testproj.go index 39ffada8cc..1d8cc729d7 100644 --- a/internal/test/integration/testproj.go +++ b/internal/test/integration/testproj.go @@ -175,7 +175,11 @@ func (p *TestProject) DoRun(args []string) error { p.t.Logf("running testdep %v", args) } prog := filepath.Join(p.origWd, "testdep"+test.ExeSuffix) - newargs := append([]string{args[0], "-v"}, args[1:]...) + + newargs := args + if args[0] != "check" { + newargs = append([]string{args[0], "-v"}, args[1:]...) + } p.stdout.Reset() p.stderr.Reset() diff --git a/internal/test/test.go b/internal/test/test.go index 36c75ac320..9d609f74f5 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -171,8 +171,11 @@ func (h *Helper) DoRun(args []string) error { } else { prog = filepath.Join(h.wd, "testdep"+ExeSuffix) } - newargs := []string{args[0], "-v"} - newargs = append(newargs, args[1:]...) + newargs := args + if args[0] != "check" { + newargs = append([]string{args[0], "-v"}, args[1:]...) + } + cmd := exec.Command(prog, newargs...) h.stdout.Reset() h.stderr.Reset() From 26fced190965df2d9b82fb2a98e5f876bdec7aa4 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Fri, 20 Jul 2018 17:05:08 -0700 Subject: [PATCH 05/12] dep: Add harness tests for dep check --- .../check/excess_inputs/final/Gopkg.lock | 12 ++++++++++++ .../check/excess_inputs/final/Gopkg.toml | 0 .../check/excess_inputs/initial/Gopkg.lock | 12 ++++++++++++ .../check/excess_inputs/initial/Gopkg.toml | 0 .../check/excess_inputs/initial/main.go | 12 ++++++++++++ .../check/excess_inputs/stdout.txt | 3 +++ .../check/excess_inputs/testcase.json | 7 +++++++ .../check/hash_mismatch/final/Gopkg.lock | 17 +++++++++++++++++ .../check/hash_mismatch/final/Gopkg.toml | 0 .../check/hash_mismatch/initial/Gopkg.lock | 17 +++++++++++++++++ .../check/hash_mismatch/initial/Gopkg.toml | 0 .../check/hash_mismatch/initial/main.go | 12 ++++++++++++ .../github.com/sdboyer/deptest/deptest.go | 3 +++ .../check/hash_mismatch/stdout.txt | 2 ++ .../check/hash_mismatch/testcase.json | 9 +++++++++ .../hash_version_mismatch/final/Gopkg.lock | 17 +++++++++++++++++ .../hash_version_mismatch/final/Gopkg.toml | 0 .../hash_version_mismatch/initial/Gopkg.lock | 17 +++++++++++++++++ .../hash_version_mismatch/initial/Gopkg.toml | 0 .../check/hash_version_mismatch/initial/main.go | 12 ++++++++++++ .../github.com/sdboyer/deptest/deptest.go | 3 +++ .../check/hash_version_mismatch/stdout.txt | 2 ++ .../check/hash_version_mismatch/testcase.json | 9 +++++++++ .../check/missing_and_excess/final/Gopkg.lock | 9 +++++++++ .../check/missing_and_excess/final/Gopkg.toml | 0 .../check/missing_and_excess/initial/Gopkg.lock | 9 +++++++++ .../check/missing_and_excess/initial/Gopkg.toml | 0 .../check/missing_and_excess/initial/main.go | 12 ++++++++++++ .../check/missing_and_excess/stdout.txt | 4 ++++ .../check/missing_and_excess/testcase.json | 7 +++++++ .../check/missing_inputs/final/Gopkg.lock | 9 +++++++++ .../check/missing_inputs/final/Gopkg.toml | 0 .../check/missing_inputs/initial/Gopkg.lock | 9 +++++++++ .../check/missing_inputs/initial/Gopkg.toml | 0 .../check/missing_inputs/initial/main.go | 12 ++++++++++++ .../check/missing_inputs/stdout.txt | 3 +++ .../check/missing_inputs/testcase.json | 7 +++++++ .../check/unmet_constraint/final/Gopkg.lock | 17 +++++++++++++++++ .../check/unmet_constraint/final/Gopkg.toml | 3 +++ .../check/unmet_constraint/initial/Gopkg.lock | 17 +++++++++++++++++ .../check/unmet_constraint/initial/Gopkg.toml | 3 +++ .../check/unmet_constraint/initial/main.go | 12 ++++++++++++ .../check/unmet_constraint/stdout.txt | 5 +++++ .../check/unmet_constraint/testcase.json | 7 +++++++ .../check/unmet_override/final/Gopkg.lock | 17 +++++++++++++++++ .../check/unmet_override/final/Gopkg.toml | 3 +++ .../check/unmet_override/initial/Gopkg.lock | 17 +++++++++++++++++ .../check/unmet_override/initial/Gopkg.toml | 3 +++ .../check/unmet_override/initial/main.go | 12 ++++++++++++ .../check/unmet_override/stdout.txt | 5 +++++ .../check/unmet_override/testcase.json | 7 +++++++ .../check/vendororphans/final/Gopkg.lock | 17 +++++++++++++++++ .../check/vendororphans/final/Gopkg.toml | 0 .../check/vendororphans/initial/Gopkg.lock | 17 +++++++++++++++++ .../check/vendororphans/initial/Gopkg.toml | 0 .../check/vendororphans/initial/main.go | 12 ++++++++++++ .../check/vendororphans/initial/vendor/foo | 0 .../github.com/sdboyer/deptest/deptest.go | 3 +++ .../check/vendororphans/stdout.txt | 3 +++ .../check/vendororphans/testcase.json | 9 +++++++++ 60 files changed, 436 insertions(+) create mode 100644 cmd/dep/testdata/harness_tests/check/excess_inputs/final/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/excess_inputs/final/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/excess_inputs/initial/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/excess_inputs/initial/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/excess_inputs/initial/main.go create mode 100644 cmd/dep/testdata/harness_tests/check/excess_inputs/stdout.txt create mode 100644 cmd/dep/testdata/harness_tests/check/excess_inputs/testcase.json create mode 100644 cmd/dep/testdata/harness_tests/check/hash_mismatch/final/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/hash_mismatch/final/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/main.go create mode 100644 cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/vendor/github.com/sdboyer/deptest/deptest.go create mode 100644 cmd/dep/testdata/harness_tests/check/hash_mismatch/stdout.txt create mode 100644 cmd/dep/testdata/harness_tests/check/hash_mismatch/testcase.json create mode 100644 cmd/dep/testdata/harness_tests/check/hash_version_mismatch/final/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/hash_version_mismatch/final/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/main.go create mode 100644 cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/vendor/github.com/sdboyer/deptest/deptest.go create mode 100644 cmd/dep/testdata/harness_tests/check/hash_version_mismatch/stdout.txt create mode 100644 cmd/dep/testdata/harness_tests/check/hash_version_mismatch/testcase.json create mode 100644 cmd/dep/testdata/harness_tests/check/missing_and_excess/final/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/missing_and_excess/final/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/missing_and_excess/initial/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/missing_and_excess/initial/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/missing_and_excess/initial/main.go create mode 100644 cmd/dep/testdata/harness_tests/check/missing_and_excess/stdout.txt create mode 100644 cmd/dep/testdata/harness_tests/check/missing_and_excess/testcase.json create mode 100644 cmd/dep/testdata/harness_tests/check/missing_inputs/final/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/missing_inputs/final/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/missing_inputs/initial/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/missing_inputs/initial/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/missing_inputs/initial/main.go create mode 100644 cmd/dep/testdata/harness_tests/check/missing_inputs/stdout.txt create mode 100644 cmd/dep/testdata/harness_tests/check/missing_inputs/testcase.json create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_constraint/final/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_constraint/final/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_constraint/initial/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_constraint/initial/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_constraint/initial/main.go create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_constraint/stdout.txt create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_constraint/testcase.json create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_override/final/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_override/final/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_override/initial/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_override/initial/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_override/initial/main.go create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_override/stdout.txt create mode 100644 cmd/dep/testdata/harness_tests/check/unmet_override/testcase.json create mode 100644 cmd/dep/testdata/harness_tests/check/vendororphans/final/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/vendororphans/final/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/vendororphans/initial/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/check/vendororphans/initial/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/check/vendororphans/initial/main.go create mode 100644 cmd/dep/testdata/harness_tests/check/vendororphans/initial/vendor/foo create mode 100644 cmd/dep/testdata/harness_tests/check/vendororphans/initial/vendor/github.com/sdboyer/deptest/deptest.go create mode 100644 cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt create mode 100644 cmd/dep/testdata/harness_tests/check/vendororphans/testcase.json diff --git a/cmd/dep/testdata/harness_tests/check/excess_inputs/final/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/excess_inputs/final/Gopkg.lock new file mode 100644 index 0000000000..4951912e22 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/excess_inputs/final/Gopkg.lock @@ -0,0 +1,12 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = [ + "github.com/sdboyer/deptest", + "github.com/sdboyer/deptestdos", + ] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/excess_inputs/final/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/excess_inputs/final/Gopkg.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/excess_inputs/initial/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/excess_inputs/initial/Gopkg.lock new file mode 100644 index 0000000000..4951912e22 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/excess_inputs/initial/Gopkg.lock @@ -0,0 +1,12 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = [ + "github.com/sdboyer/deptest", + "github.com/sdboyer/deptestdos", + ] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/excess_inputs/initial/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/excess_inputs/initial/Gopkg.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/excess_inputs/initial/main.go b/cmd/dep/testdata/harness_tests/check/excess_inputs/initial/main.go new file mode 100644 index 0000000000..6fa0454844 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/excess_inputs/initial/main.go @@ -0,0 +1,12 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + _ "github.com/sdboyer/deptestdos" +) + +func main() { +} diff --git a/cmd/dep/testdata/harness_tests/check/excess_inputs/stdout.txt b/cmd/dep/testdata/harness_tests/check/excess_inputs/stdout.txt new file mode 100644 index 0000000000..34df017e42 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/excess_inputs/stdout.txt @@ -0,0 +1,3 @@ +# Gopkg.lock is out of sync: +github.com/sdboyer/deptest: in input-imports, but not imported + diff --git a/cmd/dep/testdata/harness_tests/check/excess_inputs/testcase.json b/cmd/dep/testdata/harness_tests/check/excess_inputs/testcase.json new file mode 100644 index 0000000000..fd92987e3e --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/excess_inputs/testcase.json @@ -0,0 +1,7 @@ +{ + "commands": [ + ["check"] + ], + "exit-code": 1, + "vendor-final": [] +} diff --git a/cmd/dep/testdata/harness_tests/check/hash_mismatch/final/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/hash_mismatch/final/Gopkg.lock new file mode 100644 index 0000000000..b8c274bb71 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/hash_mismatch/final/Gopkg.lock @@ -0,0 +1,17 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:ddbbbe7f7a81c86d54e89fa388b532f4c144d666a14e8e483ba04fa58265a246" + name = "github.com/sdboyer/deptest" + packages = ["."] + pruneopts = "" + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sdboyer/deptest"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/hash_mismatch/final/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/hash_mismatch/final/Gopkg.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/Gopkg.lock new file mode 100644 index 0000000000..b8c274bb71 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/Gopkg.lock @@ -0,0 +1,17 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:ddbbbe7f7a81c86d54e89fa388b532f4c144d666a14e8e483ba04fa58265a246" + name = "github.com/sdboyer/deptest" + packages = ["."] + pruneopts = "" + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sdboyer/deptest"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/Gopkg.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/main.go b/cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/main.go new file mode 100644 index 0000000000..e23fcf34c5 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/main.go @@ -0,0 +1,12 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + _ "github.com/sdboyer/deptest" +) + +func main() { +} diff --git a/cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/vendor/github.com/sdboyer/deptest/deptest.go b/cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/vendor/github.com/sdboyer/deptest/deptest.go new file mode 100644 index 0000000000..89983b5a33 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/hash_mismatch/initial/vendor/github.com/sdboyer/deptest/deptest.go @@ -0,0 +1,3 @@ +package deptest + +type Foo int diff --git a/cmd/dep/testdata/harness_tests/check/hash_mismatch/stdout.txt b/cmd/dep/testdata/harness_tests/check/hash_mismatch/stdout.txt new file mode 100644 index 0000000000..9292138cf8 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/hash_mismatch/stdout.txt @@ -0,0 +1,2 @@ +# vendor is out of sync: +vendor/github.com/sdboyer/deptest: hash of vendored tree didn't match digest in Gopkg.lock diff --git a/cmd/dep/testdata/harness_tests/check/hash_mismatch/testcase.json b/cmd/dep/testdata/harness_tests/check/hash_mismatch/testcase.json new file mode 100644 index 0000000000..2e39b365e9 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/hash_mismatch/testcase.json @@ -0,0 +1,9 @@ +{ + "commands": [ + ["check"] + ], + "exit-code": 1, + "vendor-final": [ + "github.com/sdboyer/deptest" + ] +} diff --git a/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/final/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/final/Gopkg.lock new file mode 100644 index 0000000000..737268f3ea --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/final/Gopkg.lock @@ -0,0 +1,17 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "2:ddbbbe7f7a81c86d54e89fa388b532f4c144d666a14e8e483ba04fa58265a246" + name = "github.com/sdboyer/deptest" + packages = ["."] + pruneopts = "" + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sdboyer/deptest"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/final/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/final/Gopkg.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/Gopkg.lock new file mode 100644 index 0000000000..737268f3ea --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/Gopkg.lock @@ -0,0 +1,17 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "2:ddbbbe7f7a81c86d54e89fa388b532f4c144d666a14e8e483ba04fa58265a246" + name = "github.com/sdboyer/deptest" + packages = ["."] + pruneopts = "" + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sdboyer/deptest"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/Gopkg.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/main.go b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/main.go new file mode 100644 index 0000000000..e23fcf34c5 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/main.go @@ -0,0 +1,12 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + _ "github.com/sdboyer/deptest" +) + +func main() { +} diff --git a/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/vendor/github.com/sdboyer/deptest/deptest.go b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/vendor/github.com/sdboyer/deptest/deptest.go new file mode 100644 index 0000000000..89983b5a33 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/initial/vendor/github.com/sdboyer/deptest/deptest.go @@ -0,0 +1,3 @@ +package deptest + +type Foo int diff --git a/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/stdout.txt b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/stdout.txt new file mode 100644 index 0000000000..249a4ab408 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/stdout.txt @@ -0,0 +1,2 @@ +# vendor is out of sync: +vendor/github.com/sdboyer/deptest: hash algorithm mismatch, want version 1 diff --git a/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/testcase.json b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/testcase.json new file mode 100644 index 0000000000..2e39b365e9 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/testcase.json @@ -0,0 +1,9 @@ +{ + "commands": [ + ["check"] + ], + "exit-code": 1, + "vendor-final": [ + "github.com/sdboyer/deptest" + ] +} diff --git a/cmd/dep/testdata/harness_tests/check/missing_and_excess/final/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/missing_and_excess/final/Gopkg.lock new file mode 100644 index 0000000000..e774210e9d --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/missing_and_excess/final/Gopkg.lock @@ -0,0 +1,9 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sdboyer/deptest"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/missing_and_excess/final/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/missing_and_excess/final/Gopkg.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/missing_and_excess/initial/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/missing_and_excess/initial/Gopkg.lock new file mode 100644 index 0000000000..e774210e9d --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/missing_and_excess/initial/Gopkg.lock @@ -0,0 +1,9 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sdboyer/deptest"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/missing_and_excess/initial/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/missing_and_excess/initial/Gopkg.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/missing_and_excess/initial/main.go b/cmd/dep/testdata/harness_tests/check/missing_and_excess/initial/main.go new file mode 100644 index 0000000000..6fa0454844 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/missing_and_excess/initial/main.go @@ -0,0 +1,12 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + _ "github.com/sdboyer/deptestdos" +) + +func main() { +} diff --git a/cmd/dep/testdata/harness_tests/check/missing_and_excess/stdout.txt b/cmd/dep/testdata/harness_tests/check/missing_and_excess/stdout.txt new file mode 100644 index 0000000000..21fc38bbcc --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/missing_and_excess/stdout.txt @@ -0,0 +1,4 @@ +# Gopkg.lock is out of sync: +github.com/sdboyer/deptestdos: missing from input-imports +github.com/sdboyer/deptest: in input-imports, but not imported + diff --git a/cmd/dep/testdata/harness_tests/check/missing_and_excess/testcase.json b/cmd/dep/testdata/harness_tests/check/missing_and_excess/testcase.json new file mode 100644 index 0000000000..fd92987e3e --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/missing_and_excess/testcase.json @@ -0,0 +1,7 @@ +{ + "commands": [ + ["check"] + ], + "exit-code": 1, + "vendor-final": [] +} diff --git a/cmd/dep/testdata/harness_tests/check/missing_inputs/final/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/missing_inputs/final/Gopkg.lock new file mode 100644 index 0000000000..10ef811182 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/missing_inputs/final/Gopkg.lock @@ -0,0 +1,9 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = [] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/missing_inputs/final/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/missing_inputs/final/Gopkg.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/missing_inputs/initial/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/missing_inputs/initial/Gopkg.lock new file mode 100644 index 0000000000..10ef811182 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/missing_inputs/initial/Gopkg.lock @@ -0,0 +1,9 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = [] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/missing_inputs/initial/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/missing_inputs/initial/Gopkg.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/missing_inputs/initial/main.go b/cmd/dep/testdata/harness_tests/check/missing_inputs/initial/main.go new file mode 100644 index 0000000000..6fa0454844 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/missing_inputs/initial/main.go @@ -0,0 +1,12 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + _ "github.com/sdboyer/deptestdos" +) + +func main() { +} diff --git a/cmd/dep/testdata/harness_tests/check/missing_inputs/stdout.txt b/cmd/dep/testdata/harness_tests/check/missing_inputs/stdout.txt new file mode 100644 index 0000000000..69e29c9d8e --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/missing_inputs/stdout.txt @@ -0,0 +1,3 @@ +# Gopkg.lock is out of sync: +github.com/sdboyer/deptestdos: missing from input-imports + diff --git a/cmd/dep/testdata/harness_tests/check/missing_inputs/testcase.json b/cmd/dep/testdata/harness_tests/check/missing_inputs/testcase.json new file mode 100644 index 0000000000..fd92987e3e --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/missing_inputs/testcase.json @@ -0,0 +1,7 @@ +{ + "commands": [ + ["check"] + ], + "exit-code": 1, + "vendor-final": [] +} diff --git a/cmd/dep/testdata/harness_tests/check/unmet_constraint/final/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/unmet_constraint/final/Gopkg.lock new file mode 100644 index 0000000000..188ece4f77 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_constraint/final/Gopkg.lock @@ -0,0 +1,17 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:ddbbbe7f7a81c86d54e89fa388b532f4c144d666a14e8e483ba04fa58265b135" + name = "github.com/sdboyer/deptest" + packages = ["."] + pruneopts = "" + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sdboyer/deptest"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/unmet_constraint/final/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/unmet_constraint/final/Gopkg.toml new file mode 100644 index 0000000000..6e1c497df5 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_constraint/final/Gopkg.toml @@ -0,0 +1,3 @@ +[[constraint]] + name = "github.com/sdboyer/deptest" + branch = "master" diff --git a/cmd/dep/testdata/harness_tests/check/unmet_constraint/initial/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/unmet_constraint/initial/Gopkg.lock new file mode 100644 index 0000000000..188ece4f77 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_constraint/initial/Gopkg.lock @@ -0,0 +1,17 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:ddbbbe7f7a81c86d54e89fa388b532f4c144d666a14e8e483ba04fa58265b135" + name = "github.com/sdboyer/deptest" + packages = ["."] + pruneopts = "" + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sdboyer/deptest"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/unmet_constraint/initial/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/unmet_constraint/initial/Gopkg.toml new file mode 100644 index 0000000000..6e1c497df5 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_constraint/initial/Gopkg.toml @@ -0,0 +1,3 @@ +[[constraint]] + name = "github.com/sdboyer/deptest" + branch = "master" diff --git a/cmd/dep/testdata/harness_tests/check/unmet_constraint/initial/main.go b/cmd/dep/testdata/harness_tests/check/unmet_constraint/initial/main.go new file mode 100644 index 0000000000..e23fcf34c5 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_constraint/initial/main.go @@ -0,0 +1,12 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + _ "github.com/sdboyer/deptest" +) + +func main() { +} diff --git a/cmd/dep/testdata/harness_tests/check/unmet_constraint/stdout.txt b/cmd/dep/testdata/harness_tests/check/unmet_constraint/stdout.txt new file mode 100644 index 0000000000..f5f4d7c66c --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_constraint/stdout.txt @@ -0,0 +1,5 @@ +# Gopkg.lock is out of sync: +github.com/sdboyer/deptest@v1.0.0: not allowed by constraint master + +# vendor is out of sync: +vendor/github.com/sdboyer/deptest: missing from vendor diff --git a/cmd/dep/testdata/harness_tests/check/unmet_constraint/testcase.json b/cmd/dep/testdata/harness_tests/check/unmet_constraint/testcase.json new file mode 100644 index 0000000000..fd92987e3e --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_constraint/testcase.json @@ -0,0 +1,7 @@ +{ + "commands": [ + ["check"] + ], + "exit-code": 1, + "vendor-final": [] +} diff --git a/cmd/dep/testdata/harness_tests/check/unmet_override/final/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/unmet_override/final/Gopkg.lock new file mode 100644 index 0000000000..188ece4f77 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_override/final/Gopkg.lock @@ -0,0 +1,17 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:ddbbbe7f7a81c86d54e89fa388b532f4c144d666a14e8e483ba04fa58265b135" + name = "github.com/sdboyer/deptest" + packages = ["."] + pruneopts = "" + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sdboyer/deptest"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/unmet_override/final/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/unmet_override/final/Gopkg.toml new file mode 100644 index 0000000000..66a88c9a8a --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_override/final/Gopkg.toml @@ -0,0 +1,3 @@ +[[override]] + name = "github.com/sdboyer/deptest" + branch = "master" diff --git a/cmd/dep/testdata/harness_tests/check/unmet_override/initial/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/unmet_override/initial/Gopkg.lock new file mode 100644 index 0000000000..188ece4f77 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_override/initial/Gopkg.lock @@ -0,0 +1,17 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:ddbbbe7f7a81c86d54e89fa388b532f4c144d666a14e8e483ba04fa58265b135" + name = "github.com/sdboyer/deptest" + packages = ["."] + pruneopts = "" + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sdboyer/deptest"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/unmet_override/initial/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/unmet_override/initial/Gopkg.toml new file mode 100644 index 0000000000..66a88c9a8a --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_override/initial/Gopkg.toml @@ -0,0 +1,3 @@ +[[override]] + name = "github.com/sdboyer/deptest" + branch = "master" diff --git a/cmd/dep/testdata/harness_tests/check/unmet_override/initial/main.go b/cmd/dep/testdata/harness_tests/check/unmet_override/initial/main.go new file mode 100644 index 0000000000..e23fcf34c5 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_override/initial/main.go @@ -0,0 +1,12 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + _ "github.com/sdboyer/deptest" +) + +func main() { +} diff --git a/cmd/dep/testdata/harness_tests/check/unmet_override/stdout.txt b/cmd/dep/testdata/harness_tests/check/unmet_override/stdout.txt new file mode 100644 index 0000000000..bbe870a9c0 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_override/stdout.txt @@ -0,0 +1,5 @@ +# Gopkg.lock is out of sync: +github.com/sdboyer/deptest@v1.0.0: not allowed by override master + +# vendor is out of sync: +vendor/github.com/sdboyer/deptest: missing from vendor diff --git a/cmd/dep/testdata/harness_tests/check/unmet_override/testcase.json b/cmd/dep/testdata/harness_tests/check/unmet_override/testcase.json new file mode 100644 index 0000000000..fd92987e3e --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/unmet_override/testcase.json @@ -0,0 +1,7 @@ +{ + "commands": [ + ["check"] + ], + "exit-code": 1, + "vendor-final": [] +} diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/final/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/vendororphans/final/Gopkg.lock new file mode 100644 index 0000000000..188ece4f77 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/vendororphans/final/Gopkg.lock @@ -0,0 +1,17 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:ddbbbe7f7a81c86d54e89fa388b532f4c144d666a14e8e483ba04fa58265b135" + name = "github.com/sdboyer/deptest" + packages = ["."] + pruneopts = "" + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sdboyer/deptest"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/final/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/vendororphans/final/Gopkg.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/initial/Gopkg.lock b/cmd/dep/testdata/harness_tests/check/vendororphans/initial/Gopkg.lock new file mode 100644 index 0000000000..188ece4f77 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/vendororphans/initial/Gopkg.lock @@ -0,0 +1,17 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:ddbbbe7f7a81c86d54e89fa388b532f4c144d666a14e8e483ba04fa58265b135" + name = "github.com/sdboyer/deptest" + packages = ["."] + pruneopts = "" + revision = "ff2948a2ac8f538c4ecd55962e919d1e13e74baf" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sdboyer/deptest"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/initial/Gopkg.toml b/cmd/dep/testdata/harness_tests/check/vendororphans/initial/Gopkg.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/initial/main.go b/cmd/dep/testdata/harness_tests/check/vendororphans/initial/main.go new file mode 100644 index 0000000000..e23fcf34c5 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/vendororphans/initial/main.go @@ -0,0 +1,12 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + _ "github.com/sdboyer/deptest" +) + +func main() { +} diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/initial/vendor/foo b/cmd/dep/testdata/harness_tests/check/vendororphans/initial/vendor/foo new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/initial/vendor/github.com/sdboyer/deptest/deptest.go b/cmd/dep/testdata/harness_tests/check/vendororphans/initial/vendor/github.com/sdboyer/deptest/deptest.go new file mode 100644 index 0000000000..89983b5a33 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/vendororphans/initial/vendor/github.com/sdboyer/deptest/deptest.go @@ -0,0 +1,3 @@ +package deptest + +type Foo int diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt b/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt new file mode 100644 index 0000000000..f43f9d6018 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt @@ -0,0 +1,3 @@ +# vendor is out of sync: +vendor/orphdir: unused project +vendor/foo: orphaned file diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/testcase.json b/cmd/dep/testdata/harness_tests/check/vendororphans/testcase.json new file mode 100644 index 0000000000..2e39b365e9 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/check/vendororphans/testcase.json @@ -0,0 +1,9 @@ +{ + "commands": [ + ["check"] + ], + "exit-code": 1, + "vendor-final": [ + "github.com/sdboyer/deptest" + ] +} From 2c0659e7dbed0307fe3df427f3c9c360b7591f23 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Fri, 20 Jul 2018 17:07:37 -0700 Subject: [PATCH 06/12] check: Include vendor/ in path output --- cmd/dep/check.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/dep/check.go b/cmd/dep/check.go index 7266ddb8bf..c921ccdd97 100644 --- a/cmd/dep/check.go +++ b/cmd/dep/check.go @@ -132,27 +132,28 @@ func (cmd *checkCommand) Run(ctx *dep.Ctx, args []string) error { } for pr, status := range statuses { + vpr := filepath.Join("vendor", string(pr)) switch status { case verify.NotInTree: - logger.Printf("%s: missing from vendor\n", pr) + logger.Printf("%s: missing from vendor\n", vpr) case verify.NotInLock: - fi, err := os.Stat(filepath.Join(p.AbsRoot, "vendor", pr)) + fi, err := os.Stat(filepath.Join(p.AbsRoot, vpr)) if err != nil { return errors.Wrap(err, "could not stat file that VerifyVendor claimed existed") } if fi.IsDir() { - logger.Printf("%s: unused project\n", pr) + logger.Printf("%s: unused project\n", vpr) } else { - logger.Printf("%s: orphaned file\n", pr) + logger.Printf("%s: orphaned file\n", vpr) } case verify.DigestMismatchInLock: - logger.Printf("%s: hash of vendored tree didn't match digest in Gopkg.lock\n", pr) + logger.Printf("%s: hash of vendored tree didn't match digest in Gopkg.lock\n", vpr) case verify.HashVersionMismatch: // This will double-print if the hash version is zero, but // that's a rare case that really only occurs before the first // run with a version of dep >=0.5.0, so it's fine. - logger.Printf("%s: hash algorithm mismatch, want version %v\n", pr, verify.HashVersion) + logger.Printf("%s: hash algorithm mismatch, want version %v\n", vpr, verify.HashVersion) } } } From 354108c3b0ee082d6d2343d2e99765101ad63f5d Mon Sep 17 00:00:00 2001 From: sam boyer Date: Fri, 20 Jul 2018 17:08:54 -0700 Subject: [PATCH 07/12] dep: Make SafeWriter use status map for OnChanged If vendor was empty, nonexistent, or just missing a few targeted items, the SafeWriter would miss them. --- cmd/dep/ensure.go | 2 +- cmd/dep/init.go | 2 +- txn_writer.go | 17 ++++++++++++++--- txn_writer_test.go | 28 ++++++++++++++-------------- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/cmd/dep/ensure.go b/cmd/dep/ensure.go index 23015ed71f..b6fbf963f1 100644 --- a/cmd/dep/ensure.go +++ b/cmd/dep/ensure.go @@ -316,7 +316,7 @@ func (cmd *ensureCommand) runVendorOnly(ctx *dep.Ctx, args []string, p *dep.Proj // Pass the same lock as old and new so that the writer will observe no // difference, and write out only ncessary vendor/ changes. - dw, err := dep.NewSafeWriter(nil, p.Lock, p.Lock, dep.VendorAlways, p.Manifest.PruneOptions) + dw, err := dep.NewSafeWriter(nil, p.Lock, p.Lock, dep.VendorAlways, p.Manifest.PruneOptions, nil) //dw, err := dep.NewDeltaWriter(p.Lock, p.Lock, p.Manifest.PruneOptions, filepath.Join(p.AbsRoot, "vendor"), dep.VendorAlways) if err != nil { return err diff --git a/cmd/dep/init.go b/cmd/dep/init.go index c50d82cbf0..70df59fb90 100644 --- a/cmd/dep/init.go +++ b/cmd/dep/init.go @@ -170,7 +170,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error { ctx.Err.Printf("Old vendor backed up to %v", vendorbak) } - sw, err := dep.NewSafeWriter(p.Manifest, nil, p.Lock, dep.VendorAlways, p.Manifest.PruneOptions) + sw, err := dep.NewSafeWriter(p.Manifest, nil, p.Lock, dep.VendorAlways, p.Manifest.PruneOptions, nil) if err != nil { return errors.Wrap(err, "init failed: unable to create a SafeWriter") } diff --git a/txn_writer.go b/txn_writer.go index 5df2f26047..c03ed4956b 100644 --- a/txn_writer.go +++ b/txn_writer.go @@ -90,7 +90,7 @@ type SafeWriter struct { // - If oldLock is provided without newLock, error. // // - If vendor is VendorAlways without a newLock, error. -func NewSafeWriter(manifest *Manifest, oldLock, newLock *Lock, vendor VendorBehavior, prune gps.CascadingPruneOptions) (*SafeWriter, error) { +func NewSafeWriter(manifest *Manifest, oldLock, newLock *Lock, vendor VendorBehavior, prune gps.CascadingPruneOptions, status map[string]verify.VendorStatus) (*SafeWriter, error) { sw := &SafeWriter{ Manifest: manifest, lock: newLock, @@ -114,7 +114,18 @@ func NewSafeWriter(manifest *Manifest, oldLock, newLock *Lock, vendor VendorBeha case VendorAlways: sw.writeVendor = true case VendorOnChanged: - sw.writeVendor = sw.lockDiff.Changed(anyExceptHash & ^verify.InputImportsChanged) || (newLock != nil && oldLock == nil) + if newLock != nil && oldLock == nil { + sw.writeVendor = true + } else if sw.lockDiff.Changed(anyExceptHash & ^verify.InputImportsChanged) { + sw.writeVendor = true + } else { + for _, stat := range status { + if stat != verify.NoMismatch { + sw.writeVendor = true + break + } + } + } } if sw.writeVendor && newLock == nil { @@ -442,7 +453,7 @@ func NewDeltaWriter(oldLock, newLock *Lock, status map[string]verify.VendorStatu if err != nil && os.IsNotExist(err) { // Provided dir does not exist, so there's no disk contents to compare // against. Fall back to the old SafeWriter. - return NewSafeWriter(nil, oldLock, newLock, behavior, prune) + return NewSafeWriter(nil, oldLock, newLock, behavior, prune, status) } sw.lockDiff = verify.DiffLocks(oldLock, newLock) diff --git a/txn_writer_test.go b/txn_writer_test.go index 0c213edb6d..201021d4c6 100644 --- a/txn_writer_test.go +++ b/txn_writer_test.go @@ -33,7 +33,7 @@ func TestSafeWriter_BadInput_MissingRoot(t *testing.T) { pc := NewTestProjectContext(h, safeWriterProject) defer pc.Release() - sw, _ := NewSafeWriter(nil, nil, nil, VendorOnChanged, defaultCascadingPruneOptions()) + sw, _ := NewSafeWriter(nil, nil, nil, VendorOnChanged, defaultCascadingPruneOptions(), nil) err := sw.Write("", pc.SourceManager, true, nil) if err == nil { @@ -51,7 +51,7 @@ func TestSafeWriter_BadInput_MissingSourceManager(t *testing.T) { pc.CopyFile(LockName, safeWriterGoldenLock) pc.Load() - sw, _ := NewSafeWriter(nil, nil, pc.Project.Lock, VendorAlways, defaultCascadingPruneOptions()) + sw, _ := NewSafeWriter(nil, nil, pc.Project.Lock, VendorAlways, defaultCascadingPruneOptions(), nil) err := sw.Write(pc.Project.AbsRoot, nil, true, nil) if err == nil { @@ -67,7 +67,7 @@ func TestSafeWriter_BadInput_ForceVendorMissingLock(t *testing.T) { pc := NewTestProjectContext(h, safeWriterProject) defer pc.Release() - _, err := NewSafeWriter(nil, nil, nil, VendorAlways, defaultCascadingPruneOptions()) + _, err := NewSafeWriter(nil, nil, nil, VendorAlways, defaultCascadingPruneOptions(), nil) if err == nil { t.Fatal("should have errored without a lock when forceVendor is true, but did not") } else if !strings.Contains(err.Error(), "newLock") { @@ -83,7 +83,7 @@ func TestSafeWriter_BadInput_OldLockOnly(t *testing.T) { pc.CopyFile(LockName, safeWriterGoldenLock) pc.Load() - _, err := NewSafeWriter(nil, pc.Project.Lock, nil, VendorAlways, defaultCascadingPruneOptions()) + _, err := NewSafeWriter(nil, pc.Project.Lock, nil, VendorAlways, defaultCascadingPruneOptions(), nil) if err == nil { t.Fatal("should have errored with only an old lock, but did not") } else if !strings.Contains(err.Error(), "oldLock") { @@ -97,7 +97,7 @@ func TestSafeWriter_BadInput_NonexistentRoot(t *testing.T) { pc := NewTestProjectContext(h, safeWriterProject) defer pc.Release() - sw, _ := NewSafeWriter(nil, nil, nil, VendorOnChanged, defaultCascadingPruneOptions()) + sw, _ := NewSafeWriter(nil, nil, nil, VendorOnChanged, defaultCascadingPruneOptions(), nil) missingroot := filepath.Join(pc.Project.AbsRoot, "nonexistent") err := sw.Write(missingroot, pc.SourceManager, true, nil) @@ -115,7 +115,7 @@ func TestSafeWriter_BadInput_RootIsFile(t *testing.T) { pc := NewTestProjectContext(h, safeWriterProject) defer pc.Release() - sw, _ := NewSafeWriter(nil, nil, nil, VendorOnChanged, defaultCascadingPruneOptions()) + sw, _ := NewSafeWriter(nil, nil, nil, VendorOnChanged, defaultCascadingPruneOptions(), nil) fileroot := pc.CopyFile("fileroot", "txn_writer/badinput_fileroot") err := sw.Write(fileroot, pc.SourceManager, true, nil) @@ -139,7 +139,7 @@ func TestSafeWriter_Manifest(t *testing.T) { pc.CopyFile(ManifestName, safeWriterGoldenManifest) pc.Load() - sw, _ := NewSafeWriter(pc.Project.Manifest, nil, nil, VendorOnChanged, defaultCascadingPruneOptions()) + sw, _ := NewSafeWriter(pc.Project.Manifest, nil, nil, VendorOnChanged, defaultCascadingPruneOptions(), nil) // Verify prepared actions if !sw.HasManifest() { @@ -181,7 +181,7 @@ func TestSafeWriter_ManifestAndUnmodifiedLock(t *testing.T) { pc.CopyFile(LockName, safeWriterGoldenLock) pc.Load() - sw, _ := NewSafeWriter(pc.Project.Manifest, pc.Project.Lock, pc.Project.Lock, VendorOnChanged, defaultCascadingPruneOptions()) + sw, _ := NewSafeWriter(pc.Project.Manifest, pc.Project.Lock, pc.Project.Lock, VendorOnChanged, defaultCascadingPruneOptions(), nil) // Verify prepared actions if !sw.HasManifest() { @@ -226,7 +226,7 @@ func TestSafeWriter_ManifestAndUnmodifiedLockWithForceVendor(t *testing.T) { pc.CopyFile(LockName, safeWriterGoldenLock) pc.Load() - sw, _ := NewSafeWriter(pc.Project.Manifest, pc.Project.Lock, pc.Project.Lock, VendorAlways, defaultCascadingPruneOptions()) + sw, _ := NewSafeWriter(pc.Project.Manifest, pc.Project.Lock, pc.Project.Lock, VendorAlways, defaultCascadingPruneOptions(), nil) // Verify prepared actions if !sw.HasManifest() { @@ -273,12 +273,12 @@ func TestSafeWriter_ForceVendorWhenVendorAlreadyExists(t *testing.T) { pc.CopyFile(LockName, safeWriterGoldenLock) pc.Load() - sw, _ := NewSafeWriter(nil, pc.Project.Lock, pc.Project.Lock, VendorAlways, defaultCascadingPruneOptions()) + sw, _ := NewSafeWriter(nil, pc.Project.Lock, pc.Project.Lock, VendorAlways, defaultCascadingPruneOptions(), nil) err := sw.Write(pc.Project.AbsRoot, pc.SourceManager, true, nil) h.Must(errors.Wrap(err, "SafeWriter.Write failed")) // Verify prepared actions - sw, _ = NewSafeWriter(nil, nil, pc.Project.Lock, VendorAlways, defaultCascadingPruneOptions()) + sw, _ = NewSafeWriter(nil, nil, pc.Project.Lock, VendorAlways, defaultCascadingPruneOptions(), nil) if sw.HasManifest() { t.Fatal("Did not expect the payload to contain the manifest") } @@ -325,7 +325,7 @@ func TestSafeWriter_NewLock(t *testing.T) { defer lf.Close() newLock, err := readLock(lf) h.Must(err) - sw, _ := NewSafeWriter(nil, nil, newLock, VendorOnChanged, defaultCascadingPruneOptions()) + sw, _ := NewSafeWriter(nil, nil, newLock, VendorOnChanged, defaultCascadingPruneOptions(), nil) // Verify prepared actions if sw.HasManifest() { @@ -372,7 +372,7 @@ func TestSafeWriter_NewLockSkipVendor(t *testing.T) { defer lf.Close() newLock, err := readLock(lf) h.Must(err) - sw, _ := NewSafeWriter(nil, nil, newLock, VendorNever, defaultCascadingPruneOptions()) + sw, _ := NewSafeWriter(nil, nil, newLock, VendorNever, defaultCascadingPruneOptions(), nil) // Verify prepared actions if sw.HasManifest() { @@ -433,7 +433,7 @@ func TestSafeWriter_VendorDotGitPreservedWithForceVendor(t *testing.T) { pc.CopyFile(LockName, safeWriterGoldenLock) pc.Load() - sw, _ := NewSafeWriter(pc.Project.Manifest, pc.Project.Lock, pc.Project.Lock, VendorAlways, defaultCascadingPruneOptions()) + sw, _ := NewSafeWriter(pc.Project.Manifest, pc.Project.Lock, pc.Project.Lock, VendorAlways, defaultCascadingPruneOptions(), nil) // Verify prepared actions if !sw.HasManifest() { From 3a268596628c4a8b52f273b9940e26b6e8e99b2e Mon Sep 17 00:00:00 2001 From: sam boyer Date: Fri, 20 Jul 2018 17:59:26 -0700 Subject: [PATCH 08/12] check: Stop filepath.Join on vendor paths This is sad, but it's the fastest way to satisfy the test harness running on Windows. --- cmd/dep/check.go | 13 ++++++------- .../harness_tests/check/hash_mismatch/stdout.txt | 2 +- .../check/hash_version_mismatch/stdout.txt | 2 +- .../harness_tests/check/unmet_constraint/stdout.txt | 2 +- .../harness_tests/check/unmet_override/stdout.txt | 2 +- .../harness_tests/check/vendororphans/stdout.txt | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/cmd/dep/check.go b/cmd/dep/check.go index c921ccdd97..7266ddb8bf 100644 --- a/cmd/dep/check.go +++ b/cmd/dep/check.go @@ -132,28 +132,27 @@ func (cmd *checkCommand) Run(ctx *dep.Ctx, args []string) error { } for pr, status := range statuses { - vpr := filepath.Join("vendor", string(pr)) switch status { case verify.NotInTree: - logger.Printf("%s: missing from vendor\n", vpr) + logger.Printf("%s: missing from vendor\n", pr) case verify.NotInLock: - fi, err := os.Stat(filepath.Join(p.AbsRoot, vpr)) + fi, err := os.Stat(filepath.Join(p.AbsRoot, "vendor", pr)) if err != nil { return errors.Wrap(err, "could not stat file that VerifyVendor claimed existed") } if fi.IsDir() { - logger.Printf("%s: unused project\n", vpr) + logger.Printf("%s: unused project\n", pr) } else { - logger.Printf("%s: orphaned file\n", vpr) + logger.Printf("%s: orphaned file\n", pr) } case verify.DigestMismatchInLock: - logger.Printf("%s: hash of vendored tree didn't match digest in Gopkg.lock\n", vpr) + logger.Printf("%s: hash of vendored tree didn't match digest in Gopkg.lock\n", pr) case verify.HashVersionMismatch: // This will double-print if the hash version is zero, but // that's a rare case that really only occurs before the first // run with a version of dep >=0.5.0, so it's fine. - logger.Printf("%s: hash algorithm mismatch, want version %v\n", vpr, verify.HashVersion) + logger.Printf("%s: hash algorithm mismatch, want version %v\n", pr, verify.HashVersion) } } } diff --git a/cmd/dep/testdata/harness_tests/check/hash_mismatch/stdout.txt b/cmd/dep/testdata/harness_tests/check/hash_mismatch/stdout.txt index 9292138cf8..228f5bb24e 100644 --- a/cmd/dep/testdata/harness_tests/check/hash_mismatch/stdout.txt +++ b/cmd/dep/testdata/harness_tests/check/hash_mismatch/stdout.txt @@ -1,2 +1,2 @@ # vendor is out of sync: -vendor/github.com/sdboyer/deptest: hash of vendored tree didn't match digest in Gopkg.lock +github.com/sdboyer/deptest: hash of vendored tree didn't match digest in Gopkg.lock diff --git a/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/stdout.txt b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/stdout.txt index 249a4ab408..49ebb4dd1d 100644 --- a/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/stdout.txt +++ b/cmd/dep/testdata/harness_tests/check/hash_version_mismatch/stdout.txt @@ -1,2 +1,2 @@ # vendor is out of sync: -vendor/github.com/sdboyer/deptest: hash algorithm mismatch, want version 1 +github.com/sdboyer/deptest: hash algorithm mismatch, want version 1 diff --git a/cmd/dep/testdata/harness_tests/check/unmet_constraint/stdout.txt b/cmd/dep/testdata/harness_tests/check/unmet_constraint/stdout.txt index f5f4d7c66c..812ea5afb5 100644 --- a/cmd/dep/testdata/harness_tests/check/unmet_constraint/stdout.txt +++ b/cmd/dep/testdata/harness_tests/check/unmet_constraint/stdout.txt @@ -2,4 +2,4 @@ github.com/sdboyer/deptest@v1.0.0: not allowed by constraint master # vendor is out of sync: -vendor/github.com/sdboyer/deptest: missing from vendor +github.com/sdboyer/deptest: missing from vendor diff --git a/cmd/dep/testdata/harness_tests/check/unmet_override/stdout.txt b/cmd/dep/testdata/harness_tests/check/unmet_override/stdout.txt index bbe870a9c0..9ca5bc93b1 100644 --- a/cmd/dep/testdata/harness_tests/check/unmet_override/stdout.txt +++ b/cmd/dep/testdata/harness_tests/check/unmet_override/stdout.txt @@ -2,4 +2,4 @@ github.com/sdboyer/deptest@v1.0.0: not allowed by override master # vendor is out of sync: -vendor/github.com/sdboyer/deptest: missing from vendor +github.com/sdboyer/deptest: missing from vendor diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt b/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt index f43f9d6018..9400f1efd1 100644 --- a/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt +++ b/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt @@ -1,3 +1,3 @@ # vendor is out of sync: -vendor/orphdir: unused project -vendor/foo: orphaned file +foo: orphaned file +orphdir: unused project From fb3d78141eec9b09c0b3edf93b7d950ef91fd5dc Mon Sep 17 00:00:00 2001 From: sam boyer Date: Fri, 20 Jul 2018 18:08:03 -0700 Subject: [PATCH 09/12] test: .gitkeep the orphan dir --- .../check/vendororphans/initial/vendor/orphdir/.gitkeep | 0 cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 cmd/dep/testdata/harness_tests/check/vendororphans/initial/vendor/orphdir/.gitkeep diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/initial/vendor/orphdir/.gitkeep b/cmd/dep/testdata/harness_tests/check/vendororphans/initial/vendor/orphdir/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt b/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt index 9400f1efd1..95b31587b9 100644 --- a/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt +++ b/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt @@ -1,3 +1,3 @@ # vendor is out of sync: -foo: orphaned file orphdir: unused project +foo: orphaned file From e3ceae31d79d80a5fd7062facbc1a987e547a7bd Mon Sep 17 00:00:00 2001 From: sam boyer Date: Fri, 20 Jul 2018 19:03:48 -0700 Subject: [PATCH 10/12] ci: Use dep check to check dep No more hacky ensure-and-diff-vendor! --- Makefile | 2 +- hack/validate-vendor.bash | 53 --------------------------------------- 2 files changed, 1 insertion(+), 54 deletions(-) delete mode 100755 hack/validate-vendor.bash diff --git a/Makefile b/Makefile index e7a9c41ab2..1c7abf8051 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,8 @@ licenseok: go build -o licenseok ./hack/licenseok/main.go validate: build licenseok + ./dep check ./hack/lint.bash - ./hack/validate-vendor.bash ./hack/validate-licence.bash test: build diff --git a/hack/validate-vendor.bash b/hack/validate-vendor.bash deleted file mode 100755 index d6fb2bf5bc..0000000000 --- a/hack/validate-vendor.bash +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2017 The Go Authors. All rights reserved. -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file. -# -# This script checks if we changed anything with regard to dependency management -# for our repo and makes sure that it was done in a valid way. - -set -e -o pipefail - -if [ -z "$VALIDATE_UPSTREAM" ]; then - VALIDATE_REPO='https://github.com/golang/dep.git' - VALIDATE_BRANCH='master' - - VALIDATE_HEAD="$(git rev-parse --verify HEAD)" - - git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH" - VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)" - - VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD" - - validate_diff() { - if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then - git diff "$VALIDATE_COMMIT_DIFF" "$@" - fi - } -fi - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- 'Gopkg.toml' 'Gopkg.lock' 'vendor/' || true) ) -unset IFS - -if [ ${#files[@]} -gt 0 ]; then - go build ./cmd/dep - ./dep ensure -vendor-only - # Let see if the working directory is clean - diffs="$(git status --porcelain -- vendor Gopkg.toml Gopkg.lock 2>/dev/null)" - if [ "$diffs" ]; then - { - echo 'The contents of vendor differ after "dep ensure":' - echo - echo "$diffs" - echo - echo 'Make sure these commands have been run before committing.' - echo - } >&2 - false - else - echo 'Congratulations! All vendoring changes are done the right way.' - fi -else - echo 'No vendor changes in diff.' -fi From dd5c305180e41db78dcd0a0d8fdcbc939a47710f Mon Sep 17 00:00:00 2001 From: sam boyer Date: Fri, 20 Jul 2018 19:04:31 -0700 Subject: [PATCH 11/12] ci: Don't validate license in testdata dir --- hack/validate-licence.bash | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hack/validate-licence.bash b/hack/validate-licence.bash index 17d0d42594..385a31490b 100755 --- a/hack/validate-licence.bash +++ b/hack/validate-licence.bash @@ -8,5 +8,6 @@ set -e go build -o licenseok ./hack/licenseok/main.go -find . -path ./vendor -prune -o -regex ".+\.pb\.go$" -prune -o -type f -regex ".*\.\(go\|proto\)$"\ - -printf '%P\n' | xargs ./licenseok +find . -path ./vendor -prune -o -path ./cmd/dep/testdata -prune\ + -o -regex ".+\.pb\.go$" -prune -o -type f -regex ".*\.\(go\|proto\)$"\ + -printf '%P\n' | xargs ./licenseok From 683164ac990fabfa671ebad6a0f2f75b1bb1bc9a Mon Sep 17 00:00:00 2001 From: sam boyer Date: Fri, 20 Jul 2018 20:03:24 -0700 Subject: [PATCH 12/12] check: Deterministically order all output --- cmd/dep/check.go | 51 ++++++++++++++++--- .../check/vendororphans/stdout.txt | 2 +- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/cmd/dep/check.go b/cmd/dep/check.go index 7266ddb8bf..10d1213a87 100644 --- a/cmd/dep/check.go +++ b/cmd/dep/check.go @@ -12,6 +12,7 @@ import ( "log" "os" "path/filepath" + "sort" "strings" "github.com/golang/dep" @@ -89,7 +90,15 @@ func (cmd *checkCommand) Run(ctx *dep.Ctx, args []string) error { logger.Printf("%s\n", sprintLockUnsat(lsat)) } if changed { - for pr, lpd := range delta.ProjectDeltas { + // Sort, for deterministic output. + var ordered []string + for pr := range delta.ProjectDeltas { + ordered = append(ordered, string(pr)) + } + sort.Strings(ordered) + + for _, pr := range ordered { + lpd := delta.ProjectDeltas[gps.ProjectRoot(pr)] // Only two possible changes right now are prune opts // changing or a missing hash digest (for old Gopkg.lock // files) @@ -122,16 +131,25 @@ func (cmd *checkCommand) Run(ctx *dep.Ctx, args []string) error { if fail { logger.Println() } - // One full pass through, to see if we need to print the header. - for _, status := range statuses { + + var vendorfail bool + // One full pass through, to see if we need to print the header, and to + // create an array of names to sort for deterministic output. + var ordered []string + for path, status := range statuses { + ordered = append(ordered, path) if status != verify.NoMismatch { fail = true - logger.Println("# vendor is out of sync:") - break + if !vendorfail { + vendorfail = true + logger.Println("# vendor is out of sync:") + } } } + sort.Strings(ordered) - for pr, status := range statuses { + for _, pr := range ordered { + status := statuses[pr] switch status { case verify.NotInTree: logger.Printf("%s: missing from vendor\n", pr) @@ -165,16 +183,33 @@ func (cmd *checkCommand) Run(ctx *dep.Ctx, args []string) error { func sprintLockUnsat(lsat verify.LockSatisfaction) string { var buf bytes.Buffer + sort.Strings(lsat.MissingImports) for _, missing := range lsat.MissingImports { fmt.Fprintf(&buf, "%s: missing from input-imports\n", missing) } + + sort.Strings(lsat.ExcessImports) for _, excess := range lsat.ExcessImports { fmt.Fprintf(&buf, "%s: in input-imports, but not imported\n", excess) } - for pr, unmatched := range lsat.UnmetOverrides { + + var ordered []string + for pr := range lsat.UnmetOverrides { + ordered = append(ordered, string(pr)) + } + sort.Strings(ordered) + for _, pr := range ordered { + unmatched := lsat.UnmetOverrides[gps.ProjectRoot(pr)] fmt.Fprintf(&buf, "%s@%s: not allowed by override %s\n", pr, unmatched.V, unmatched.C) } - for pr, unmatched := range lsat.UnmetConstraints { + + ordered = ordered[:0] + for pr := range lsat.UnmetConstraints { + ordered = append(ordered, string(pr)) + } + sort.Strings(ordered) + for _, pr := range ordered { + unmatched := lsat.UnmetConstraints[gps.ProjectRoot(pr)] fmt.Fprintf(&buf, "%s@%s: not allowed by constraint %s\n", pr, unmatched.V, unmatched.C) } return strings.TrimSpace(buf.String()) diff --git a/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt b/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt index 95b31587b9..9400f1efd1 100644 --- a/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt +++ b/cmd/dep/testdata/harness_tests/check/vendororphans/stdout.txt @@ -1,3 +1,3 @@ # vendor is out of sync: -orphdir: unused project foo: orphaned file +orphdir: unused project