hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

list_test.go (1245B)

    1 package commands
    2 
    3 import (
    4 	"bytes"
    5 	"encoding/csv"
    6 	"io"
    7 	"os"
    8 	"path/filepath"
    9 	"strings"
   10 	"testing"
   11 
   12 	qt "github.com/frankban/quicktest"
   13 )
   14 
   15 func captureStdout(f func() error) (string, error) {
   16 	old := os.Stdout
   17 	r, w, _ := os.Pipe()
   18 	os.Stdout = w
   19 
   20 	err := f()
   21 
   22 	w.Close()
   23 	os.Stdout = old
   24 
   25 	var buf bytes.Buffer
   26 	io.Copy(&buf, r)
   27 	return buf.String(), err
   28 }
   29 
   30 func TestListAll(t *testing.T) {
   31 	c := qt.New(t)
   32 	dir := createSimpleTestSite(t, testSiteConfig{})
   33 
   34 	hugoCmd := newCommandsBuilder().addAll().build()
   35 	cmd := hugoCmd.getCommand()
   36 
   37 	t.Cleanup(func() {
   38 		os.RemoveAll(dir)
   39 	})
   40 
   41 	cmd.SetArgs([]string{"-s=" + dir, "list", "all"})
   42 
   43 	out, err := captureStdout(func() error {
   44 		_, err := cmd.ExecuteC()
   45 		return err
   46 	})
   47 	c.Assert(err, qt.IsNil)
   48 
   49 	r := csv.NewReader(strings.NewReader(out))
   50 
   51 	header, err := r.Read()
   52 
   53 	c.Assert(err, qt.IsNil)
   54 	c.Assert(header, qt.DeepEquals, []string{
   55 		"path", "slug", "title",
   56 		"date", "expiryDate", "publishDate",
   57 		"draft", "permalink",
   58 	})
   59 
   60 	record, err := r.Read()
   61 
   62 	c.Assert(err, qt.IsNil)
   63 	c.Assert(record, qt.DeepEquals, []string{
   64 		filepath.Join("content", "p1.md"), "", "P1",
   65 		"0001-01-01T00:00:00Z", "0001-01-01T00:00:00Z", "0001-01-01T00:00:00Z",
   66 		"false", "https://example.org/p1/",
   67 	})
   68 }