Add conversion test and fix some stuff

apigen
Jeff Mitchell 6 years ago
parent f70ff526da
commit 24d82ebe4e

@ -6,7 +6,6 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"net/url"
@ -528,7 +527,7 @@ func (c *Client) Clone() (*Client, error) {
func copyHeaders(in http.Header) http.Header {
ret := make(http.Header)
for k, v := range in.headers {
for k, v := range in {
for _, val := range v {
ret[k] = append(ret[k], val)
}
@ -685,10 +684,12 @@ func (c *Client) Do(r *http.Request) (*http.Response, error) {
}
var result *http.Response
resp, err := client.Do(req)
if resp != nil {
result = &Response{Response: resp}
}
result, err = client.Do(req)
/*
if resp != nil {
result = &Response{Response: resp}
}
*/
if err != nil {
if strings.Contains(err.Error(), "tls: oversized") {
err = errwrap.Wrapf(

@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2020-05-03 11:13:42.5271736 -0400 EDT m=+0.049578501
// 2020-05-03 13:43:08.126021 -0400 EDT m=+0.032030001
package hosts
import (
@ -22,9 +22,9 @@ type AwsEc2HostCatalog struct {
Rotate *bool `json:"rotate,omitempty"`
}
func (s *HostCatalog) AsAwsEc2HostCatalog() (*AwsEc2HostCatalog, error) {
func (s HostCatalog) AsAwsEc2HostCatalog() (*AwsEc2HostCatalog, error) {
out := &AwsEc2HostCatalog{
HostCatalog: s,
HostCatalog: &s,
}
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: out,

@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2020-05-03 11:13:42.5265109 -0400 EDT m=+0.048915801
// 2020-05-03 13:43:08.1253741 -0400 EDT m=+0.031383201
package hosts
import (

@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2020-05-03 11:13:42.5269139 -0400 EDT m=+0.049318801
// 2020-05-03 13:43:08.1257653 -0400 EDT m=+0.031774501
package hosts
import (

@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2020-05-03 11:13:42.5267614 -0400 EDT m=+0.049166301
// 2020-05-03 13:43:08.1256396 -0400 EDT m=+0.031648601
package hosts
import (

@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2020-05-03 11:13:42.5270389 -0400 EDT m=+0.049443801
// 2020-05-03 13:43:08.1258801 -0400 EDT m=+0.031889201
package hosts
import (
@ -13,9 +13,9 @@ type StaticHostCatalog struct {
*HostCatalog
}
func (s *HostCatalog) AsStaticHostCatalog() (*StaticHostCatalog, error) {
func (s HostCatalog) AsStaticHostCatalog() (*StaticHostCatalog, error) {
out := &StaticHostCatalog{
HostCatalog: s,
HostCatalog: &s,
}
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: out,

@ -445,9 +445,9 @@ type {{ .DetailName }} struct {
{{ .StructFields }}
}
func (s *{{ .ParentName }}) As{{ .DetailName }}() (*{{ .DetailName }}, error) {
func (s {{ .ParentName }}) As{{ .DetailName }}() (*{{ .DetailName }}, error) {
out := &{{ .DetailName }}{
{{ .ParentName }}: s,
{{ .ParentName }}: &s,
}
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: out,

@ -0,0 +1,34 @@
package tests
import (
"testing"
"time"
"github.com/hashicorp/watchtower/api"
"github.com/hashicorp/watchtower/api/hosts"
"github.com/stretchr/testify/assert"
)
func TestDetailTemplating(t *testing.T) {
lt := time.Now()
c := hosts.HostCatalog{
Path: api.String("path"),
CreatedTime: lt,
Attributes: map[string]interface{}{
"regions": []string{"a", "b"},
"access_key": "access",
"secret_key": "secret",
"rotate": true,
},
}
ac, err := c.AsAwsEc2HostCatalog()
assert.NoError(t, err)
assert.Equal(t, &hosts.AwsEc2HostCatalog{
HostCatalog: &c,
Regions: []string{"a", "b"},
AccessKey: api.String("access"),
SecretKey: api.String("secret"),
Rotate: api.Bool(true),
}, ac)
}

@ -1,5 +1,11 @@
package api
func Bool(in bool) *bool {
ret := new(bool)
*ret = in
return ret
}
func String(in string) *string {
ret := new(string)
*ret = in

@ -44,6 +44,7 @@ require (
github.com/ryanuber/columnize v2.1.0+incompatible
github.com/ryanuber/go-glob v1.0.0
github.com/spf13/viper v1.6.3 // indirect
github.com/stretchr/testify v1.5.1
go.mongodb.org/mongo-driver v1.3.2 // indirect
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f // indirect

Loading…
Cancel
Save