2019-12-05 22:25:03 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-02-29 18:36:59 -07:00
|
|
|
"io/ioutil"
|
2020-02-29 22:37:22 -07:00
|
|
|
"testing"
|
2020-08-14 20:26:04 -06:00
|
|
|
|
|
|
|
"github.com/spf13/afero"
|
2019-12-05 22:25:03 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTheme(t *testing.T) {
|
2020-08-14 20:26:04 -06:00
|
|
|
filename := "/index.html"
|
2019-12-05 22:25:03 -07:00
|
|
|
fs := new(afero.MemMapFs)
|
2020-02-29 18:36:59 -07:00
|
|
|
index := "this is the index"
|
2020-08-14 20:26:04 -06:00
|
|
|
afero.WriteFile(fs, filename, []byte(index), 0644)
|
|
|
|
fileInfo, err := fs.Stat(filename)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2019-12-05 22:25:03 -07:00
|
|
|
|
|
|
|
s := NewTheme(fs)
|
|
|
|
|
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")
|
2020-08-14 20:26:04 -06:00
|
|
|
} else if !timestamp.Equal(fileInfo.ModTime()) {
|
|
|
|
t.Error("Timestamp compared wrong")
|
2019-12-05 22:25:03 -07:00
|
|
|
}
|
|
|
|
}
|