github.com/klaytn/klaytn@v1.10.2/datasync/chaindatafetcher/types/types_test.go (about) 1 // Copyright 2020 The klaytn Authors 2 // This file is part of the klaytn library. 3 // 4 // The klaytn library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The klaytn library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>. 16 17 package types 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/assert" 23 ) 24 25 func TestHasDataType(t *testing.T) { 26 testdata := []RequestType{ 27 // single type 28 RequestTypeTransaction, 29 RequestTypeTokenTransfer, 30 RequestTypeTrace, 31 RequestTypeContract, 32 33 // 2 composite type 34 RequestTypeTransaction | RequestTypeTokenTransfer, 35 RequestTypeTransaction | RequestTypeTrace, 36 RequestTypeTransaction | RequestTypeContract, 37 RequestTypeTokenTransfer | RequestTypeTrace, 38 RequestTypeTokenTransfer | RequestTypeContract, 39 RequestTypeTrace | RequestTypeContract, 40 41 // 3 composite type 42 RequestTypeTransaction | RequestTypeTokenTransfer | RequestTypeTrace, 43 RequestTypeTransaction | RequestTypeTokenTransfer | RequestTypeContract, 44 RequestTypeTransaction | RequestTypeTrace | RequestTypeContract, 45 RequestTypeTokenTransfer | RequestTypeTrace | RequestTypeContract, 46 47 // all type 48 RequestTypeAll, 49 } 50 51 expected := [][]bool{ 52 // single type 53 {true, false, false, false}, 54 {false, true, false, false}, 55 {false, false, true, false}, 56 {false, false, false, true}, 57 58 // composite type 59 {true, true, false, false}, 60 {true, false, true, false}, 61 {true, false, false, true}, 62 {false, true, true, false}, 63 {false, true, false, true}, 64 {false, false, true, true}, 65 66 // 3 composite type 67 {true, true, true, false}, 68 {true, true, false, true}, 69 {true, false, true, true}, 70 {false, true, true, true}, 71 72 // all type 73 {true, true, true, true}, 74 } 75 76 targetType := []RequestType{ 77 RequestTypeTransaction, RequestTypeTokenTransfer, RequestTypeTrace, RequestTypeContract, 78 } 79 80 for idx, types := range testdata { 81 expectedTypes := expected[idx] 82 for idx, target := range targetType { 83 assert.Equal(t, expectedTypes[idx], CheckRequestType(types, target)) 84 } 85 } 86 }