github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/http/header-content-type_test.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package http 4 5 import ( 6 "reflect" 7 "testing" 8 ) 9 10 func Test_getContentType(t *testing.T) { 11 type args struct { 12 contentType string 13 } 14 tests := []struct { 15 name string 16 args args 17 wantC ContentType 18 }{ 19 { 20 name: "test1", 21 args: args{ 22 contentType: "text/html; charset=utf-8", 23 }, 24 wantC: ContentType{ 25 Type: 1, 26 SubType: 1, 27 Charset: "utf-8", 28 }, 29 }, 30 { 31 name: "test2", 32 args: args{ 33 contentType: "application/json; charset=utf-8", 34 }, 35 wantC: ContentType{ 36 Type: 2, 37 SubType: 2, 38 Charset: "utf-8", 39 }, 40 }, 41 } 42 for _, tt := range tests { 43 t.Run(tt.name, func(t *testing.T) { 44 if gotC := getContentType(tt.args.contentType); !reflect.DeepEqual(gotC, tt.wantC) { 45 t.Errorf("getContentType() = %v, want %v", gotC, tt.wantC) 46 } 47 }) 48 } 49 }