forked from mirror/oddmu
Starting a go routine that walks the directory tree, adding files to a tasks channel and then closing it; starting a bunch of worker go routines that take files from the tasks channel until there is nothing left to do; putting errors on a results channel and when they’re done, putting a true value on a done channel; a watcher go routine that checks the done channel and if every worker is done, close the results channel; and the main program goes through all the values on the results channel and sets up some short-circuiting in the case of errors and otherwise it prints the counter. What a glorious spaghetti mess of code!
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/google/subcommands"
|
|
"github.com/stretchr/testify/assert"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestStatusCmd(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 TestFeedStatusCmd(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()
|
|
wd, err := os.Getwd()
|
|
assert.NoError(t, err)
|
|
assert.NoError(t, os.Chdir("testdata/static-feed"))
|
|
s := staticCli("../static-feed-out/", 2, true)
|
|
assert.Equal(t, subcommands.ExitSuccess, s)
|
|
assert.NoError(t, os.Chdir(wd))
|
|
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>")
|
|
}
|