github.com/clusterize-io/tusk@v0.6.3-0.20211001020217-cfe8a8cd0d4a/appcli/flag_test.go (about)

     1  package appcli
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/clusterize-io/tusk/runner"
     7  	"github.com/urfave/cli"
     8  )
     9  
    10  func TestCreateCLIFlag_undefined(t *testing.T) {
    11  	opt := &runner.Option{
    12  		Type: "wrong",
    13  	}
    14  
    15  	flag, err := createCLIFlag(opt)
    16  	if err == nil {
    17  		t.Fatalf("flag was wrongly created: %#v", flag)
    18  	}
    19  }
    20  
    21  func TestAddFlag_no_duplicates(t *testing.T) {
    22  	command := &cli.Command{}
    23  
    24  	opt := &runner.Option{
    25  		Name:  "foo",
    26  		Short: "f",
    27  	}
    28  
    29  	if err := addFlag(command, opt); err != nil {
    30  		t.Fatalf(`addFlag(): unexpected err: %s`, err)
    31  	}
    32  
    33  	if err := addFlag(command, opt); err != nil {
    34  		t.Fatalf(`addFlag(): unexpected err: %s`, err)
    35  	}
    36  
    37  	if len(command.Flags) != 1 {
    38  		t.Errorf(
    39  			`addFlag() twice with same flag: expected %d flags, actual %d`,
    40  			2, len(command.Flags),
    41  		)
    42  	}
    43  }