forked from manno/xsltd-web
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchaospage_test.go
53 lines (45 loc) · 1.18 KB
/
chaospage_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"io/ioutil"
"log"
"os"
"testing"
)
func TestStylesheet(t *testing.T) {
webRoot := "/home/www"
var tests = []struct {
content string
expected string
}{
{`<?xml-stylesheet href="/xsl/page_sub.xsl" type="text/xsl"?>`, "/xsl/page_sub.xsl"},
{`<?xml-stylesheet href="xsl/page_sub.xsl" type="text/xsl"?>`, "/xsl/page_sub.xsl"},
{`<?xml-stylesheet href="/xsl/page_teaser.xsl" type="text/xsl"?>`, "/xsl/page_teaser.xsl"},
{`<?xml-stylesheet href="xsl/page_index.xsl" type="text/xsl"?>`, "/xsl/page_index.xsl"},
}
for _, test := range tests {
tmpfile := NewTempFile(test.content)
defer os.Remove(tmpfile.Name())
c := NewChaosPage(webRoot, tmpfile.Name())
s, err := c.Stylesheet()
if err != nil {
t.Error("did not expect error")
}
if s != webRoot+test.expected {
t.Errorf("expected %s, got: %s", webRoot+test.expected, s)
}
os.Remove(tmpfile.Name())
}
}
func NewTempFile(content string) *os.File {
tmpfile, err := ioutil.TempFile("", "example")
if err != nil {
log.Fatal(err)
}
if _, err := tmpfile.WriteString(content); err != nil {
log.Fatal(err)
}
if err := tmpfile.Close(); err != nil {
log.Fatal(err)
}
return tmpfile
}