github.com/BlockABC/godash@v0.0.0-20191112120524-f4aa3a32c566/rpcserverhelp_test.go (about)

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