Skip to content

Commit

Permalink
client return node metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>
  • Loading branch information
rizzza committed Oct 18, 2023
1 parent b398e2c commit fceeb43
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
52 changes: 52 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,58 @@ func TestGetLoadBalancer(t *testing.T) {
assert.True(t, lb.IPAddresses[1].Reserved)
})

t.Run("successful query with metadata status", func(t *testing.T) {
respJSON := `{
"data": {
"loadBalancer": {
"id": "loadbal-testing",
"name": "some lb",
"location": {
"id": "lctnloc-testing"
},
"metadata": {
"id": "metadat-testing",
"nodeID": "loadbal-testing",
"statuses": {
"edges": [
{
"node": {
"source": "lctnloc-testing",
"statusNamespaceID": "metasns-testing",
"id": "metasts-testing",
"data": {
"status": "creating"
}
}
}
]
}
}
}
}
}`

cli.gqlCli = mustNewGQLTestClient(respJSON, http.StatusOK)
lb, err := cli.GetLoadBalancer(context.Background(), "loadbal-randovalue")
require.NoError(t, err)
require.NotNil(t, lb)

assert.Equal(t, "loadbal-testing", lb.ID)
assert.Equal(t, "some lb", lb.Name)
assert.Equal(t, "lctnloc-testing", lb.Location.ID)

assert.Equal(t, "metadat-testing", lb.Metadata.ID)
assert.Equal(t, "loadbal-testing", lb.Metadata.NodeID)
assert.Len(t, lb.IPAddresses, 0)
assert.Len(t, lb.Ports.Edges, 0)

require.Len(t, lb.Metadata.Statuses.Edges, 1)
assert.Equal(t, "lctnloc-testing", lb.Metadata.Statuses.Edges[0].Node.Source)
assert.Equal(t, "metasts-testing", lb.Metadata.Statuses.Edges[0].Node.ID)
assert.Equal(t, "metasns-testing", lb.Metadata.Statuses.Edges[0].Node.StatusNamespaceID)
assert.JSONEq(t, `{"status": "creating"}`, string(lb.Metadata.Statuses.Edges[0].Node.Data))
})

t.Run("unauthorized", func(t *testing.T) {
respJSON := `{"message":"invalid or expired jwt"}`

Expand Down
47 changes: 46 additions & 1 deletion pkg/client/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package client

import "encoding/json"

// OriginNode is a struct that represents the OriginNode GraphQL type
type OriginNode struct {
ID string
Expand Down Expand Up @@ -63,6 +65,7 @@ type LoadBalancer struct {
Owner OwnerNode
Location LocationNode
IPAddresses []IPAddress `graphql:"IPAddresses" json:"IPAddresses"`
Metadata Metadata `graphql:"metadata" json:"metadata"`
Ports Ports
}

Expand All @@ -78,13 +81,55 @@ type IPAddress struct {
Reserved bool
}

// MetadataStatusNode is a struct that represents the Metadata status node GraphQL type
type MetadataStatusNode struct {
ID string `graphql:"id"`
Data json.RawMessage `graphql:"data"`
Source string `graphql:"source"`
StatusNamespaceID string `graphql:"statusNamespaceID"`
}

// MetadataStatusEdges is a struct that represents the Metadata status edges GraphQL type
type MetadataStatusEdges struct {
Node MetadataStatusNode
}

// MetadataStatuses is a struct that represents the Metadata statuses GraphQL type
type MetadataStatuses struct {
Edges []MetadataStatusEdges
}

// Metadata is a struct that represents the metadata GraphQL type
type Metadata struct {
ID string `graphql:"id"`
NodeID string `graphql:"nodeID"`
Statuses MetadataStatuses `graphql:"statuses" json:"statuses"`
}

// Readable version of the above:
// type GetLoadBalancer struct {
// LoadBalancer struct {
// ID string
// Owner string
// Name string
// IPAddressableFragment
// IPAddresses {
// id string
// ip
// }
// metadata struct {
// id string
// nodeID string
// statuses struct {
// edges []struct {
// node struct {
// source string
// statusNamespaceID string
// id string
// data json bytes
// }
// }
// }
// }
// Ports struct {
// Edges []struct {
// Node struct {
Expand Down

0 comments on commit fceeb43

Please sign in to comment.