Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
add test for setting custom types in struct field
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb committed Jul 18, 2017
1 parent d9897c9 commit 29c38da
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ type testSettable struct {
Value string
}

type testSettableStruct struct {
Settable testSettable `survey:"settable"`
}

func (t *testSettable) WriteAnswer(value interface{}) error {
if v, ok := value.(string); ok {
t.Value = v
Expand All @@ -274,6 +278,11 @@ func TestWriteWithSettable(t *testing.T) {
err = WriteAnswer(&testSet2, "prompt", 123)
assert.Error(t, fmt.Errorf("Incompatible type int64"), err)
assert.Equal(t, "", testSet2.Value)

testSetStruct := testSettableStruct{}
err = WriteAnswer(&testSetStruct, "settable", "stringVal1")
assert.Nil(t, err)
assert.Equal(t, testSetStruct.Settable.Value, "stringVal1")
}

type testFieldSettable struct {
Expand Down Expand Up @@ -302,7 +311,7 @@ func TestWriteWithFieldSettable(t *testing.T) {
assert.Error(t, fmt.Errorf("Incompatible type int64"), err)
assert.Equal(t, map[string]string{}, testSet2.Values)
}

// CONVERSION TESTS
func TestWrite_canStringToBool(t *testing.T) {
// a pointer to hold the boolean value
Expand Down

0 comments on commit 29c38da

Please sign in to comment.