github.com/prysmaticlabs/prysm@v1.4.4/cmd/slasher/usage_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/prysmaticlabs/prysm/shared/featureconfig"
     7  	"github.com/prysmaticlabs/prysm/shared/testutil/assert"
     8  	"github.com/urfave/cli/v2"
     9  )
    10  
    11  func TestAllFlagsExistInHelp(t *testing.T) {
    12  	// If this test is failing, it is because you've recently added/removed a
    13  	// flag in beacon chain main.go, but did not add/remove it to the usage.go
    14  	// flag grouping (appHelpFlagGroups).
    15  
    16  	var helpFlags []cli.Flag
    17  	for _, group := range appHelpFlagGroups {
    18  		helpFlags = append(helpFlags, group.Flags...)
    19  	}
    20  	helpFlags = featureconfig.ActiveFlags(helpFlags)
    21  	appFlags = featureconfig.ActiveFlags(appFlags)
    22  
    23  	for _, flag := range appFlags {
    24  		assert.Equal(t, true, doesFlagExist(flag, helpFlags), "Flag %s does not exist in help/usage flags.", flag.Names()[0])
    25  	}
    26  
    27  	for _, flag := range helpFlags {
    28  		assert.Equal(t, true, doesFlagExist(flag, appFlags), "Flag %s does not exist in main.go, but exists in help flags", flag.Names()[0])
    29  	}
    30  }
    31  
    32  func doesFlagExist(flag cli.Flag, flags []cli.Flag) bool {
    33  	for _, f := range flags {
    34  		if f.String() == flag.String() {
    35  			return true
    36  		}
    37  	}
    38  	return false
    39  }