aboutsummaryrefslogtreecommitdiff
path: root/lib/memfs/memfs_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-05-04 13:22:39 +0700
committerShulhan <ms@kilabit.info>2021-05-04 13:28:56 +0700
commit0156b4eb4b25d48d4e8f16606aef6da8a596aedb (patch)
tree47225648e147d16245cbcd7cea57245ba9015543 /lib/memfs/memfs_test.go
parent32cdac5631d3b01bab58e8f5ff8955df9014eddd (diff)
downloadpakakeh.go-0156b4eb4b25d48d4e8f16606aef6da8a596aedb.tar.xz
memfs: fix test by checking multiple content-types
On Arch Linux with Go tip, the content-type for JavaScript file is "text/javascript". While on Ubuntu with Go 1.16 the content-type for JavaScript file is "application/javascript".
Diffstat (limited to 'lib/memfs/memfs_test.go')
-rw-r--r--lib/memfs/memfs_test.go53
1 files changed, 38 insertions, 15 deletions
diff --git a/lib/memfs/memfs_test.go b/lib/memfs/memfs_test.go
index 9f72e6b3..fc680401 100644
--- a/lib/memfs/memfs_test.go
+++ b/lib/memfs/memfs_test.go
@@ -108,7 +108,7 @@ func TestGet(t *testing.T) {
cases := []struct {
path string
expV []byte
- expContentType string
+ expContentType []string
expErr error
}{{
path: "/",
@@ -120,14 +120,17 @@ func TestGet(t *testing.T) {
}, {
path: "/exclude/index.css",
expV: []byte("body {\n}\n"),
- expContentType: "text/css; charset=utf-8",
+ expContentType: []string{"text/css; charset=utf-8"},
}, {
path: "/exclude/index.html",
expV: []byte("<html></html>\n"),
- expContentType: "text/html; charset=utf-8",
+ expContentType: []string{"text/html; charset=utf-8"},
}, {
- path: "/exclude/index.js",
- expContentType: "text/javascript; charset=utf-8",
+ path: "/exclude/index.js",
+ expContentType: []string{
+ "text/javascript; charset=utf-8",
+ "application/javascript",
+ },
}, {
path: "/include",
}, {
@@ -136,28 +139,34 @@ func TestGet(t *testing.T) {
}, {
path: "/include/index.css",
expV: []byte("body {\n}\n"),
- expContentType: "text/css; charset=utf-8",
+ expContentType: []string{"text/css; charset=utf-8"},
}, {
path: "/include/index.html",
expV: []byte("<html></html>\n"),
- expContentType: "text/html; charset=utf-8",
+ expContentType: []string{"text/html; charset=utf-8"},
}, {
- path: "/include/index.js",
- expContentType: "text/javascript; charset=utf-8",
+ path: "/include/index.js",
+ expContentType: []string{
+ "text/javascript; charset=utf-8",
+ "application/javascript",
+ },
}, {
path: "/index.css",
expV: []byte("body {\n}\n"),
- expContentType: "text/css; charset=utf-8",
+ expContentType: []string{"text/css; charset=utf-8"},
}, {
path: "/index.html",
expV: []byte("<html></html>\n"),
- expContentType: "text/html; charset=utf-8",
+ expContentType: []string{"text/html; charset=utf-8"},
}, {
- path: "/index.js",
- expContentType: "text/javascript; charset=utf-8",
+ path: "/index.js",
+ expContentType: []string{
+ "text/javascript; charset=utf-8",
+ "application/javascript",
+ },
}, {
path: "/plain",
- expContentType: "application/octet-stream",
+ expContentType: []string{"application/octet-stream"},
}}
dir := filepath.Join(_testWD, "/testdata")
@@ -186,7 +195,21 @@ func TestGet(t *testing.T) {
test.Assert(t, "node.V", c.expV, got.V)
}
- test.Assert(t, "node.ContentType", c.expContentType, got.ContentType)
+ if len(got.ContentType) == 0 && len(c.expContentType) == 0 {
+ continue
+ }
+
+ found := false
+ for _, expCT := range c.expContentType {
+ if expCT == got.ContentType {
+ found = true
+ break
+ }
+ }
+ if !found {
+ t.Errorf("expecting one of the Content-Type %v, got %s",
+ c.expContentType, got.ContentType)
+ }
}
}