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

Integration test harness #287

Merged
merged 16 commits into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 0 additions & 108 deletions cmd/dep/ensure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
package main

import (
"path/filepath"
"testing"

"github.com/golang/dep/test"
"github.com/sdboyer/gps"
)

Expand Down Expand Up @@ -38,109 +36,3 @@ func TestDeduceConstraint(t *testing.T) {
}
}
}

type ensureTestCase struct {
dataRoot string
commands [][]string
sourceFiles map[string]string
goldenManifest string
goldenLock string
}

func TestEnsureCases(t *testing.T) {
tests := []ensureTestCase{

// Override test case
{
dataRoot: "ensure/override",
commands: [][]string{
{"init"},
{"ensure", "-override", "github.com/sdboyer/deptest@1.0.0"},
},
sourceFiles: map[string]string{
"main.go": "thing.go",
},
goldenManifest: "manifest.golden.json",
goldenLock: "lock.golden.json",
},

// Empty repo test case
{
dataRoot: "ensure/empty",
commands: [][]string{
{"init"},
{"ensure"},
},
sourceFiles: map[string]string{
"main.go": "thing.go",
},
goldenManifest: "manifest.golden.json",
goldenLock: "lock.golden.json",
},

// Update test case
{
dataRoot: "ensure/update",
commands: [][]string{
{"ensure", "-update", "github.com/sdboyer/deptest"},
},
sourceFiles: map[string]string{
"main.go": "thing.go",
"manifest.json": "manifest.json",
"lock.json": "lock.json",
},
goldenManifest: "manifest.json",
goldenLock: "lock.golden.json",
},
}

test.NeedsExternalNetwork(t)
test.NeedsGit(t)

for _, testCase := range tests {
t.Run(testCase.dataRoot, func(t *testing.T) {
h := test.NewHelper(t)
defer h.Cleanup()

h.TempDir("src")
h.Setenv("GOPATH", h.Path("."))

// Build a fake consumer of these packages.
root := "src/thing"
for src, dest := range testCase.sourceFiles {
h.TempCopy(filepath.Join(root, dest), filepath.Join(testCase.dataRoot, src))
}
h.Cd(h.Path(root))

for _, cmd := range testCase.commands {
h.Run(cmd...)
}

wantPath := filepath.Join(testCase.dataRoot, testCase.goldenManifest)
wantManifest := h.GetTestFileString(wantPath)
gotManifest := h.ReadManifest()
if wantManifest != gotManifest {
if *test.UpdateGolden {
if err := h.WriteTestFile(wantPath, gotManifest); err != nil {
t.Fatal(err)
}
} else {
t.Errorf("expected %s, got %s", wantManifest, gotManifest)
}
}

wantPath = filepath.Join(testCase.dataRoot, testCase.goldenLock)
wantLock := h.GetTestFileString(wantPath)
gotLock := h.ReadLock()
if wantLock != gotLock {
if *test.UpdateGolden {
if err := h.WriteTestFile(wantPath, gotLock); err != nil {
t.Fatal(err)
}
} else {
t.Errorf("expected %s, got %s", wantLock, gotLock)
}
}
})
}
}
124 changes: 1 addition & 123 deletions cmd/dep/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

package main

import (
"path/filepath"
"testing"

"github.com/golang/dep/test"
)
import "testing"

func TestContains(t *testing.T) {
a := []string{"a", "b", "abcd"}
Expand Down Expand Up @@ -38,120 +33,3 @@ func TestIsStdLib(t *testing.T) {
}
}
}

type initTestCase struct {
dataRoot string
importPaths map[string]string
sourceFiles map[string]string
goldenManifest string
goldenLock string
vendorPaths []string
}

