media: Add missing BMP and GIF to the default MediaTypes list
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 21 Dec 2021 08:54:14 +0000 (09:54 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 22 Dec 2021 10:35:53 +0000 (11:35 +0100)
media/mediaType.go
media/mediaType_test.go
media/testdata/resource.bmp [new file with mode: 0644]
media/testdata/resource.gif [new file with mode: 0644]

index 18af666d59af7067e0ac589b339489b54ca42e1f..819de9d80281aaf2caba4dc676d988a421db15f1 100644 (file)
@@ -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.
index 8c739813d797edd3a4476db07d04034702d82c86..cd4439fe79bd8216d96dd11ca27c09e977d05309 100644 (file)
@@ -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 mode 100644 (file)
index 0000000..19759b3
Binary files /dev/null and b/media/testdata/resource.bmp differ
diff --git a/media/testdata/resource.gif b/media/testdata/resource.gif
new file mode 100644 (file)
index 0000000..9549c0b
Binary files /dev/null and b/media/testdata/resource.gif differ