Files
oddmu/static_cmd_test.go
Alex Schroeder 912b6baad0 Do not use Chdir
Using os.Chdir in the tests confuses the test process. This means
rewriting staticCli so that it accepts an input directory. When called
from the command-line, that input directory is always the current
working directory. For the tests, however, that is not necessarily
true.
2024-07-31 11:37:18 +02:00

45 lines
1.3 KiB
Go

package main
import (
"github.com/google/subcommands"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestStaticCmd(t *testing.T) {
cleanup(t, "testdata/static")
s := staticCli(".", "testdata/static", 2, true)
assert.Equal(t, subcommands.ExitSuccess, s)
// pages
assert.FileExists(t, "testdata/static/index.html")
assert.FileExists(t, "testdata/static/README.html")
// regular files
assert.FileExists(t, "testdata/static/static_cmd.go")
assert.FileExists(t, "testdata/static/static_cmd_test.go")
}
func TestFeedStaticCmd(t *testing.T) {
cleanup(t, "testdata/static-feed")
cleanup(t, "testdata/static-feed-out")
p := &Page{Name: "testdata/static-feed/Haiku", Body: []byte("# Haiku\n")}
p.save()
h := &Page{Name: "testdata/static-feed/2024-03-07-poem",
Body: []byte(`# Rain
I cannot hear you
The birds outside are singing
And the cars so loud
#Haiku
`)}
h.save()
h.notify()
s := staticCli("testdata/static-feed", "testdata/static-feed-out", 2, true)
assert.Equal(t, subcommands.ExitSuccess, s)
assert.FileExists(t, "testdata/static-feed-out/2024-03-07-poem.html")
assert.FileExists(t, "testdata/static-feed-out/Haiku.html")
b, err := os.ReadFile("testdata/static-feed-out/Haiku.rss")
assert.NoError(t, err)
assert.Contains(t, string(b), "<channel>")
}