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

Integration test harness #287

merged 16 commits into from
Mar 9, 2017

Conversation

tro3
Copy link
Contributor

@tro3 tro3 commented Mar 5, 2017

Addressing #282. @sdboyer, please let me know what you think of this path.

@tro3 tro3 changed the title Test harness Integration test harness Mar 5, 2017
@tro3
Copy link
Contributor Author

tro3 commented Mar 5, 2017

Note that for now, I have the tests under testdata/harness_tests, with only the init tests converted. The whole thing currently runs in parallel to the original suite. Final version will remove the other tests and promote the harness_tests directory one level.

@tro3 tro3 changed the title Integration test harness Integration test harness [WIP] Mar 5, 2017
@tro3
Copy link
Contributor Author

tro3 commented Mar 6, 2017

Okay - I set up a vendor initialization function, so I think we can really beat the he** out of this thing now. If the community agrees with the direction, then I will document the structure and usage, and propose a test list to start working against (which would also serve as a high-level functionality cheat sheet).

All thoughts welcome.

@tro3 tro3 changed the title Integration test harness [WIP] Integration test harness Mar 6, 2017
@tro3
Copy link
Contributor Author

tro3 commented Mar 6, 2017

This is almost ready to merge, after review and documentation. Increased number of remove tests makes it harder to get past AppVeyor. After this, I will put together a test table porposal in a separate issue for discussion/feedback before filling out the tests.

@tro3
Copy link
Contributor Author

tro3 commented Mar 6, 2017

@sdboyer - where would you like the harness docs? test, cmd/dep, or cmd/dep/testdata?

@sdboyer
Copy link
Member

sdboyer commented Mar 7, 2017

@tro3 my first impulse is to say cmd/dep/testdata for the docs.

I've got reviewing this on my TODO list for tomorrow.

@tro3
Copy link
Contributor Author

tro3 commented Mar 7, 2017 via email

@tro3
Copy link
Contributor Author

tro3 commented Mar 7, 2017

Maybe even better would be a single testcase.yaml file:

# ensure/update test case 4 - description here

commands:
  - init
  - ensure -update

imports:
    github.com/sdboyer/deptestdos: 1.0.0

initialVendors:
    github.com/sdboyer/deptest: 0.8.0

finalVendors:
    - github.com/sdboyer/deptest
    - github.com/sdboyer/deptestdos

Then the overall testcase would be a single file to describe it and the initial and final directories to populate and check against. I don't want to require a go-yaml package, so I'd write a simple parser for the above subset. Thoughts?

@tro3
Copy link
Contributor Author

tro3 commented Mar 7, 2017

Okay, I moved to the yaml config file, blocked the remove tests on Windows, and all seems to be working. Starting to work on documentation.

@sdboyer
Copy link
Member

sdboyer commented Mar 8, 2017

I actually blocked the remove tests on windows a bit earlier back on aster, so you can pull that part out.

nvm this, ofc, the logic has to be a bit different now. You'll still need to rebase back onto master to fix the conflict, though.

@sdboyer
Copy link
Member

sdboyer commented Mar 8, 2017

(starting review)

Copy link
Member

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oi, this is a ton of work - thank you! Overall, this is looking really good! Biggest comment is switching from YAML -> JSON - see inline comment.

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

filepath.Walk("testdata", func(path string, info os.FileInfo, err error) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's actually put an extra parent directory in here - testdata/harness_tests is fine (sorry I didn't catch you earlier with this), so that it's easily possible to use the testdata dir for something other than just this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. Note that it already can be used for other things. The system just looks for testcase.yaml, so other directories can exist in parallel. But I have no problem moving them back.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, but yeah, I think the extra separator is still worthwhile. Given that we're defining semantics around filesystem organization, I think it's better to have the explicit top-level choice.

test/miniyaml.go Outdated
}

