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:
Tim Heckman 2019-02-28 10:02:53 -08:00
Родитель 14bef7d1ca 3d0cccb0aa
Коммит e2709bef5f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 9B800DBDE3FA5355
13 изменённых файлов: 196 добавлений и 2 удалений

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
Просмотреть файл

@ -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

Просмотреть файл

@ -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
Просмотреть файл

@ -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) {