func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData, zoneName string) (*route53.ResourceRecordSet, error) { recs := d.Get("records").(*schema.Set).List() records := make([]route53.ResourceRecord, 0, len(recs)) typeStr := d.Get("type").(string) for _, r := range recs { switch typeStr { case "TXT": str := fmt.Sprintf("\"%s\"", r.(string)) records = append(records, route53.ResourceRecord{Value: aws.String(str)}) default: records = append(records, route53.ResourceRecord{Value: aws.String(r.(string))}) } } // get expanded name en := expandRecordName(d.Get("name").(string), zoneName) // Create the RecordSet request with the fully expanded name, e.g. // sub.domain.com. Route 53 requires a fully qualified domain name, but does // not require the trailing ".", which it will itself, so we don't call FQDN // here. rec := &route53.ResourceRecordSet{ Name: aws.String(en), Type: aws.String(d.Get("type").(string)), TTL: aws.Long(int64(d.Get("ttl").(int))), ResourceRecords: records, } return rec, nil }
func TestQueryRequest(t *testing.T) { var m sync.Mutex var httpReq *http.Request var form url.Values server := httptest.NewServer(http.HandlerFunc( func(w http.ResponseWriter, r *http.Request) { m.Lock() defer m.Unlock() httpReq = r if err := r.ParseForm(); err != nil { t.Fatal(err) } form = r.Form fmt.Fprintln(w, `<Thing><IpAddress>woo</IpAddress></Thing>`) }, )) defer server.Close() client := aws.QueryClient{ Context: aws.Context{ Service: "animals", Region: "us-west-2", Credentials: aws.Creds( "accessKeyID", "secretAccessKey", "securityToken", ), }, Client: http.DefaultClient, Endpoint: server.URL, APIVersion: "1.1", } req := fakeQueryRequest{ PresentString: aws.String("string"), PresentBoolean: aws.True(), PresentInteger: aws.Integer(1), PresentLong: aws.Long(2), PresentDouble: aws.Double(1.2), PresentFloat: aws.Float(2.3), PresentTime: time.Date(2001, 1, 1, 2, 1, 1, 0, time.FixedZone("UTC+1", 3600)), PresentSlice: []string{"one", "two"}, PresentStruct: &EmbeddedStruct{Value: aws.String("v")}, PresentStructSlice: []EmbeddedStruct{ {Value: aws.String("p")}, {Value: aws.String("q")}, }, PresentMap: map[string]EmbeddedStruct{ "aa": EmbeddedStruct{Value: aws.String("AA")}, "bb": EmbeddedStruct{Value: aws.String("BB")}, }, } var resp fakeQueryResponse if err := client.Do("GetIP", "POST", "/", &req, &resp); err != nil { t.Fatal(err) } m.Lock() defer m.Unlock() if v, want := httpReq.Method, "POST"; v != want { t.Errorf("Method was %v but expected %v", v, want) } if httpReq.Header.Get("Authorization") == "" { t.Error("Authorization header is missing") } if v, want := httpReq.Header.Get("Content-Type"), "application/x-www-form-urlencoded"; v != want { t.Errorf("Content-Type was %v but expected %v", v, want) } if v, want := httpReq.Header.Get("User-Agent"), "aws-go"; v != want { t.Errorf("User-Agent was %v but expected %v", v, want) } if err := httpReq.ParseForm(); err != nil { t.Fatal(err) } expectedForm := url.Values{ "Action": []string{"GetIP"}, "Version": []string{"1.1"}, "PresentString": []string{"string"}, "PresentBoolean": []string{"true"}, "PresentInteger": []string{"1"}, "PresentLong": []string{"2"}, "PresentDouble": []string{"1.2"}, "PresentFloat": []string{"2.3"}, "PresentTime": []string{"2001-01-01T01:01:01Z"}, "PresentSlice.1": []string{"one"}, "PresentSlice.2": []string{"two"}, "PresentStruct.Value": []string{"v"}, "PresentStructSlice.1.Value": []string{"p"}, "PresentStructSlice.2.Value": []string{"q"}, "PresentMap.1.Name": []string{"aa"}, "PresentMap.1.Value.Value": []string{"AA"}, "PresentMap.2.Name": []string{"bb"}, "PresentMap.2.Value.Value": []string{"BB"}, } if !reflect.DeepEqual(form, expectedForm) { t.Errorf("Post body was \n%s\n but expected \n%s", form.Encode(), expectedForm.Encode()) } if want := (fakeQueryResponse{IPAddress: "woo"}); want != resp { t.Errorf("Response was %#v, but expected %#v", resp, want) } }