From ce04011096456c77479fa98a6ceee242aeac7919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 21 Dec 2021 09:54:14 +0100 Subject: [PATCH] media: Add missing BMP and GIF to the default MediaTypes list --- media/mediaType.go | 11 +++++++++++ media/mediaType_test.go | 4 +++- media/testdata/resource.bmp | Bin 0 -> 65334 bytes media/testdata/resource.gif | Bin 0 -> 161 bytes 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 media/testdata/resource.bmp create mode 100644 media/testdata/resource.gif diff --git a/media/mediaType.go b/media/mediaType.go index 18af666d59a..819de9d8028 100644 --- a/media/mediaType.go +++ b/media/mediaType.go @@ -274,6 +274,8 @@ var DefaultTypes = Types{ YAMLType, TOMLType, PNGType, + GIFType, + BMPType, JPEGType, WEBPType, AVIType, @@ -289,6 +291,15 @@ var DefaultTypes = Types{ func init() { sort.Sort(DefaultTypes) + + // Sanity check. + seen := make(map[Type]bool) + for _, t := range DefaultTypes { + if seen[t] { + panic(fmt.Sprintf("MediaType %s duplicated in list", t)) + } + seen[t] = true + } } // Types is a slice of media types. diff --git a/media/mediaType_test.go b/media/mediaType_test.go index 8c739813d79..cd4439fe79b 100644 --- a/media/mediaType_test.go +++ b/media/mediaType_test.go @@ -15,6 +15,7 @@ package media import ( "encoding/json" + "fmt" "io/ioutil" "path/filepath" "sort" @@ -63,7 +64,7 @@ func TestDefaultTypes(t *testing.T) { } - c.Assert(len(DefaultTypes), qt.Equals, 31) + c.Assert(len(DefaultTypes), qt.Equals, 33) } func TestGetByType(t *testing.T) { @@ -193,6 +194,7 @@ func TestFromContent(t *testing.T) { content, err := ioutil.ReadFile(filename) c.Assert(err, qt.IsNil) ext := strings.TrimPrefix(paths.Ext(filename), ".") + fmt.Println("=>", ext) expected, _, found := mtypes.GetFirstBySuffix(ext) c.Assert(found, qt.IsTrue) got := FromContent(mtypes, ext, content) diff --git a/media/testdata/resource.bmp b/media/testdata/resource.bmp new file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