// Only parses key:val pairs (both strings) and lists of strings
func ParseYaml(rdr io.Reader) (YamlDoc, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please use JSON, instead.

I realize that JSON is suboptimal for this purpose, but it's in stdlib, and until we come to a decision in #119, it's not clear what parsers for more human-readable formats we'll have available to us. I'd rather not introduce an extra dependency for just this purpose, and I like introducing a custom parser even less than that.

Also, would I be right to guess that this implementation probably came from somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I wrote it on the fly (looking sheepish). No problem - I'll convert to JSON.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ach, sorry, i wish i'd caught it before you put all the time in on that - sorry! thanks for making the change.

@@ -0,0 +1,269 @@
// Copyright 2017 The Go Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to abbreviate filename - integration_testcase.go is fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

if err != nil {
panic(err)
}
rootPath := filepath.Join(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorter:

rootPath := filepath.FromSlash(filepath.Join(wd, "testdata", name))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k

}

//
// func (tc *IntegrationTestCase) GetImports() map[string]string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these commented bits?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stupidity. Will remove

@tro3
Copy link
Contributor Author

tro3 commented Mar 8, 2017

@sdboyer, harness feedback implemented

Copy link
Member

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sooo close! Just a couple of nits.

@@ -18,51 +18,52 @@ func TestIntegration(t *testing.T) {
test.NeedsExternalNetwork(t)
test.NeedsGit(t)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that everything on one line here is fine - even preferable, because it'll de-dent everything below. Go is lax about the 80-width column thing.

If the width thing really bugs you, assign the func to a var and then call the filepath.Walk() below with it 😄

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want filepath.Base() here

finalVendors:
- github.com/sdboyer/deptest
- github.com/sdboyer/deptestdos
The test code itself simply walks down the directory tree, looking for `testcase.json` files. These files can be as many levels down the tree as 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`). 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While wrap may not matter overmuch, I think it'd be worth wrapping these at 80; this is a file that likely will be read in a terminal/editors.

@@ -51,7 +54,7 @@ The test procedure is as follows:
2. Create `src/github.com/golang/notexist` as the project
3. Copy the contents of `initial` to the project
4. `go get` the repos and versions in `imports` to the `src` directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say fetch rather than go get; less misleading.

Also, should probably note in here that we only support git repos.

@tro3
Copy link
Contributor Author

tro3 commented Mar 9, 2017

@sdboyer - latest mods in place. Pls have a look.

Copy link
Contributor

@groob groob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made a few small style nits. Hope you don't mind.

if err := tc.WriteFile(golden, got); err != nil {
tc.t.Fatal(err)
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the else for cases where you call t.Fatal first?
It would improve readability of this test if some of the if ... else if ... else code could be simplified into something with fewer indentation levels.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on the readability here, but don't see an obvious simplification. There is a 2x3 decision matrix being handled, and some of the quadrants need error handling built in, causing more ifs. Open to suggestions - I am a Go newbie.


gotExists, got, err := getFile(working)
if err != nil {
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for calling panic instead of Fatal here?

)

var (
ProjectRoot string = "src/github.com/golang/notexist"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this var be a const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Newbie move.

UpdateGolden *bool = flag.Bool("update", false, "update golden files")
)

// To manage a test case directory structure and content
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the recommended comment format from go lint here: IntegrationTestCase ...

@tro3
Copy link
Contributor Author

tro3 commented Mar 9, 2017

@groob, thanks for the feedback. Mods are pushed - please let me know what you think.

@domgreen domgreen mentioned this pull request Mar 9, 2017
@sdboyer
Copy link
Member

sdboyer commented Mar 9, 2017

@groob thanks for the extra review!

still needs a rebase to fix conflicts :)

@tro3
Copy link
Contributor Author

tro3 commented Mar 9, 2017

? It says it specifically can't be rebased, due to conflicts (files being deleted/moved across branches). But I think merge is ok? I just did it locally without issue. If it does need a rebase, just let me know to where.

@sdboyer
Copy link
Member

sdboyer commented Mar 9, 2017

right, it says GH can't rebase because the repository is set to incorporate PRs via rebase, rather than via merge - and there's a conflict. (i just verified the conflict locally - at least one, in cmd/dep/remove_test.go).

i realize it doesn't report the same conflict on merge, but that's not how we're incorporating PRs at the moment, so you'll need to resolve the rebase conflict, push up the rebased branch, and then we can hit the button here.

@sdboyer
Copy link
Member

sdboyer commented Mar 9, 2017

oh wait - i can just do the merge here :) thanks!

@sdboyer sdboyer merged commit 5b98ab1 into golang:master Mar 9, 2017
@tro3 tro3 deleted the test_harness branch March 9, 2017 18:47
ibrasho pushed a commit to ibrasho-forks/dep that referenced this pull request May 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants