2019-05-04 10:21:21 -04:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/csv"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
qt "github.com/frankban/quicktest"
|
2019-05-04 10:21:21 -04:00
|
|
|
)
|
|
|
|
|
2020-01-31 03:09:11 -05:00
|
|
|
func captureStdout(f func() error) (string, error) {
|
2019-05-04 10:21:21 -04:00
|
|
|
old := os.Stdout
|
|
|
|
r, w, _ := os.Pipe()
|
|
|
|
os.Stdout = w
|
|
|
|
|
2020-01-31 03:09:11 -05:00
|
|
|
err := f()
|
2019-05-04 10:21:21 -04:00
|
|
|
|
|
|
|
w.Close()
|
|
|
|
os.Stdout = old
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
io.Copy(&buf, r)
|
2020-01-31 03:09:11 -05:00
|
|
|
return buf.String(), err
|
2019-05-04 10:21:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestListAll(t *testing.T) {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2022-03-21 04:35:15 -04:00
|
|
|
dir := createSimpleTestSite(t, testSiteConfig{})
|
2019-05-04 10:21:21 -04:00
|
|
|
|
|
|
|
hugoCmd := newCommandsBuilder().addAll().build()
|
|
|
|
cmd := hugoCmd.getCommand()
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
os.RemoveAll(dir)
|
|
|
|
}()
|
|
|
|
|
|
|
|
cmd.SetArgs([]string{"-s=" + dir, "list", "all"})
|
|
|
|
|
2020-01-31 03:09:11 -05:00
|
|
|
out, err := captureStdout(func() error {
|
|
|
|
_, err := cmd.ExecuteC()
|
|
|
|
return err
|
|
|
|
})
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2019-05-04 10:21:21 -04:00
|
|
|
|
|
|
|
r := csv.NewReader(strings.NewReader(out))
|
|
|
|
|
|
|
|
header, err := r.Read()
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(header, qt.DeepEquals, []string{
|
2019-05-04 10:21:21 -04:00
|
|
|
"path", "slug", "title",
|
|
|
|
"date", "expiryDate", "publishDate",
|
|
|
|
"draft", "permalink",
|
2019-08-10 15:05:17 -04:00
|
|
|
})
|
2019-05-04 10:21:21 -04:00
|
|
|
|
|
|
|
record, err := r.Read()
|
2019-08-10 15:05:17 -04:00
|
|
|
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(record, qt.DeepEquals, []string{
|
2019-05-04 10:21:21 -04:00
|
|
|
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/",
|
2019-08-10 15:05:17 -04:00
|
|
|
})
|
2019-05-04 10:21:21 -04:00
|
|
|
}
|