Skip to content

Commit

Permalink
Merge pull request golang#310 from sdboyer/test-harness-tweaks
Browse files Browse the repository at this point in the history
Rename fields and update test harness docs
  • Loading branch information
sdboyer authored Mar 10, 2017
2 parents 70f818a + 10ae941 commit 3df8773
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions cmd/dep/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ func TestIntegration(t *testing.T) {
defer testProj.Cleanup()

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

// Create and checkout the import revisions
for ip, rev := range testCase.Imports {
for ip, rev := range testCase.GopathInitial {
testProj.RunGo("get", ip)
testProj.RunGit(testProj.Path("src", ip), "checkout", rev)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/dep/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ func TestRemoveErrors(t *testing.T) {
defer testProj.Cleanup()

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

// Create and checkout the import revisions
for ip, rev := range testCase.Imports {
for ip, rev := range testCase.GopathInitial {
testProj.RunGo("get", ip)
testProj.RunGit(testProj.Path("src", ip), "checkout", rev)
}
Expand Down
26 changes: 13 additions & 13 deletions cmd/dep/testdata/harness_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ desired. The test name will consist of the directory path from `testdata` to
the test case directory itself. In the above example, the test name would be
`category1/subcategory1/case1`, and could be singled out with the `-run` option
of `go test` (i.e.
`go test github.com/golang/dep/cmp/dep -run Integration/category1/subcategory1/case1`).
`go test github.com/golang/dep/cmp/dep -run Integration/category1/subcategory1/case1`).
New tests can be added simply by adding a new directory with the json file to
the `testdata` tree. There is no need for code modification - the new test
will be included automatically.
Expand All @@ -44,15 +44,15 @@ The `testcase.json` file has the following format:
["init"],
["ensure", "github.com/sdboyer/deptesttres"]
],
"imports": {
"gopath-initial": {
"github.com/sdboyer/deptest": "v0.8.0",
"github.com/sdboyer/deptestdos": "a0196baa11ea047dd65037287451d36b861b00ea"
},
"initialVendors": {
"vendor-initial": {
"github.com/sdboyer/deptesttres": "v2.1.0",
"github.com/sdboyer/deptestquatro": "cf596baa11ea047ddf8797287451d36b861bab45"
},
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest",
"github.com/sdboyer/deptestdos",
"github.com/sdboyer/deptesttres",
Expand All @@ -65,15 +65,15 @@ for example, it can be completely left out.

The test procedure is as follows:

1. Create a temporary directory for the test project environment
2. Create `src/github.com/golang/notexist` as the project
3. Copy the contents of `initial` to the project
4. Fetch the repos and versions in `imports` to the `src` directory
5. Fetch the repos and versions in `initialVendors` to the `vendor` directory
6. Run the commands in `commands` in order on the project
7. Check the resulting files against those in `final`
8. Check the `vendor` directory for the repos listed under `finalVendors`
1. Create a unique temporary directory (TMPDIR) as the test run's GOPATH
2. Create `$TMPDIR/src/github.com/golang/notexist` as the current project
3. Copy the contents of `initial` input directory to the project
4. Fetch the repos and versions in `gopath-initial` into `$TMPDIR/src` directory
5. Fetch the repos and versions in `vendor-initial` to the project's `vendor` directory
6. Run `commands` on the project, in declaration order
7. Check the resulting files against those in the `final` input directory
8. Check the `vendor` directory for the projects listed under `vendor-final`
9. Check that there were no changes to `src` listings
10. Clean up
10. Clean up

Note that for the remote fetches, only git repos are currently supported.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
["init"],
["ensure", "-update"]
],
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"commands": [
["ensure"]
],
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
["init"],
["ensure", "-override", "github.com/sdboyer/deptest@1.0.0"]
],
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
["init"],
["ensure", "-update", "github.com/sdboyer/deptest"]
],
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest",
"github.com/sdboyer/deptestdos"
]
Expand Down
4 changes: 2 additions & 2 deletions cmd/dep/testdata/harness_tests/init/case1/testcase.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"commands": [
["init"]
],
"imports": {
"gopath-initial": {
"github.com/sdboyer/deptest": "v0.8.0",
"github.com/sdboyer/deptestdos": "a0196baa11ea047dd65037287451d36b861b00ea"
},
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest",
"github.com/sdboyer/deptestdos"
]
Expand Down
4 changes: 2 additions & 2 deletions cmd/dep/testdata/harness_tests/init/case2/testcase.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"commands": [
["init"]
],
"imports": {
"gopath-initial": {
"github.com/sdboyer/deptest": "v0.8.0"
},
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest",
"github.com/sdboyer/deptestdos"
]
Expand Down
4 changes: 2 additions & 2 deletions cmd/dep/testdata/harness_tests/init/case3/testcase.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"commands": [
["init"]
],
"imports": {
"gopath-initial": {
"github.com/sdboyer/deptestdos": "a0196baa11ea047dd65037287451d36b861b00ea"
},
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest",
"github.com/sdboyer/deptestdos"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"commands": [
["init"]
],
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"commands": [
["remove", "-force", "github.com/sdboyer/deptestdos", "github.com/not/used"]
],
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest",
"github.com/sdboyer/deptestdos"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"commands": [
["remove", "github.com/not/used"]
],
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest",
"github.com/sdboyer/deptestdos"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"commands": [
["remove", "github.com/not/used"]
],
"initialVendors": {
"vendor-initial": {
"github.com/sdboyer/deptest": "v0.8.0",
"github.com/sdboyer/deptestdos": "a0196baa11ea047dd65037287451d36b861b00ea"
},
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"commands": [
["remove", "-unused"]
],
"finalVendors": [
"vendor-final": [
"github.com/sdboyer/deptest",
"github.com/sdboyer/deptestdos"
]
Expand Down
20 changes: 10 additions & 10 deletions test/integration_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ var (

// IntegrationTestCase manages a test case directory structure and content
type IntegrationTestCase struct {
t *testing.T
Name string
RootPath string
InitialPath string
FinalPath string
Commands [][]string `json:"commands"`
Imports map[string]string `json:"imports"`
InitialVendors map[string]string `json:"initialVendors"`
FinalVendors []string `json:"finalVendors"`
t *testing.T
Name string
RootPath string
InitialPath string
FinalPath string
Commands [][]string `json:"commands"`
GopathInitial map[string]string `json:"gopath-initial"`
VendorInitial map[string]string `json:"vendor-initial"`
VendorFinal []string `json:"vendor-final"`
}

func NewTestCase(t *testing.T, name string) *IntegrationTestCase {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (tc *IntegrationTestCase) CompareFile(goldenPath, working string) {
}

func (tc *IntegrationTestCase) CompareVendorPaths(gotVendorPaths []string) {
wantVendorPaths := tc.FinalVendors
wantVendorPaths := tc.VendorFinal
if len(gotVendorPaths) != len(wantVendorPaths) {
tc.t.Fatalf("Wrong number of vendor paths created: want %d got %d", len(wantVendorPaths), len(gotVendorPaths))
}
Expand Down

0 comments on commit 3df8773

Please sign in to comment.