feat(http): self sources now return links to /api/v2
parent
448058dbd6
commit
ea5d9112b2
|
@ -32,6 +32,19 @@ type sourceResponse struct {
|
|||
func newSourceResponse(s *platform.Source) *sourceResponse {
|
||||
s.Password = ""
|
||||
s.SharedSecret = ""
|
||||
|
||||
if s.Type == platform.SelfSourceType {
|
||||
return &sourceResponse{
|
||||
Source: s,
|
||||
Links: map[string]interface{}{
|
||||
"self": fmt.Sprintf("%s/%s", sourceHTTPPath, s.ID.String()),
|
||||
"query": "/api/v2/query",
|
||||
"buckets": "/api/v2/buckets",
|
||||
"health": "/api/v2/health",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return &sourceResponse{
|
||||
Source: s,
|
||||
Links: map[string]interface{}{
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/platform"
|
||||
)
|
||||
|
||||
func Test_newSourceResponse(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
s *platform.Source
|
||||
want *sourceResponse
|
||||
}{
|
||||
{
|
||||
name: "self source returns links to this instance",
|
||||
s: &platform.Source {
|
||||
ID: platform.ID(1),
|
||||
OrganizationID: platform.ID(1),
|
||||
Name: "Hi",
|
||||
Type: platform.SelfSourceType,
|
||||
URL: "/",
|
||||
},
|
||||
want: &sourceResponse{
|
||||
Source: &platform.Source {
|
||||
ID: platform.ID(1),
|
||||
OrganizationID: platform.ID(1),
|
||||
Name: "Hi",
|
||||
Type: platform.SelfSourceType,
|
||||
URL: "/",
|
||||
},
|
||||
Links: map[string]interface{}{
|
||||
"self": "/api/v2/sources/0000000000000001",
|
||||
"query": "/api/v2/query",
|
||||
"buckets": "/api/v2/buckets",
|
||||
"health": "/api/v2/health",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "v1 sources have proxied links",
|
||||
s: &platform.Source {
|
||||
ID: platform.ID(1),
|
||||
OrganizationID: platform.ID(1),
|
||||
Name: "Hi",
|
||||
Type: platform.V1SourceType,
|
||||
URL: "/",
|
||||
},
|
||||
want: &sourceResponse{
|
||||
Source: &platform.Source {
|
||||
ID: platform.ID(1),
|
||||
OrganizationID: platform.ID(1),
|
||||
Name: "Hi",
|
||||
Type: platform.V1SourceType,
|
||||
URL: "/",
|
||||
},
|
||||
Links: map[string]interface{}{
|
||||
"self": "/api/v2/sources/0000000000000001",
|
||||
"query": "/api/v2/sources/0000000000000001/query",
|
||||
"buckets": "/api/v2/sources/0000000000000001/buckets",
|
||||
"health": "/api/v2/sources/0000000000000001/health",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := newSourceResponse(tt.s); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("newSourceResponse() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue