Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit e2709be

Browse files
committed
Merge pull request #1979 from tariq1890/unit_tests
Adding Unit tests to increase coverage Signed-off-by: Tim Heckman <[email protected]>
2 parents 14bef7d + 3d0cccb commit e2709be

File tree

13 files changed

+196
-2
lines changed

13 files changed

+196
-2
lines changed

cmd/dep/testdata/harness_tests/check/pruneopts_changed/final/Gopkg.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
[[constraint]]
3+
name = "github.com/sdboyer/deptest"
4+
version = "1.0.0"
5+
6+
[prune]
7+
go-tests = true
8+
unused-packages = true

cmd/dep/testdata/harness_tests/check/pruneopts_changed/initial/Gopkg.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
[[constraint]]
3+
name = "github.com/sdboyer/deptest"
4+
version = "1.0.0"
5+
6+
[prune]
7+
go-tests = true
8+
unused-packages = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"github.com/sdboyer/deptest"
9+
)
10+
11+
func main() {
12+
err := nil
13+
if err != nil {
14+
deptest.Map["yo yo!"]
15+
}
16+
}

cmd/dep/testdata/harness_tests/check/pruneopts_changed/initial/vendor/github.com/sdboyer/deptest/deptest.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Gopkg.lock is out of sync:
2+
github.com/sdboyer/deptest: prune options changed ( -> UT)
3+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"commands": [
3+
["check"]
4+
],
5+
"should-fail": true,
6+
"vendor-final": [
7+
"github.com/sdboyer/deptest"
8+
]
9+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package canonical /* import "vanity1" */
6+
7+
var (
8+
A = "A"
9+
)
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package canonical /* import "vanity2" */
6+
7+
var (
8+
B = "B"
9+
)

gps/pkgtree/pkgtree_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,24 @@ func TestListPackages(t *testing.T) {
15391539
},
15401540
},
15411541
},
1542+
"slash-star": {
1543+
fileRoot: j("slash-star_confl"),
1544+
importRoot: "slash-star_confl",
1545+
out: PackageTree{
1546+
ImportRoot: "slash-star_confl",
1547+
Packages: map[string]PackageOrErr{
1548+
"slash-star_confl": {
1549+
Err: &ConflictingImportComments{
1550+
ImportPath: "slash-star_confl",
1551+
ConflictingImportComments: []string{
1552+
"vanity1",
1553+
"vanity2",
1554+
},
1555+
},
1556+
},
1557+
},
1558+
},
1559+
},
15421560
}
15431561

15441562
for name, fix := range table {

gps/verify/digest.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,10 @@ const (
299299

300300
func (ls VendorStatus) String() string {
301301
switch ls {
302-
case NotInTree:
303-
return "not in tree"
304302
case NotInLock:
305303
return "not in lock"
304+
case NotInTree:
305+
return "not in tree"
306306
case NoMismatch:
307307
return "match"
308308
case EmptyDigestInLock:

gps/verify/digest_test.go

+77
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func TestDigestFromDirectory(t *testing.T) {
117117
// ensure hash ignores prefix.
118118

119119
t.Run("AbsolutePrefix", func(t *testing.T) {
120+
t.Parallel()
120121
prefix := getTestdataVerifyRoot(t)
121122
got, err := DigestFromDirectory(filepath.Join(prefix, relativePathname))
122123
if err != nil {
@@ -128,6 +129,7 @@ func TestDigestFromDirectory(t *testing.T) {
128129
})
129130

130131
t.Run("RelativePrefix", func(t *testing.T) {
132+
t.Parallel()
131133
prefix := "../_testdata/digest"
132134
got, err := DigestFromDirectory(filepath.Join(prefix, relativePathname))
133135
if err != nil {
@@ -232,6 +234,81 @@ func TestVerifyDepTree(t *testing.T) {
232234
checkStatus(t, status, "github.com/charlie/notInTree", NotInTree)
233235
checkStatus(t, status, "launchpad.net/match", HashVersionMismatch)
234236
})
237+
238+
t.Run("Non-existent directory", func(t *testing.T) {
239+
t.Parallel()
240+
wantDigests := make(map[string]VersionedDigest)
241+
for k, v := range wantSums {
242+
wantDigests[k] = VersionedDigest{
243+
HashVersion: HashVersion + 1,
244+
Digest: v,
245+
}
246+
}
247+
248+
status, err := CheckDepTree("fooVendorRoot", wantDigests)
249+
if err != nil {
250+
t.Fatal(err)
251+
}
252+
253+
if got, want := len(status), 6; got != want {
254+
t.Errorf("Unexpected result count from VerifyDepTree:\n\t(GOT): %v\n\t(WNT): %v", got, want)
255+
}
256+
257+
checkStatus(t, status, "github.com/alice/match", NotInTree)
258+
checkStatus(t, status, "github.com/alice/mismatch", NotInTree)
259+
checkStatus(t, status, "github.com/bob/match", NotInTree)
260+
checkStatus(t, status, "github.com/bob/emptyDigest", NotInTree)
261+
checkStatus(t, status, "github.com/charlie/notInTree", NotInTree)
262+
checkStatus(t, status, "launchpad.net/match", NotInTree)
263+
264+
})
265+
}
266+
267+
func TestParseVersionedDigest(t *testing.T) {
268+
t.Run("Parse valid VersionedDigest", func(t *testing.T) {
269+
t.Parallel()
270+
input := "1:60861e762bdbe39c4c7bf292c291329b731c9925388fd41125888f5c1c595feb"
271+
vd, err := ParseVersionedDigest(input)
272+
if err != nil {
273+
t.Fatal()
274+
}
275+
276+
expectedHash := "60861e762bdbe39c4c7bf292c291329b731c9925388fd41125888f5c1c595feb"
277+
if got, want := vd.Digest, expectedHash; bytes.Equal(got, []byte(expectedHash)) {
278+
t.Errorf("Unexpected result from ParseVersionedDigest:\n\t(GOT): %s\n\t(WNT): %s", got, want)
279+
}
280+
281+
if got, want := vd.String(), input; got != want {
282+
t.Errorf("Unexpected result from ParseVersionedDigest String:\n\t(GOT): %s\n\t(WNT): %s", got, want)
283+
}
284+
})
285+
286+
t.Run("Parse VersionedDigest with invalid format", func(t *testing.T) {
287+
t.Parallel()
288+
input := "1abc"
289+
_, err := ParseVersionedDigest(input)
290+
if err == nil {
291+
t.Error("expected error for invalid VersionedDigest format")
292+
}
293+
})
294+
295+
t.Run("Parse VersionedDigest with invalid hex string", func(t *testing.T) {
296+
t.Parallel()
297+
input := "1:60861g762bdbe39c4c7bf292c291329b731c9925388fd41125888f5c1c595feb"
298+
_, err := ParseVersionedDigest(input)
299+
if err == nil {
300+
t.Error("expected error VersionedDigest with invalid hex string")
301+
}
302+
})
303+
304+
t.Run("Parse VersionedDigest with invalid hash version", func(t *testing.T) {
305+
t.Parallel()
306+
input := "a:60861e762bdbe39c4c7bf292c291329b731c9925388fd41125888f5c1c595feb"
307+
_, err := ParseVersionedDigest(input)
308+
if err == nil {
309+
t.Error("expected error VersionedDigest with invalid hash version")
310+
}
311+
})
235312
}
236313

237314
func BenchmarkDigestFromDirectory(b *testing.B) {

0 commit comments

Comments
 (0)