moth/cmd/mothd/theme_test.go

34 lines
749 B
Go
Raw Normal View History

2019-12-05 22:25:03 -07:00
package main
import (
2020-02-29 18:36:59 -07:00
"io/ioutil"
2022-05-10 13:20:54 -06:00
"os"
2020-02-29 22:37:22 -07:00
"testing"
2019-12-05 22:25:03 -07:00
)
func TestTheme(t *testing.T) {
2022-05-10 13:20:54 -06:00
s := NewTheme("testdata/theme")
2019-12-05 22:25:03 -07:00
2020-08-14 20:26:04 -06:00
if f, timestamp, err := s.Open("/index.html"); err != nil {
2020-02-29 18:36:59 -07:00
t.Error(err)
} else if buf, err := ioutil.ReadAll(f); err != nil {
t.Error(err)
} else if string(buf) != index {
t.Error("Read wrong value from index")
2022-05-10 13:20:54 -06:00
} else if fi, err := os.Stat("testdata/theme/index.html"); err != nil {
t.Error(err)
} else if !timestamp.Equal(fi.ModTime()) {
2020-08-14 20:26:04 -06:00
t.Error("Timestamp compared wrong")
2019-12-05 22:25:03 -07:00
}
2020-08-21 17:02:38 -06:00
2021-10-13 16:43:51 -06:00
if f, _, err := s.Open("/foo/bar/index.html"); err == nil {
f.Close()
t.Error("Path is ignored")
}
2020-08-21 17:02:38 -06:00
if f, _, err := s.Open("nofile"); err == nil {
f.Close()
t.Error("Opening non-existent file didn't return an error")
}
2019-12-05 22:25:03 -07:00
}