github.com/lbryio/lbcd@v0.22.119/rpcserverhelp_test.go (about) 1 // Copyright (c) 2015 The btcsuite developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import "testing" 8 9 // TestHelp ensures the help is reasonably accurate by checking that every 10 // command specified also has result types defined and the one-line usage and 11 // help text can be generated for them. 12 func TestHelp(t *testing.T) { 13 // Ensure there are result types specified for every handler. 14 for k := range rpcHandlers { 15 if _, ok := rpcResultTypes[k]; !ok { 16 t.Errorf("RPC handler defined for method '%v' without "+ 17 "also specifying result types", k) 18 continue 19 } 20 21 } 22 for k := range wsHandlers { 23 if _, ok := rpcResultTypes[k]; !ok { 24 t.Errorf("RPC handler defined for method '%v' without "+ 25 "also specifying result types", k) 26 continue 27 } 28 29 } 30 31 // Ensure the usage for every command can be generated without errors. 32 helpCacher := newHelpCacher() 33 if _, err := helpCacher.rpcUsage(true); err != nil { 34 t.Fatalf("Failed to generate one-line usage: %v", err) 35 } 36 if _, err := helpCacher.rpcUsage(true); err != nil { 37 t.Fatalf("Failed to generate one-line usage (cached): %v", err) 38 } 39 40 // Ensure the help for every command can be generated without errors. 41 for k := range rpcHandlers { 42 if _, err := helpCacher.rpcMethodHelp(k); err != nil { 43 t.Errorf("Failed to generate help for method '%v': %v", 44 k, err) 45 continue 46 } 47 if _, err := helpCacher.rpcMethodHelp(k); err != nil { 48 t.Errorf("Failed to generate help for method '%v'"+ 49 "(cached): %v", k, err) 50 continue 51 } 52 } 53 for k := range wsHandlers { 54 if _, err := helpCacher.rpcMethodHelp(k); err != nil { 55 t.Errorf("Failed to generate help for method '%v': %v", 56 k, err) 57 continue 58 } 59 if _, err := helpCacher.rpcMethodHelp(k); err != nil { 60 t.Errorf("Failed to generate help for method '%v'"+ 61 "(cached): %v", k, err) 62 continue 63 } 64 } 65 }