moth

Monarch Of The Hill game server
git clone https://git.woozle.org/neale/moth.git

moth / cmd / mothd
Neale Pickett  ·  2021-10-13

theme_test.go

 1package main
 2
 3import (
 4	"io/ioutil"
 5	"testing"
 6
 7	"github.com/spf13/afero"
 8)
 9
10func NewTestTheme() *Theme {
11	return NewTheme(new(afero.MemMapFs))
12}
13
14func TestTheme(t *testing.T) {
15	s := NewTestTheme()
16
17	filename := "/index.html"
18	index := "this is the index"
19	afero.WriteFile(s.Fs, filename, []byte(index), 0644)
20	fileInfo, err := s.Fs.Stat(filename)
21	if err != nil {
22		t.Error(err)
23	}
24
25	if f, timestamp, err := s.Open("/index.html"); err != nil {
26		t.Error(err)
27	} else if buf, err := ioutil.ReadAll(f); err != nil {
28		t.Error(err)
29	} else if string(buf) != index {
30		t.Error("Read wrong value from index")
31	} else if !timestamp.Equal(fileInfo.ModTime()) {
32		t.Error("Timestamp compared wrong")
33	}
34
35	if f, _, err := s.Open("/foo/bar/index.html"); err == nil {
36		f.Close()
37		t.Error("Path is ignored")
38	}
39
40	if f, _, err := s.Open("nofile"); err == nil {
41		f.Close()
42		t.Error("Opening non-existent file didn't return an error")
43	}
44}