func TestUIInput_input(t *testing.T) { client, server := plugin.TestRPCConn(t) defer client.Close() i := new(terraform.MockUIInput) i.InputReturnString = "foo" err := server.RegisterName("Plugin", &UIInputServer{ UIInput: i, }) if err != nil { t.Fatalf("err: %s", err) } input := &UIInput{Client: client} opts := &terraform.InputOpts{ Id: "foo", } v, err := input.Input(opts) if !i.InputCalled { t.Fatal("input should be called") } if !reflect.DeepEqual(i.InputOpts, opts) { t.Fatalf("bad: %#v", i.InputOpts) } if err != nil { t.Fatalf("bad: %#v", err) } if v != "foo" { t.Fatalf("bad: %#v", v) } }
func TestSchemaMap_Input(t *testing.T) { cases := []struct { Schema map[string]*Schema Config map[string]interface{} Input map[string]string Result map[string]interface{} Err bool }{ /* * String decode */ { Schema: map[string]*Schema{ "availability_zone": &Schema{ Type: TypeString, Optional: true, }, }, Input: map[string]string{ "availability_zone": "foo", }, Result: map[string]interface{}{ "availability_zone": "foo", }, Err: false, }, { Schema: map[string]*Schema{ "availability_zone": &Schema{ Type: TypeString, Optional: true, }, }, Config: map[string]interface{}{ "availability_zone": "bar", }, Input: map[string]string{ "availability_zone": "foo", }, Result: map[string]interface{}{}, Err: false, }, { Schema: map[string]*Schema{ "availability_zone": &Schema{ Type: TypeString, Default: "foo", Optional: true, }, }, Input: map[string]string{ "availability_zone": "bar", }, Result: map[string]interface{}{}, Err: false, }, { Schema: map[string]*Schema{ "availability_zone": &Schema{ Type: TypeString, DefaultFunc: func() (interface{}, error) { return "foo", nil }, Optional: true, }, }, Input: map[string]string{ "availability_zone": "bar", }, Result: map[string]interface{}{}, Err: false, }, { Schema: map[string]*Schema{ "availability_zone": &Schema{ Type: TypeString, DefaultFunc: func() (interface{}, error) { return nil, nil }, Optional: true, }, }, Input: map[string]string{ "availability_zone": "bar", }, Result: map[string]interface{}{ "availability_zone": "bar", }, Err: false, }, } for i, tc := range cases { if tc.Config == nil { tc.Config = make(map[string]interface{}) } c, err := config.NewRawConfig(tc.Config) if err != nil { t.Fatalf("err: %s", err) } input := new(terraform.MockUIInput) input.InputReturnMap = tc.Input rc := terraform.NewResourceConfig(c) rc.Config = make(map[string]interface{}) actual, err := schemaMap(tc.Schema).Input(input, rc) if (err != nil) != tc.Err { t.Fatalf("#%d err: %s", i, err) } if !reflect.DeepEqual(tc.Result, actual.Config) { t.Fatalf("#%d: bad:\n\n%#v", i, actual.Config) } } }