Skip to content

Commit

Permalink
media: Add missing BMP and GIF to the default MediaTypes list
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Dec 22, 2021
1 parent cdc7352 commit ce04011
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions media/mediaType.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ var DefaultTypes = Types{
YAMLType,
TOMLType,
PNGType,
GIFType,
BMPType,
JPEGType,
WEBPType,
AVIType,
Expand All @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion media/mediaType_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package media

import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
"sort"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
Binary file added media/testdata/resource.bmp
Binary file not shown.
Binary file added media/testdata/resource.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ce04011

Please sign in to comment.