github.com/alimy/mir/v4@v4.1.0/internal/utils/set_method_test.go (about) 1 // Copyright 2022 Michael Li <alimy@gility.net>. All rights reserved. 2 // Use of this source code is governed by Apache License 2.0 that 3 // can be found in the LICENSE file. 4 5 package utils 6 7 import ( 8 "net/http" 9 "testing" 10 ) 11 12 func TestMethodSet_Add_List(t *testing.T) { 13 for _, data := range []struct { 14 input []string 15 expect []string 16 }{ 17 { 18 input: []string{http.MethodGet}, 19 expect: []string{http.MethodGet}, 20 }, 21 { 22 input: []string{"others"}, 23 expect: []string{}, 24 }, 25 { 26 input: []string{ 27 http.MethodGet, 28 http.MethodHead, 29 http.MethodPost, 30 http.MethodPut, 31 http.MethodPatch, 32 http.MethodDelete, 33 http.MethodConnect, 34 http.MethodOptions, 35 http.MethodTrace, 36 "others", 37 "notbeincludes", 38 }, 39 expect: []string{ 40 http.MethodGet, 41 http.MethodHead, 42 http.MethodPost, 43 http.MethodPut, 44 http.MethodPatch, 45 http.MethodDelete, 46 http.MethodConnect, 47 http.MethodOptions, 48 http.MethodTrace, 49 }, 50 }, 51 } { 52 ms := HttpMethodSet{} 53 ms.Add(data.input...) 54 list := ms.List() 55 if len(list) != len(data.expect) { 56 t.Errorf("want list length=%d but got %d", len(data.expect), len(list)) 57 } 58 59 Top: 60 for _, lv := range list { 61 for _, ev := range data.expect { 62 if lv == ev { 63 continue Top 64 } 65 } 66 t.Errorf("want list %v but got %v", data.expect, list) 67 } 68 } 69 }