github.com/WindomZ/go-commander@v1.2.2/actor_test.go (about)

     1  package commander
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/WindomZ/testify/assert"
     6  	"testing"
     7  )
     8  
     9  func TestActor_IncludeKeys(t *testing.T) {
    10  	var a actor
    11  	var pass bool
    12  	a.addIncludeKeys([]string{"a", "b", "c"})
    13  	for _, key := range a.getIncludeKeys() {
    14  		pass = false
    15  		for _, k := range []string{"a", "b", "c"} {
    16  			if key == k {
    17  				pass = true
    18  			}
    19  		}
    20  		if !pass {
    21  			assert.FailNow(t, fmt.Sprintf("Error: %v", a.getIncludeKeys()))
    22  		}
    23  	}
    24  }
    25  
    26  func TestActor_ExcludeKeys(t *testing.T) {
    27  	var a actor
    28  	var pass bool
    29  	a.addExcludeKeys([]string{"a", "b", "c"})
    30  	for _, key := range a.getExcludeKeys() {
    31  		pass = false
    32  		for _, k := range []string{"a", "b", "c"} {
    33  			if key == k {
    34  				pass = true
    35  			}
    36  		}
    37  		if !pass {
    38  			assert.FailNow(t, fmt.Sprintf("Error: %v", a.getExcludeKeys()))
    39  		}
    40  	}
    41  }
    42  
    43  func TestActor_Action(t *testing.T) {
    44  	var result bool
    45  	var a actor
    46  	a.Action(func(c Context) {
    47  		result = true
    48  		assert.Equal(t, c.MustBool("a"), true)
    49  		assert.Equal(t, c.MustBool("b"), true)
    50  		assert.Equal(t, c.MustBool("c"), true)
    51  		assert.Equal(t, c.MustBool("d"), false)
    52  	}, []string{"a", "b", "c"})
    53  
    54  	a.run(newContext(nil, newDocoptMap(
    55  		map[string]interface{}{
    56  			"a": true,
    57  			"b": true,
    58  			"c": false,
    59  		},
    60  	),
    61  	))
    62  	assert.Equal(t, result, false)
    63  
    64  	a.run(newContext(nil, newDocoptMap(
    65  		map[string]interface{}{
    66  			"a": true,
    67  			"b": true,
    68  			"c": true,
    69  		},
    70  	),
    71  	))
    72  	assert.Equal(t, result, true)
    73  }