summaryrefslogtreecommitdiff
path: root/libgo/go/mime/type_test.go
blob: 07e1cd5daecfbfb84896a582fd1c1b3be9eb1705 (plain)
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
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package mime

import "testing"

var typeTests = initMimeForTests()

func TestTypeByExtension(t *testing.T) {
	for ext, want := range typeTests {
		val := TypeByExtension(ext)
		if val != want {
			t.Errorf("TypeByExtension(%q) = %q, want %q", ext, val, want)
		}

	}
}

func TestCustomExtension(t *testing.T) {
	custom := "text/xml; charset=iso-8859-1"
	if error := AddExtensionType(".xml", custom); error != nil {
		t.Fatalf("error %s for AddExtension(%s)", error, custom)
	}
	if registered := TypeByExtension(".xml"); registered != custom {
		t.Fatalf("registered %s instead of %s", registered, custom)
	}
}