func TestInit(t *testing.T) {
tests := []initTestCase{

// Both dependencies previously retrieved. Both will show up in manifest and lock
{
dataRoot: "init/case1",
importPaths: map[string]string{
"github.com/sdboyer/deptest": "v0.8.0", // semver
"github.com/sdboyer/deptestdos": "a0196baa11ea047dd65037287451d36b861b00ea", // random sha
},
sourceFiles: map[string]string{
"thing.input.go": "foo/thing.go",
"bar.input.go": "foo/bar/bar.go",
},
goldenManifest: "manifest.golden.json",
goldenLock: "lock.golden.json",
},

// One dependency previously retrieved by version. Both will show up in lock, but only retrieved one in manifest?
{
dataRoot: "init/case2",
importPaths: map[string]string{
"github.com/sdboyer/deptest": "v0.8.0", // semver
},
sourceFiles: map[string]string{
"thing.input.go": "foo/thing.go",
"bar.input.go": "foo/bar/bar.go",
},
goldenManifest: "manifest.golden.json",
goldenLock: "lock.golden.json",
},

// One dependency previously retrieved by sha. Both will show up in lock and manifest
{
dataRoot: "init/case3",
importPaths: map[string]string{
"github.com/sdboyer/deptestdos": "a0196baa11ea047dd65037287451d36b861b00ea",
},
sourceFiles: map[string]string{
"thing.input.go": "foo/thing.go",
"bar.input.go": "foo/bar/bar.go",
},
goldenManifest: "manifest.golden.json",
goldenLock: "lock.golden.json",
},
}

test.NeedsExternalNetwork(t)
test.NeedsGit(t)

for _, testCase := range tests {
t.Run(testCase.dataRoot, func(t *testing.T) {
h := test.NewHelper(t)
defer h.Cleanup()

h.TempDir("src")
h.Setenv("GOPATH", h.Path("."))

// checkout the specified revisions
for ip, rev := range testCase.importPaths {
h.RunGo("get", ip)
repoDir := h.Path(filepath.Join("src", ip))
h.RunGit(repoDir, "checkout", rev)
}

// Build a fake consumer of these packages.
root := "src/github.com/golang/notexist"
for src, dest := range testCase.sourceFiles {
h.TempCopy(filepath.Join(root, dest), filepath.Join(testCase.dataRoot, src))
}

h.Cd(h.Path(root))
h.Run("init")

wantPath := filepath.Join(testCase.dataRoot, testCase.goldenManifest)
wantManifest := h.GetTestFileString(wantPath)
gotManifest := h.ReadManifest()
if wantManifest != gotManifest {
if *test.UpdateGolden {
if err := h.WriteTestFile(wantPath, gotManifest); err != nil {
t.Fatal(err)
}
} else {
t.Errorf("expected %s, got %s", wantManifest, gotManifest)
}
}

wantPath = filepath.Join(testCase.dataRoot, testCase.goldenLock)
wantLock := h.GetTestFileString(wantPath)
gotLock := h.ReadLock()
if wantLock != gotLock {
if *test.UpdateGolden {
if err := h.WriteTestFile(wantPath, gotLock); err != nil {
t.Fatal(err)
}
} else {
t.Errorf("expected %s, got %s", wantLock, gotLock)
}
}

// vendor should have been created & populated
for ip := range testCase.importPaths {
h.MustExist(h.Path(filepath.Join(root, "vendor", ip)))
}
})
}
}
68 changes: 68 additions & 0 deletions cmd/dep/integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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 (
"os"
"path/filepath"
"runtime"
"strings"
"testing"

"github.com/golang/dep/test"
)

func TestIntegration(t *testing.T) {
test.NeedsExternalNetwork(t)
test.NeedsGit(t)

filepath.Walk(filepath.Join("testdata", "harness_tests"), func(path string, info os.FileInfo, err error) error {

if runtime.GOOS == "windows" && strings.Contains(path, "remove") {
// TODO skipping the remove tests on windows until some fixes happen in gps -
// see https://github.com/golang/dep/issues/301
return filepath.SkipDir
}

if filepath.Base(path) == "testcase.json" {
parse := strings.Split(path, string(filepath.Separator))
testName := strings.Join(parse[2:len(parse)-1], "/")

t.Run(testName, func(t *testing.T) {
// Set up environment
testCase := test.NewTestCase(t, testName)
testProj := test.NewTestProject(t, testCase.InitialPath)
defer testProj.Cleanup()

// Create and checkout the vendor revisions
for ip, rev := range testCase.InitialVendors {
testProj.GetVendorGit(ip)
testProj.RunGit(testProj.VendorPath(ip), "checkout", rev)
}

// Create and checkout the import revisions
for ip, rev := range testCase.Imports {
testProj.RunGo("get", ip)
testProj.RunGit(testProj.Path("src", ip), "checkout", rev)
}

// Run commands
testProj.RecordImportPaths()
for _, args := range testCase.Commands {
testProj.DoRun(args)
}

// Check final manifest and lock
testCase.CompareFile("manifest.json", testProj.ProjPath("manifest.json"))
testCase.CompareFile("lock.json", testProj.ProjPath("lock.json"))

// Check vendor paths
testProj.CompareImportPaths()
testCase.CompareVendorPaths(testProj.GetVendorPaths())
})
}
return nil
})
}
Loading