github.com/klaytn/klaytn@v1.12.1/cmd/utils/config_test.go (about) 1 package utils 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/urfave/cli/v2" 8 "github.com/urfave/cli/v2/altsrc" 9 ) 10 11 func newAppWithAction(action func(ctx *cli.Context) error) *cli.App { 12 app := cli.NewApp() 13 app.Flags = append(app.Flags, AllNodeFlags()...) 14 app.Before = func(ctx *cli.Context) error { 15 if err := altsrc.InitInputSourceWithContext( 16 AllNodeFlags(), 17 altsrc.NewYamlSourceFromFlagFunc("conf"), 18 )(ctx); err != nil { 19 return err 20 } 21 return nil 22 } 23 app.Action = action 24 return app 25 } 26 27 func TestLoadYaml(t *testing.T) { 28 testcases := map[string]bool{ 29 "conf": true, 30 "ntp.disable": true, 31 "ntp.server": true, 32 "docroot": false, 33 "bootnodes": true, 34 "identity": false, 35 "unlock": true, 36 "password": true, 37 "dbtype": true, 38 "datadir": false, 39 "overwrite-genesis": true, 40 "start-block-num": true, 41 "keystore": false, 42 "txpool.nolocals": true, 43 "txpool.allow-local-anchortx": true, 44 "txpool.deny.remotetx": true, 45 "txpool.journal": true, 46 "txpool.journal-interval": true, 47 "txpool.pricelimit": true, 48 "txpool.pricebump": true, 49 "txpool.exec-slots.account": true, 50 "txpool.exec-slots.all": true, 51 "txpool.nonexec-slots.account": true, 52 "txpool.nonexec-slots.all": true, 53 "txpool.lifetime": true, 54 "txpool.keeplocals": true, 55 "syncmode": false, 56 "gcmode": true, 57 "lightkdf": true, 58 "db.single": true, 59 "db.num-statetrie-shards": true, 60 "db.leveldb.compression": true, 61 "db.leveldb.no-buffer-pool": true, 62 "db.no-perf-metrics": true, 63 "db.dynamo.tablename": true, 64 "db.dynamo.region": true, 65 "db.dynamo.is-provisioned": true, 66 "db.dynamo.read-capacity": true, // TODO-check after bugfix 67 "db.dynamo.write-capacity": true, // TODO-check after bugfix 68 "db.dynamo.read-only": true, 69 "db.leveldb.cache-size": true, 70 "db.no-parallel-write": true, 71 "db.rocksdb.secondary": true, 72 "db.rocksdb.cache-size": true, 73 "db.rocksdb.dump-memory-stat": true, 74 "db.rocksdb.compression-type": true, 75 "db.rocksdb.bottommost-compression-type": true, 76 "db.rocksdb.filter-policy": true, 77 "db.rocksdb.disable-metrics": true, 78 "sendertxhashindexing": true, 79 "state.cache-size": true, 80 "state.block-interval": true, 81 "state.tries-in-memory": true, 82 "state.live-pruning": true, 83 "state.live-pruning-retention": true, 84 "cache.type": true, 85 "cache.scale": true, 86 "cache.level": false, 87 "cache.memory": true, 88 "statedb.cache.type": true, 89 "statedb.cache.num-fetcher-prefetch-worker": true, 90 "statedb.cache.use-snapshot-for-prefetch": true, 91 "state.trie-cache-limit": true, 92 "state.trie-cache-save-period": true, 93 "statedb.cache.redis.endpoints": true, 94 "statedb.cache.redis.cluster": true, 95 "statedb.cache.redis.publish": true, 96 "statedb.cache.redis.subscribe": true, 97 "port": true, 98 "subport": true, 99 "multichannel": true, 100 "maxconnections": true, 101 "maxRequestContentLength": true, 102 "maxpendpeers": true, 103 "targetgaslimit": true, 104 "nat": true, 105 "nodiscover": true, 106 "rwtimerwaittime": true, 107 "rwtimerinterval": true, 108 "netrestrict": false, 109 "nodekey": false, 110 "nodekeyhex": false, 111 "vmdebug": true, 112 "vmlog": true, 113 "vm.internaltx": true, 114 "networkid": true, 115 "metrics": true, 116 "prometheus": true, 117 "prometheusport": true, 118 "extradata": false, 119 "srvtype": true, 120 "autorestart.enable": true, 121 "autorestart.timeout": true, 122 "autorestart.daemon.path": true, 123 "config": false, 124 "api.filter.getLogs.maxitems": true, 125 "api.filter.getLogs.deadline": true, 126 "opcode-computation-cost-limit": true, 127 "snapshot": true, 128 "snapshot.cache-size": true, 129 "snapshot.async-gen": true, 130 "rpc": true, 131 "rpcaddr": true, 132 "rpcport": true, 133 "rpcapi": true, 134 "rpc.gascap": true, 135 "rpc.ethtxfeecap": true, 136 "rpccorsdomain": false, 137 "rpcvhosts": true, 138 "rpc.eth.noncompatible": true, 139 "ws": true, 140 "wsaddr": true, 141 "wsport": true, 142 "grpc": true, 143 "grpcaddr": true, 144 "grpcport": true, 145 "rpc.concurrencylimit": true, 146 "wsapi": true, 147 "wsorigins": true, 148 "wsmaxsubscriptionperconn": true, 149 "wsreaddeadline": true, // TODO-check after bugfix 150 "wswritedeadline": true, 151 "wsmaxconnections": true, 152 "ipcdisable": true, 153 "ipcpath": false, 154 "rpcreadtimeout": true, 155 "rpcwritetimeout": true, 156 "rpcidletimeout": true, 157 "rpcexecutiontimeout": true, 158 "jspath": true, 159 "exec": false, 160 "preload": false, 161 "verbosity": true, 162 "vmodule": true, 163 "backtrace": true, 164 "debug": true, 165 "pprof": true, 166 "pprofaddr": true, 167 "pprofport": true, 168 "memprofile": true, 169 "memprofilerate": true, 170 "blockprofilerate": true, 171 "cpuprofile": true, 172 "trace": true, 173 "chaindatafetcher": true, 174 "chaindatafetcher.mode": true, 175 "chaindatafetcher.no.default": true, 176 "chaindatafetcher.num.handlers": true, 177 "chaindatafetcher.job.channel.size": true, 178 "chaindatafetcher.block.channel.size": true, 179 "chaindatafetcher.max.processing.data.size": true, 180 "chaindatafetcher.kas.db.host": false, 181 "chaindatafetcher.kas.db.port": false, 182 "chaindatafetcher.kas.db.name": false, 183 "chaindatafetcher.kas.db.user": false, 184 "chaindatafetcher.kas.db.password": false, 185 "chaindatafetcher.kas.cache.use": false, 186 "chaindatafetcher.kas.cache.url": false, 187 "chaindatafetcher.kas.xchainid": false, 188 "chaindatafetcher.kas.basic.auth.param": false, 189 "chaindatafetcher.kafka.replicas": true, // TODO-check after bugfix 190 "chaindatafetcher.kafka.brokers": true, 191 "chaindatafetcher.kafka.partitions": true, 192 "chaindatafetcher.kafka.topic.resource": true, 193 "chaindatafetcher.kafka.topic.environment": true, 194 "chaindatafetcher.kafka.max.message.bytes": true, 195 "chaindatafetcher.kafka.segment.size": true, 196 "chaindatafetcher.kafka.required.acks": true, 197 "chaindatafetcher.kafka.msg.version": true, 198 "chaindatafetcher.kafka.producer.id": false, 199 "dst.dbtype": false, 200 "dst.datadir": false, 201 "db.dst.single": false, 202 "db.dst.leveldb.cache-size": false, 203 "db.dst.leveldb.compression": false, 204 "db.dst.num-statetrie-shards": false, 205 "db.dst.dynamo.tablename": false, 206 "db.dst.dynamo.region": false, 207 "db.dst.dynamo.is-provisioned": false, 208 "db.dst.dynamo.read-capacity": false, 209 "db.dst.dynamo.write-capacity": false, 210 "genkey": false, 211 "writeaddress": true, 212 "bnaddr": true, 213 "authorized-nodes": false, 214 "rewardbase": false, 215 "cypress": true, 216 "baobab": true, 217 "block-generation-interval": true, 218 "block-generation-time-limit": true, 219 "txresend.interval": true, 220 "txresend.max-count": true, 221 "txresend.use-legacy": true, 222 "txpool.spamthrottler.disable": true, 223 "scsigner": false, 224 "childchainindexing": true, 225 "mainbridge": true, 226 "mainbridgeport": true, 227 "kes.nodetype.service": true, 228 "dbsyncer": true, 229 "dbsyncer.db.host": true, 230 "dbsyncer.db.port": true, 231 "dbsyncer.db.name": true, 232 "dbsyncer.db.user": true, 233 "dbsyncer.db.password": true, 234 "dbsyncer.logmode": true, 235 "dbsyncer.db.max.idle": true, 236 "dbsyncer.db.max.open": true, 237 "dbsyncer.db.max.lifetime": true, 238 "dbsyncer.block.channel.size": true, 239 "dbsyncer.mode": true, 240 "dbsyncer.genquery.th": true, 241 "dbsyncer.insert.th": true, 242 "dbsyncer.bulk.size": true, 243 "dbsyncer.event.mode": true, 244 "dbsyncer.max.block.diff": true, 245 "chaintxperiod": true, 246 "chaintxlimit": true, 247 "subbridge": true, 248 "subbridgeport": true, 249 "parentchainid": true, 250 "vtrecovery": true, 251 "vtrecoveryinterval": true, 252 "scnewaccount": true, 253 "anchoring": true, 254 "sc.parentoperator.gaslimit": true, 255 "sc.childoperator.gaslimit": true, 256 "kas.sc.anchor": false, 257 "kas.sc.anchor.period": false, 258 "kas.sc.anchor.url": false, 259 "kas.sc.anchor.operator": false, 260 "kas.secretkey": false, 261 "kas.accesskey": false, 262 "kas.x-chain-id": false, 263 "kas.sc.anchor.request.timeout": false, 264 } 265 266 printFlags := func(ctx *cli.Context) error { 267 for _, flag := range AllNodeFlags() { 268 assert.Equal(t, testcases[flag.Names()[0]], ctx.IsSet(flag.Names()[0]), "IsSet returned unexpected result", flag.Names()[0]) 269 } 270 return nil 271 } 272 app := newAppWithAction(printFlags) 273 err := app.Run([]string{"testApp", "--conf", "nodecmd/testdata/test-config.yaml"}) 274 if err != nil { 275 t.Error(err) 276 } 277 }