зеркало из https://github.com/golang/dep.git
Merge pull request #1979 from tariq1890/unit_tests
Adding Unit tests to increase coverage Signed-off-by: Tim Heckman <t@heckman.io>
This commit is contained in:
Коммит
e2709bef5f
17
cmd/dep/testdata/harness_tests/check/pruneopts_changed/final/Gopkg.lock
сгенерированный
поставляемый
Normal file
17
cmd/dep/testdata/harness_tests/check/pruneopts_changed/final/Gopkg.lock
сгенерированный
поставляемый
Normal file
|
@ -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
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
[[constraint]]
|
||||
name = "github.com/sdboyer/deptest"
|
||||
version = "1.0.0"
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
17
cmd/dep/testdata/harness_tests/check/pruneopts_changed/initial/Gopkg.lock
сгенерированный
поставляемый
Normal file
17
cmd/dep/testdata/harness_tests/check/pruneopts_changed/initial/Gopkg.lock
сгенерированный
поставляемый
Normal file
|
@ -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
|
8
cmd/dep/testdata/harness_tests/check/pruneopts_changed/initial/Gopkg.toml
поставляемый
Normal file
8
cmd/dep/testdata/harness_tests/check/pruneopts_changed/initial/Gopkg.toml
поставляемый
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
[[constraint]]
|
||||
name = "github.com/sdboyer/deptest"
|
||||
version = "1.0.0"
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2016 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() {
|
||||
err := nil
|
||||
if err != nil {
|
||||
deptest.Map["yo yo!"]
|
||||
}
|
||||
}
|
3
cmd/dep/testdata/harness_tests/check/pruneopts_changed/initial/vendor/github.com/sdboyer/deptest/deptest.go
сгенерированный
поставляемый
Normal file
3
cmd/dep/testdata/harness_tests/check/pruneopts_changed/initial/vendor/github.com/sdboyer/deptest/deptest.go
сгенерированный
поставляемый
Normal file
|
@ -0,0 +1,3 @@
|
|||
package deptest
|
||||
|
||||
type Foo int
|
|
@ -0,0 +1,3 @@
|
|||
# Gopkg.lock is out of sync:
|
||||
github.com/sdboyer/deptest: prune options changed ( -> UT)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"commands": [
|
||||
["check"]
|
||||
],
|
||||
"should-fail": true,
|
||||
"vendor-final": [
|
||||
"github.com/sdboyer/deptest"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
// 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 canonical /* import "vanity1" */
|
||||
|
||||
var (
|
||||
A = "A"
|
||||
)
|
|
@ -0,0 +1,9 @@
|
|||
// 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 canonical /* import "vanity2" */
|
||||
|
||||
var (
|
||||
B = "B"
|
||||
)
|
|
@ -1539,6 +1539,24 @@ func TestListPackages(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
"slash-star": {
|
||||
fileRoot: j("slash-star_confl"),
|
||||
importRoot: "slash-star_confl",
|
||||
out: PackageTree{
|
||||
ImportRoot: "slash-star_confl",
|
||||
Packages: map[string]PackageOrErr{
|
||||
"slash-star_confl": {
|
||||
Err: &ConflictingImportComments{
|
||||
ImportPath: "slash-star_confl",
|
||||
ConflictingImportComments: []string{
|
||||
"vanity1",
|
||||
"vanity2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for name, fix := range table {
|
||||
|
|
|
@ -299,10 +299,10 @@ const (
|
|||
|
||||
func (ls VendorStatus) String() string {
|
||||
switch ls {
|
||||
case NotInTree:
|
||||
return "not in tree"
|
||||
case NotInLock:
|
||||
return "not in lock"
|
||||
case NotInTree:
|
||||
return "not in tree"
|
||||
case NoMismatch:
|
||||
return "match"
|
||||
case EmptyDigestInLock:
|
||||
|
|
|
@ -117,6 +117,7 @@ func TestDigestFromDirectory(t *testing.T) {
|
|||
// ensure hash ignores prefix.
|
||||
|
||||
t.Run("AbsolutePrefix", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
prefix := getTestdataVerifyRoot(t)
|
||||
got, err := DigestFromDirectory(filepath.Join(prefix, relativePathname))
|
||||
if err != nil {
|
||||
|
@ -128,6 +129,7 @@ func TestDigestFromDirectory(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("RelativePrefix", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
prefix := "../_testdata/digest"
|
||||
got, err := DigestFromDirectory(filepath.Join(prefix, relativePathname))
|
||||
if err != nil {
|
||||
|
@ -232,6 +234,81 @@ func TestVerifyDepTree(t *testing.T) {
|
|||
checkStatus(t, status, "github.com/charlie/notInTree", NotInTree)
|
||||
checkStatus(t, status, "launchpad.net/match", HashVersionMismatch)
|
||||
})
|
||||
|
||||
t.Run("Non-existent directory", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
wantDigests := make(map[string]VersionedDigest)
|
||||
for k, v := range wantSums {
|
||||
wantDigests[k] = VersionedDigest{
|
||||
HashVersion: HashVersion + 1,
|
||||
Digest: v,
|
||||
}
|
||||
}
|
||||
|
||||
status, err := CheckDepTree("fooVendorRoot", wantDigests)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if got, want := len(status), 6; got != want {
|
||||
t.Errorf("Unexpected result count from VerifyDepTree:\n\t(GOT): %v\n\t(WNT): %v", got, want)
|
||||
}
|
||||
|
||||
checkStatus(t, status, "github.com/alice/match", NotInTree)
|
||||
checkStatus(t, status, "github.com/alice/mismatch", NotInTree)
|
||||
checkStatus(t, status, "github.com/bob/match", NotInTree)
|
||||
checkStatus(t, status, "github.com/bob/emptyDigest", NotInTree)
|
||||
checkStatus(t, status, "github.com/charlie/notInTree", NotInTree)
|
||||
checkStatus(t, status, "launchpad.net/match", NotInTree)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestParseVersionedDigest(t *testing.T) {
|
||||
t.Run("Parse valid VersionedDigest", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
input := "1:60861e762bdbe39c4c7bf292c291329b731c9925388fd41125888f5c1c595feb"
|
||||
vd, err := ParseVersionedDigest(input)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
expectedHash := "60861e762bdbe39c4c7bf292c291329b731c9925388fd41125888f5c1c595feb"
|
||||
if got, want := vd.Digest, expectedHash; bytes.Equal(got, []byte(expectedHash)) {
|
||||
t.Errorf("Unexpected result from ParseVersionedDigest:\n\t(GOT): %s\n\t(WNT): %s", got, want)
|
||||
}
|
||||
|
||||
if got, want := vd.String(), input; got != want {
|
||||
t.Errorf("Unexpected result from ParseVersionedDigest String:\n\t(GOT): %s\n\t(WNT): %s", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Parse VersionedDigest with invalid format", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
input := "1abc"
|
||||
_, err := ParseVersionedDigest(input)
|
||||
if err == nil {
|
||||
t.Error("expected error for invalid VersionedDigest format")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Parse VersionedDigest with invalid hex string", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
input := "1:60861g762bdbe39c4c7bf292c291329b731c9925388fd41125888f5c1c595feb"
|
||||
_, err := ParseVersionedDigest(input)
|
||||
if err == nil {
|
||||
t.Error("expected error VersionedDigest with invalid hex string")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Parse VersionedDigest with invalid hash version", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
input := "a:60861e762bdbe39c4c7bf292c291329b731c9925388fd41125888f5c1c595feb"
|
||||
_, err := ParseVersionedDigest(input)
|
||||
if err == nil {
|
||||
t.Error("expected error VersionedDigest with invalid hash version")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkDigestFromDirectory(b *testing.B) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче