Skip to content

Commit

Permalink
Merge pull request sdboyer/gps#212 from jstemmer/test-cleanup
Browse files Browse the repository at this point in the history
A bit of cleaning up the tests
  • Loading branch information
sdboyer authored Apr 9, 2017
2 parents a33a859 + 1b6303f commit 584844e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 95 deletions.
6 changes: 2 additions & 4 deletions constraint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,7 @@ func TestSemverConstraintOps(t *testing.T) {
// still an incomparable type
c1, err := NewSemverConstraint("=1.0.0")
if err != nil {
t.Errorf("Failed to create constraint: %s", err)
t.FailNow()
t.Fatalf("Failed to create constraint: %s", err)
}

if !c1.MatchesAny(any) {
Expand All @@ -610,8 +609,7 @@ func TestSemverConstraintOps(t *testing.T) {

c1, err = NewSemverConstraint(">= 1.0.0")
if err != nil {
t.Errorf("Failed to create constraint: %s", err)
t.FailNow()
t.Fatalf("Failed to create constraint: %s", err)
}

if c1.Matches(v1) {
Expand Down
15 changes: 5 additions & 10 deletions hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func TestHashInputs(t *testing.T) {

s, err := Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Errorf("Unexpected error while prepping solver: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while prepping solver: %s", err)
}

dig := s.HashInputs()
Expand Down Expand Up @@ -73,8 +72,7 @@ func TestHashInputsReqsIgs(t *testing.T) {

s, err := Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Errorf("Unexpected error while prepping solver: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while prepping solver: %s", err)
}

dig := s.HashInputs()
Expand Down Expand Up @@ -116,8 +114,7 @@ func TestHashInputsReqsIgs(t *testing.T) {

s, err = Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Errorf("Unexpected error while prepping solver: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while prepping solver: %s", err)
}

dig = s.HashInputs()
Expand Down Expand Up @@ -157,8 +154,7 @@ func TestHashInputsReqsIgs(t *testing.T) {

s, err = Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Errorf("Unexpected error while prepping solver: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while prepping solver: %s", err)
}

dig = s.HashInputs()
Expand Down Expand Up @@ -522,8 +518,7 @@ func TestHashInputsOverrides(t *testing.T) {

s, err := Prepare(params, newdepspecSM(basefix.ds, nil))
if err != nil {
t.Errorf("(fix: %q) Unexpected error while prepping solver: %s", fix.name, err)
t.FailNow()
t.Fatalf("(fix: %q) Unexpected error while prepping solver: %s", fix.name, err)
}

h := sha256.New()
Expand Down
18 changes: 6 additions & 12 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ func sv(s string) *semver.Version {
func mkNaiveSM(t *testing.T) (*SourceMgr, func()) {
cpath, err := ioutil.TempDir("", "smcache")
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
t.FailNow()
t.Fatalf("Failed to create temp dir: %s", err)
}

sm, err := NewSourceManager(cpath)
if err != nil {
t.Errorf("Unexpected error on SourceManager creation: %s", err)
t.FailNow()
t.Fatalf("Unexpected error on SourceManager creation: %s", err)
}

return sm, func() {
Expand All @@ -68,8 +66,7 @@ func remakeNaiveSM(osm *SourceMgr, t *testing.T) (*SourceMgr, func()) {

sm, err := NewSourceManager(cpath)
if err != nil {
t.Errorf("unexpected error on SourceManager recreation: %s", err)
t.FailNow()
t.Fatalf("unexpected error on SourceManager recreation: %s", err)
}

return sm, func() {
Expand Down Expand Up @@ -115,8 +112,7 @@ func TestSourceManagerInit(t *testing.T) {
}

if _, err = os.Stat(path.Join(cpath, "sm.lock")); !os.IsNotExist(err) {
t.Errorf("Global cache lock file not cleared correctly on Release()")
t.FailNow()
t.Fatalf("Global cache lock file not cleared correctly on Release()")
}

// Set another one up at the same spot now, just to be sure
Expand All @@ -140,14 +136,12 @@ func TestSourceInit(t *testing.T) {

cpath, err := ioutil.TempDir("", "smcache")
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
t.FailNow()
t.Fatalf("Failed to create temp dir: %s", err)
}

sm, err := NewSourceManager(cpath)
if err != nil {
t.Errorf("Unexpected error on SourceManager creation: %s", err)
t.FailNow()
t.Fatalf("Unexpected error on SourceManager creation: %s", err)
}

defer func() {
Expand Down
15 changes: 5 additions & 10 deletions pkgtree/pkgtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1352,8 +1352,7 @@ func TestListPackagesNoPerms(t *testing.T) {
}
tmp, err := ioutil.TempDir("", "listpkgsnp")
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
t.FailNow()
t.Fatalf("Failed to create temp dir: %s", err)
}
defer os.RemoveAll(tmp)

Expand All @@ -1364,13 +1363,11 @@ func TestListPackagesNoPerms(t *testing.T) {
// chmod the simple dir and m1p/b.go file so they can't be read
err = os.Chmod(filepath.Join(workdir, "simple"), 0)
if err != nil {
t.Error("Error while chmodding simple dir", err)
t.FailNow()
t.Fatalf("Error while chmodding simple dir: %s", err)
}
os.Chmod(filepath.Join(workdir, "m1p", "b.go"), 0)
if err != nil {
t.Error("Error while chmodding b.go file", err)
t.FailNow()
t.Fatalf("Error while chmodding b.go file: %s", err)
}

want := PackageTree{
Expand Down Expand Up @@ -1398,12 +1395,10 @@ func TestListPackagesNoPerms(t *testing.T) {
got, err := ListPackages(workdir, "ren")

if err != nil {
t.Errorf("Unexpected err from ListPackages: %s", err)
t.FailNow()
t.Fatalf("Unexpected err from ListPackages: %s", err)
}
if want.ImportRoot != got.ImportRoot {
t.Errorf("Expected ImportRoot %s, got %s", want.ImportRoot, got.ImportRoot)
t.FailNow()
t.Fatalf("Expected ImportRoot %s, got %s", want.ImportRoot, got.ImportRoot)
}

if !reflect.DeepEqual(got, want) {
Expand Down
3 changes: 1 addition & 2 deletions result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func testWriteDepTree(t *testing.T) {

tmp, err := ioutil.TempDir("", "writetree")
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
t.FailNow()
t.Fatalf("Failed to create temp dir: %s", err)
}
defer os.RemoveAll(tmp)

Expand Down
6 changes: 2 additions & 4 deletions rootdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ func TestRootdataExternalImports(t *testing.T) {

is, err := Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Errorf("Unexpected error while prepping solver: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while prepping solver: %s", err)
}
rd := is.(*solver).rd

Expand Down Expand Up @@ -71,8 +70,7 @@ func TestGetApplicableConstraints(t *testing.T) {

is, err := Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Errorf("Unexpected error while prepping solver: %s", err)
t.FailNow()
t.Fatalf("Unexpected error while prepping solver: %s", err)
}
rd := is.(*solver).rd

Expand Down
74 changes: 23 additions & 51 deletions vcs_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,17 @@ func testGitSourceInteractions(t *testing.T) {
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
}
rf := func() {
err := removeAll(cpath)
if err != nil {
defer func() {
if err := removeAll(cpath); err != nil {
t.Errorf("removeAll failed: %s", err)
}
}
}()

n := "github.com/sdboyer/gpkt"
un := "https://" + n
u, err := url.Parse(un)
if err != nil {
t.Errorf("URL was bad, lolwut? errtext: %s", err)
rf()
t.FailNow()
t.Fatalf("Error parsing URL %s: %s", un, err)
}
mb := maybeGitSource{
url: u,
Expand All @@ -61,9 +58,7 @@ func testGitSourceInteractions(t *testing.T) {
superv := newSupervisor(ctx)
isrc, state, err := mb.try(ctx, cpath, newMemoryCache(), superv)
if err != nil {
t.Errorf("Unexpected error while setting up gitSource for test repo: %s", err)
rf()
t.FailNow()
t.Fatalf("Unexpected error while setting up gitSource for test repo: %s", err)
}

wantstate := sourceIsSetUp | sourceExistsUpstream | sourceHasLatestVersionList
Expand All @@ -73,16 +68,12 @@ func testGitSourceInteractions(t *testing.T) {

err = isrc.initLocal(ctx)
if err != nil {
t.Errorf("Error on cloning git repo: %s", err)
rf()
t.FailNow()
t.Fatalf("Error on cloning git repo: %s", err)
}

src, ok := isrc.(*gitSource)
if !ok {
t.Errorf("Expected a gitSource, got a %T", isrc)
rf()
t.FailNow()
t.Fatalf("Expected a gitSource, got a %T", isrc)
}

if un != src.upstreamURL() {
Expand All @@ -91,9 +82,7 @@ func testGitSourceInteractions(t *testing.T) {

pvlist, err := src.listVersions(ctx)
if err != nil {
t.Errorf("Unexpected error getting version pairs from git repo: %s", err)
rf()
t.FailNow()
t.Fatalf("Unexpected error getting version pairs from git repo: %s", err)
}

vlist := hidePair(pvlist)
Expand Down Expand Up @@ -145,12 +134,11 @@ func testGopkginSourceInteractions(t *testing.T) {
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
}
rf := func() {
err := removeAll(cpath)
if err != nil {
defer func() {
if err := removeAll(cpath); err != nil {
t.Errorf("removeAll failed: %s", err)
}
}
}()

tfunc := func(opath, n string, major uint64, evl []Version) {
un := "https://" + n
Expand Down Expand Up @@ -180,9 +168,7 @@ func testGopkginSourceInteractions(t *testing.T) {

err = isrc.initLocal(ctx)
if err != nil {
t.Errorf("Error on cloning git repo: %s", err)
rf()
t.FailNow()
t.Fatalf("Error on cloning git repo: %s", err)
}

src, ok := isrc.(*gopkginSource)
Expand Down Expand Up @@ -275,7 +261,6 @@ func testGopkginSourceInteractions(t *testing.T) {
}()

wg.Wait()
rf()
}

func testBzrSourceInteractions(t *testing.T) {
Expand All @@ -291,20 +276,17 @@ func testBzrSourceInteractions(t *testing.T) {
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
}
rf := func() {
err := removeAll(cpath)
if err != nil {
defer func() {
if err := removeAll(cpath); err != nil {
t.Errorf("removeAll failed: %s", err)
}
}
}()

n := "launchpad.net/govcstestbzrrepo"
un := "https://" + n
u, err := url.Parse(un)
if err != nil {
t.Errorf("URL was bad, lolwut? errtext: %s", err)
rf()
t.FailNow()
t.Fatalf("Error parsing URL %s: %s", un, err)
}
mb := maybeBzrSource{
url: u,
Expand All @@ -314,9 +296,7 @@ func testBzrSourceInteractions(t *testing.T) {
superv := newSupervisor(ctx)
isrc, state, err := mb.try(ctx, cpath, newMemoryCache(), superv)
if err != nil {
t.Errorf("Unexpected error while setting up bzrSource for test repo: %s", err)
rf()
t.FailNow()
t.Fatalf("Unexpected error while setting up bzrSource for test repo: %s", err)
}

wantstate := sourceIsSetUp | sourceExistsUpstream
Expand All @@ -326,16 +306,12 @@ func testBzrSourceInteractions(t *testing.T) {

err = isrc.initLocal(ctx)
if err != nil {
t.Errorf("Error on cloning git repo: %s", err)
rf()
t.FailNow()
t.Fatalf("Error on cloning git repo: %s", err)
}

src, ok := isrc.(*bzrSource)
if !ok {
t.Errorf("Expected a bzrSource, got a %T", isrc)
rf()
t.FailNow()
t.Fatalf("Expected a bzrSource, got a %T", isrc)
}

if state != wantstate {
Expand Down Expand Up @@ -410,12 +386,11 @@ func testHgSourceInteractions(t *testing.T) {
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
}
rf := func() {
err := removeAll(cpath)
if err != nil {
defer func() {
if err := removeAll(cpath); err != nil {
t.Errorf("removeAll failed: %s", err)
}
}
}()

tfunc := func(n string, evl []Version) {
un := "https://" + n
Expand Down Expand Up @@ -443,9 +418,7 @@ func testHgSourceInteractions(t *testing.T) {

err = isrc.initLocal(ctx)
if err != nil {
t.Errorf("Error on cloning git repo: %s", err)
rf()
t.FailNow()
t.Fatalf("Error on cloning git repo: %s", err)
}

src, ok := isrc.(*hgSource)
Expand Down Expand Up @@ -530,7 +503,6 @@ func testHgSourceInteractions(t *testing.T) {
})

<-donech
rf()
}

// Fail a test if the specified binaries aren't installed.
Expand Down
3 changes: 1 addition & 2 deletions version_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ func TestVersionQueueAdvance(t *testing.T) {
// First with no prefv or lockv
vq, err := newVersionQueue(id, nil, nil, fb)
if err != nil {
t.Errorf("Unexpected err on vq create: %s", err)
t.FailNow()
t.Fatalf("Unexpected err on vq create: %s", err)
}

for k, v := range fakevl[1:] {
Expand Down

0 comments on commit 584844e

Please sign in to comment.