Skip to content

Commit

Permalink
Fixes for the test to run on windows (#71)
Browse files Browse the repository at this point in the history
* Fixes for the test to run on windows
* Fix code-review comments
  • Loading branch information
fruch authored and promiseofcake committed May 14, 2018
1 parent e3a1ff2 commit 595390d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
19 changes: 16 additions & 3 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ func NewTestClient() (c *Client) {
return
}

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
}

var JSONBytes = []byte(`{
"dcdr": {
"features": {
Expand Down Expand Up @@ -210,7 +218,9 @@ func TestUpdateFeatures(t *testing.T) {
}`)

cfg := config.DefaultConfig()
cfg.Git.RepoPath = "/tmp"
dir := TempDir(t)
defer os.RemoveAll(dir)
cfg.Git.RepoPath = dir
c, _ := New(cfg)
c.UpdateFeatures(raw)

Expand All @@ -235,14 +245,17 @@ func TestClient_UpdateFeatures_Failure(t *testing.T) {
},`)

cfg := config.DefaultConfig()
cfg.Git.RepoPath = "/tmp"
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(os.TempDir(), "dcdr.json")
p := tmpfile.Name()
fm, err := models.NewFeatureMap(JSONBytes)
assert.NoError(t, err)
err = ioutil.WriteFile(p, JSONBytes, 0644)
Expand Down
15 changes: 14 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ import (
"os/user"
"testing"

"io/ioutil"

"os"

"fmt"

"github.com/stretchr/testify/assert"
)

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
}

func TestDefaultConfig(t *testing.T) {
ConfigDir = "/tmp/does/not/exist"
cfg := LoadConfig()
Expand Down Expand Up @@ -41,7 +51,10 @@ func TestDefaultConfig(t *testing.T) {
}

func TestEnvOverride(t *testing.T) {
os.Setenv(envConfigDirOverride, "/tmp/dcdr")
dir := TempDir(t)
defer os.RemoveAll(dir)

os.Setenv(envConfigDirOverride, dir)
cfg := LoadConfig()

assert.Equal(t, Path(), fmt.Sprintf("%s/%s", os.Getenv(envConfigDirOverride), configFileName))
Expand Down

0 comments on commit 595390d

Please sign in to comment.