Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for the test to run on windows #71

Merged
merged 2 commits into from
May 14, 2018

Conversation

fruch
Copy link
Contributor

@fruch fruch commented Mar 13, 2018

Utilize OS specific temp directories/files rather than relying on /tmp

@fruch fruch force-pushed the windows_test_fixs branch from 196d773 to 98b1926 Compare May 6, 2018 19:45
@fruch
Copy link
Contributor Author

fruch commented May 10, 2018

@promiseofcake can you also review this one ? it's quite straightforward and make the tests a bit more cross platform. (and my life as windows user a bit easier ;))

Copy link
Contributor

@promiseofcake promiseofcake left a comment

Choose a reason for hiding this comment

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

Few comments relating to DRY and error handling, but thanks for the patch!

@@ -210,7 +210,11 @@ func TestUpdateFeatures(t *testing.T) {
}`)

cfg := config.DefaultConfig()
cfg.Git.RepoPath = "/tmp"
dir, err := ioutil.TempDir("", "example")
Copy link
Contributor

Choose a reason for hiding this comment

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

May we generalize these into a shared function, something like this:

func TempDir(t *testing.T) string {
	dir, err := ioutil.TempDir(os.TempDir(), "dcdr")
	if err != nil {
		t.Fatalf("ioutil.TempDir error: %s", err.Error())
	}
	return dir
}

We can also use t.Fatalf to allow the test-suite to handle the error gracefully. Also we should prefix the directory with a related to this project: dcdr or similar.

Then from each test case we can call the parent function and not need to handle the errors:

dir := TempDir(t)
defer os.RemoveAll(dir)
cfg.Git.RepoPath = dir

c, _ := New(cfg)
c.UpdateFeatures(badUpdate)
assert.EqualValues(t, models.EmptyFeatureMap(), c.FeatureMap(), "Assert bad payload returns empty feature map")
}

func TestWatch(t *testing.T) {
p := "/tmp/decider.json"
tmpfile, err := ioutil.TempFile("", "example")
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's name this decider.json to be in line with what we are expecting. I know that the library assumes "" to be the default temporary directory, but maybe we can be more explicit with: os.TempDir().

It seems like it's up to us to clean up this file as well.

@@ -4,6 +4,8 @@ import (
"os/user"
"testing"

Copy link
Contributor

Choose a reason for hiding this comment

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

May we lint these imports? I know this was an error before you change but since you're here.

Copy link
Contributor Author

@fruch fruch May 14, 2018

Choose a reason for hiding this comment

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

I've fixed the other issues, but I'm not sure what exactly you mean like this imports... care to elabrate ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, it's a nitpick but the imports, the declarations for dependencies for this file, are not ordered properly:

import (
	"encoding/json"
	"io/ioutil"
	"log"
	"os"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/vsco/dcdr/config"
	"github.com/vsco/dcdr/models"
)

Unfortunately goimports does not catch this lint error due to the spaces between the groups yet, but work is being done here: golang/go#20818

This is not necessary to merge this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ordering of imports, got it (i'll try to noticed it next time around)

@@ -41,7 +43,12 @@ func TestDefaultConfig(t *testing.T) {
}

func TestEnvOverride(t *testing.T) {
os.Setenv(envConfigDirOverride, "/tmp/dcdr")
dir, err := ioutil.TempDir("", "example")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same, as above let's use a more relatable name.

@fruch
Copy link
Contributor Author

fruch commented May 14, 2018

seem like this flanky test failed me again...

@fruch
Copy link
Contributor Author

fruch commented May 14, 2018

@promiseofcake can you rerun it ? (insted of me pushing something again)

@promiseofcake promiseofcake requested a review from a team May 14, 2018 20:50
@fruch
Copy link
Contributor Author

fruch commented May 14, 2018

@promiseofcake I do love race conditions 😄
thanks for the re-run

@promiseofcake
Copy link
Contributor

@fruch, thanks for the contribution! Ah yes, we should fix that 😄.

@promiseofcake promiseofcake merged commit 595390d into vsco:master May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants