...

Source file src/github.com/urfave/cli/v2/altsrc/map_input_source_test.go

Documentation: github.com/urfave/cli/v2/altsrc

     1  package altsrc
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  )
     8  
     9  func TestMapDuration(t *testing.T) {
    10  	inputSource := NewMapInputSource(
    11  		"test",
    12  		map[interface{}]interface{}{
    13  			"duration_of_duration_type": time.Minute,
    14  			"duration_of_string_type":   "1m",
    15  			"duration_of_int_type":      1000,
    16  		})
    17  	d, err := inputSource.Duration("duration_of_duration_type")
    18  	expect(t, time.Minute, d)
    19  	expect(t, nil, err)
    20  	d, err = inputSource.Duration("duration_of_string_type")
    21  	expect(t, time.Minute, d)
    22  	expect(t, nil, err)
    23  	_, err = inputSource.Duration("duration_of_int_type")
    24  	refute(t, nil, err)
    25  }
    26  
    27  func TestMapInputSource_Int64Slice(t *testing.T) {
    28  	inputSource := NewMapInputSource(
    29  		"test",
    30  		map[interface{}]interface{}{
    31  			"test_num": []interface{}{int64(1), int64(2), int64(3)},
    32  		})
    33  	d, err := inputSource.Int64Slice("test_num")
    34  	expect(t, []int64{1, 2, 3}, d)
    35  	expect(t, nil, err)
    36  }
    37  
    38  func TestMapInputSource_IncorrectFlagTypeError(t *testing.T) {
    39  	var testVal *bool
    40  	expect(t, incorrectTypeForFlagError("test", "bool", testVal), fmt.Errorf("Mismatched type for flag 'test'. Expected 'bool' but actual is '*bool'"))
    41  }
    42  

View as plain text