github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/pkg/mime/type_test.go (about) 1 // Copyright 2010 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package mime 6 7 import "testing" 8 9 var typeTests = initMimeForTests() 10 11 func TestTypeByExtension(t *testing.T) { 12 for ext, want := range typeTests { 13 val := TypeByExtension(ext) 14 if val != want { 15 t.Errorf("TypeByExtension(%q) = %q, want %q", ext, val, want) 16 } 17 18 } 19 } 20 21 func TestCustomExtension(t *testing.T) { 22 custom := "text/xml; charset=iso-8859-1" 23 if error := AddExtensionType(".xml", custom); error != nil { 24 t.Fatalf("error %s for AddExtension(%s)", error, custom) 25 } 26 if registered := TypeByExtension(".xml"); registered != custom { 27 t.Fatalf("registered %s instead of %s", registered, custom) 28 } 29 }