Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuslan Nasonov <rus.nasonov@gmail.com>2019-05-04 17:21:21 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-05-25 01:09:51 +0300
commit5b4b8bb3c1ecb30e7a38ed44eb795f1d972cd320 (patch)
tree7c8bf6446788bff324e83137e3ec543fcc29aec9 /commands/list_test.go
parent2278b0eb02ccdd3c2d4358d39074767d33fecb71 (diff)
commands: Create new 'hugo list all' command
New: - command `hugo list all`, return all posts meta in csv format Refactoring: - move common parts in commands/list.go to function `buildSites` - change way to detect path to content See #5904
Diffstat (limited to 'commands/list_test.go')
-rw-r--r--commands/list_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/commands/list_test.go b/commands/list_test.go
new file mode 100644
index 000000000..f2ce70010
--- /dev/null
+++ b/commands/list_test.go
@@ -0,0 +1,70 @@
+package commands
+
+import (
+ "bytes"
+ "encoding/csv"
+ "io"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/spf13/cobra"
+ "github.com/stretchr/testify/require"
+)
+
+func captureStdout(f func() (*cobra.Command, error)) (string, error) {
+ old := os.Stdout
+ r, w, _ := os.Pipe()
+ os.Stdout = w
+
+ _, err := f()
+
+ if err != nil {
+ return "", err
+ }
+
+ w.Close()
+ os.Stdout = old
+
+ var buf bytes.Buffer
+ io.Copy(&buf, r)
+ return buf.String(), nil
+}
+
+func TestListAll(t *testing.T) {
+ assert := require.New(t)
+ dir, err := createSimpleTestSite(t, testSiteConfig{})
+
+ assert.NoError(err)
+
+ hugoCmd := newCommandsBuilder().addAll().build()
+ cmd := hugoCmd.getCommand()
+
+ defer func() {
+ os.RemoveAll(dir)
+ }()
+
+ cmd.SetArgs([]string{"-s=" + dir, "list", "all"})
+
+ out, err := captureStdout(cmd.ExecuteC)
+ assert.NoError(err)
+
+ r := csv.NewReader(strings.NewReader(out))
+
+ header, err := r.Read()
+ assert.NoError(err)
+
+ assert.Equal([]string{
+ "path", "slug", "title",
+ "date", "expiryDate", "publishDate",
+ "draft", "permalink",
+ }, header)
+
+ record, err := r.Read()
+ assert.Equal([]string{
+ filepath.Join("content", "p1.md"), "", "P1",
+ "0001-01-01T00:00:00Z", "0001-01-01T00:00:00Z", "0001-01-01T00:00:00Z",
+ "false", "https://example.org/p1/",
+ }, record)
+}