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

Moving int tests to fixture repositories #265

Merged
merged 10 commits into from
Mar 5, 2017
Merged

Conversation

tro3
Copy link
Contributor

@tro3 tro3 commented Feb 23, 2017

@sdboyer, looking for feedback on this path for dealing with #255. Have moved the pointers to the fixed repos, but also refactored to allow for new test cases to be added more easily. Pls le me know what you think of this path.

@tro3
Copy link
Contributor Author

tro3 commented Feb 24, 2017

@sdboyer - After adding a few more integration test cases to init, I see a behavior I don't understand. When referencing repos that have not yet been retrieved, there is one case where the unretrieved repo is left off the manifest, but another where its "master" branch is added. (Look at the resulting golden files to see the output.) Is this correct? If not, I can open an issue.

@tro3
Copy link
Contributor Author

tro3 commented Mar 3, 2017

@sdboyer - no feedback here, so I just finished off the conversion while I have time. If this is not the path you were looking for, please let me know and I'll close the request. CI passing is still spotty on my machine, with 1 time in 4 failing due to the remove test / gps interaction. The suite always passes when skipping the remove test.

@sdboyer
Copy link
Member

sdboyer commented Mar 3, 2017

@tro3 sorry, all the spare time i've had for the last week has been devoted to trying to get the roadmap together :/ i'll review as soon as i possibly can - thanks for keeping at it!

@tro3 tro3 changed the title [WIP]Moving int tests to fixture repositories Moving int tests to fixture repositories Mar 3, 2017
@tro3
Copy link
Contributor Author

tro3 commented Mar 3, 2017

No worries and no hurry. As long as we're not in "black hole" mode. :-)

@sdboyer
Copy link
Member

sdboyer commented Mar 3, 2017

for sure not in black hole mode :)

until i do get to it, it seems like travis is complaining about a gofmt issue - have a look at that?

@tro3
Copy link
Contributor Author

tro3 commented Mar 3, 2017 via email

@sdboyer
Copy link
Member

sdboyer commented Mar 3, 2017

When referencing repos that have not yet been retrieved, there is one case where the unretrieved repo is left off the manifest, but another where its "master" branch is added. (Look at the resulting golden files to see the output.)

Could you point me more specifically at a place to look for this?

@tro3
Copy link
Contributor Author

tro3 commented Mar 3, 2017 via email

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.

I really like how this is starting to become more structured - the table-based tests, the layout of the files on disk. Much more systematic, which is awesome.

I'm thinking I might like to see this structured even a little further. For example, instead of explicitly having each table-based test entry declare the name of its golden manifest and lock file, just have that be a hardcoded decision, reflected by filesystem layout and naming. Similarly, don't declare rules for which go files to copy over - just have general logic that infers what to do based on the arrangement of the filesystem.

Does that make sense, and seem sane? My goal is to drive the locus of control for test behavior into a single location (disk vs. logic in the test) as much as possible. It seems like we can cover all cases that way, at least for now; if not, I'd be OK with covering almost all cases that way, then having a couple others that we have to manage more manually.

If we go that route, then let's also add a README to the cmd/dep/testdata directory that explains the rules behind the layout. Or one to each subdir, if appropriate.

}

for _, testCase := range tests {
runTest(t, testCase)
Copy link
Member

Choose a reason for hiding this comment

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

If you're gonna set it up like this (which is great), it's probably worth just executing them as subtests.

defer h.Cleanup()
runTest := func(t *testing.T, testCase initTestCase) {
test.NeedsExternalNetwork(t)
test.NeedsGit(t)
Copy link
Member

Choose a reason for hiding this comment

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

It's enough to just do these checks once, outside the loop.

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

Choose a reason for hiding this comment

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

Instead of infixing the "/" here, use filepath.Join() here - it'll do the cross-platform thing for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I debated that move. Clearly not best practice the way I did it yet I am running on a PC and it is handling the "/" well.

I'll fix them all. I just wish the name for that function wasn't so long - hurts readability IMO

// vendor should have been created & populated
h.MustExist(h.Path(root + "/vendor/github.com/Sirupsen/logrus"))
for _, testCase := range tests {
runTest(t, testCase)
Copy link
Member

Choose a reason for hiding this comment

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

Same deal as above - let's use subtests here.

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

wantManifest := h.GetTestFileString(testCase.dataRoot + "/" + testCase.goldenManifest)
Copy link
Member

Choose a reason for hiding this comment

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

filepath.Join() again

gotManifest := h.ReadManifest()
if wantManifest != gotManifest {
if *test.UpdateGolden {
if err := h.WriteTestFile(testCase.dataRoot+"/"+testCase.goldenManifest, gotManifest); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

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.

(i'm not gonna explicitly note any more of these, i think you have the picture 😄 )

func main() {
err := nil
if err != nil {
deptestdos.diMeLo(bar.Qux)
Copy link
Member

Choose a reason for hiding this comment

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

While we don't currently do any actual code-level analysis (beyond import statements) during solving, it's possible we might add it in the future. If/when we do, these tests may start erroneously failing if they refer to nonexistent members in the deptest packages.

To guard against that possibility, let's make sure these input fixtures are valid uses of those packages - make sure you reference them somehow (so that it's not an unused import), but also make sure to only use types that are actually present.

Boring, I know 😈

"dependencies": {
"github.com/sdboyer/deptest": {
"version": ">=0.8.0, <1.0.0"
}
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I don't know what's going on here. Looking at how this is set up, it seems like this manifest really should have an entry for both deptest and deptestdos. Let's make sure we figure out why this is happening before merging - perhaps we've found a bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to #283

@sdboyer
Copy link
Member

sdboyer commented Mar 4, 2017

...actually, I think maybe we can delay further abstracting the harness until a subsequent PR.

@tro3
Copy link
Contributor Author

tro3 commented Mar 4, 2017

I do like the abstraction idea. Let's finish off the above review changes and merge, and I'll submit an "abstract test harness" issue where we can discuss the structure there in parallel, before I dive into the implementation.

This was referenced Mar 4, 2017
@sdboyer
Copy link
Member

sdboyer commented Mar 4, 2017

I think we're looking pretty good here. Anything else you want to add to it?

@tro3
Copy link
Contributor Author

tro3 commented Mar 5, 2017 via email

@sdboyer sdboyer closed this Mar 5, 2017
@sdboyer sdboyer reopened this Mar 5, 2017
@tro3
Copy link
Contributor Author

tro3 commented Mar 5, 2017 via email

@sdboyer
Copy link
Member

sdboyer commented Mar 5, 2017

got it - was just trying to make appveyor go green. really need to fix that :(

@sdboyer sdboyer merged commit f0384c3 into golang:master Mar 5, 2017
@tro3 tro3 deleted the issue255 branch March 5, 2017 00:34
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.

3 participants