From e29ede70556c2b5207032d30351f3b53a298ca0c Mon Sep 17 00:00:00 2001 From: Steve Francia Date: Tue, 8 Dec 2015 17:38:26 -0500 Subject: [PATCH] Fix some of the "new site" tests --- commands/new.go | 2 +- commands/new_test.go | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/commands/new.go b/commands/new.go index 39454e6c8..d465e83ff 100644 --- a/commands/new.go +++ b/commands/new.go @@ -15,12 +15,12 @@ package commands import ( "bytes" + "errors" "os" "path/filepath" "strings" "time" - "errors" "github.com/spf13/cobra" "github.com/spf13/hugo/create" "github.com/spf13/hugo/helpers" diff --git a/commands/new_test.go b/commands/new_test.go index 08d50f4ce..ceed82626 100644 --- a/commands/new_test.go +++ b/commands/new_test.go @@ -1,12 +1,13 @@ package commands import ( - "github.com/spf13/afero" - "github.com/spf13/hugo/hugofs" - "github.com/stretchr/testify/assert" "os" "path/filepath" "testing" + + "github.com/spf13/afero" + "github.com/spf13/hugo/hugofs" + "github.com/stretchr/testify/assert" ) // Issue #1133 @@ -41,10 +42,20 @@ func TestDoNewSite(t *testing.T) { checkNewSiteInited(basepath, t) } +func TestDoNewSite_noerror_base_exists_but_empty(t *testing.T) { + basepath := filepath.Join(os.TempDir(), "blog") + hugofs.SourceFs = new(afero.MemMapFs) + hugofs.SourceFs.MkdirAll(basepath, 777) + err := doNewSite(basepath, false) + assert.Nil(t, err) +} + func TestDoNewSite_error_base_exists(t *testing.T) { basepath := filepath.Join(os.TempDir(), "blog") hugofs.SourceFs = new(afero.MemMapFs) hugofs.SourceFs.MkdirAll(basepath, 777) + hugofs.SourceFs.Create(filepath.Join(basepath, "foo")) + // Since the directory already exists and isn't empty, expect an error err := doNewSite(basepath, false) assert.NotNil(t, err) } @@ -59,8 +70,7 @@ func TestDoNewSite_force_empty_dir(t *testing.T) { checkNewSiteInited(basepath, t) } -// TODO(spf13): Fix and re-enable this. -func _TestDoNewSite_error_force_dir_inside_exists(t *testing.T) { +func TestDoNewSite_error_force_dir_inside_exists(t *testing.T) { basepath := filepath.Join(os.TempDir(), "blog") contentPath := filepath.Join(basepath, "content") hugofs.SourceFs = new(afero.MemMapFs)