Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetLoadbalancer return metadata status #254

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func TestGetLoadBalancer(t *testing.T) {
"id": "loadori-origin",
"name": "origin",
"target": "1.2.3.4",
"portNumber": 80
"portNumber": 80,
"weight": 100
}
}
]
Expand Down Expand Up @@ -94,6 +95,7 @@ func TestGetLoadBalancer(t *testing.T) {
assert.Equal(t, "origin", lb.Ports.Edges[0].Node.Pools[0].Origins.Edges[0].Node.Name)
assert.Equal(t, "1.2.3.4", lb.Ports.Edges[0].Node.Pools[0].Origins.Edges[0].Node.Target)
assert.Equal(t, int64(80), lb.Ports.Edges[0].Node.Pools[0].Origins.Edges[0].Node.PortNumber)
assert.Equal(t, int64(100), lb.Ports.Edges[0].Node.Pools[0].Origins.Edges[0].Node.Weight)

require.Len(t, lb.IPAddresses, 2)
assert.Equal(t, "ipamipa-randovalue", lb.IPAddresses[0].ID)
Expand All @@ -105,6 +107,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
105 changes: 75 additions & 30 deletions pkg/client/types.go
Original file line number Diff line number Diff line change
@@ -1,69 +1,72 @@
package client

import "encoding/json"

// OriginNode is a struct that represents the OriginNode GraphQL type
type OriginNode struct {
ID string
Name string
Target string
PortNumber int64
Weight int64
Active bool
ID string `graphql:"id" json:"id"`
Name string `graphql:"name" json:"name"`
Target string `graphql:"target" json:"target"`
PortNumber int64 `graphql:"portNumber" json:"portNumber"`
Weight int64 `graphql:"weight" json:"weight"`
Active bool `graphql:"active" json:"active"`
}

// OriginEdges is a struct that represents the OriginEdges GraphQL type
type OriginEdges struct {
Node OriginNode
Node OriginNode `graphql:"node" json:"node"`
}

// Origins is a struct that represents the Origins GraphQL type
type Origins struct {
Edges []OriginEdges
Edges []OriginEdges `graphql:"edges" json:"edges"`
}

// Pool is a struct that represents the Pool GraphQL type
type Pool struct {
ID string
Name string
Protocol string
Origins Origins
ID string `graphql:"id"`
Name string `graphql:"name" json:"name"`
Protocol string `graphql:"protocol" json:"protocol"`
Origins Origins `graphql:"origins" json:"origins"`
}

// PortNode is a struct that represents the PortNode GraphQL type
type PortNode struct {
ID string
Name string
Number int64
Pools []Pool
ID string `graphql:"id" json:"id"`
Name string `graphql:"name" json:"name"`
Number int64 `graphql:"number" json:"number"`
Pools []Pool `graphql:"pools" json:"pools"`
}

// PortEdges is a struct that represents the PortEdges GraphQL type
type PortEdges struct {
Node PortNode
Node PortNode `graphql:"node" json:"node"`
}

// Ports is a struct that represents the Ports GraphQL type
type Ports struct {
Edges []PortEdges
Edges []PortEdges `graphql:"edges" json:"edges"`
}

// OwnerNode is a struct that represents the OwnerNode GraphQL type
type OwnerNode struct {
ID string
ID string `graphql:"id" json:"id"`
}

// LocationNode is a struct that represents the LocationNode GraphQL type
type LocationNode struct {
ID string
ID string `graphql:"id" json:"id"`
}

// LoadBalancer is a struct that represents the LoadBalancer GraphQL type
type LoadBalancer struct {
ID string
Name string
Owner OwnerNode
Location LocationNode
IPAddresses []IPAddress `graphql:"IPAddresses" json:"IPAddresses"`
Ports Ports
ID string `graphql:"id" json:"id"`
Name string `graphql:"name" json:"name"`
Owner OwnerNode `graphql:"owner" json:"owner"`
Location LocationNode `graphql:"location" json:"location"`
IPAddresses []IPAddress `graphql:"IPAddresses" json:"IPAddresses"`
Metadata Metadata `graphql:"metadata" json:"metadata"`
Ports Ports `graphql:"ports" json:"ports"`
}

// GetLoadBalancer is a struct that represents the GetLoadBalancer GraphQL query
Expand All @@ -73,9 +76,34 @@ type GetLoadBalancer struct {

// IPAddress is a struct that represents the IPAddress GraphQL type
type IPAddress struct {
ID string
IP string
Reserved bool
ID string `graphql:"id" json:"id"`
IP string `graphql:"ip" json:"ip"`
Reserved bool `graphql:"reserved" json:"reserved"`
}

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

// MetadataStatusEdges is a struct that represents the Metadata status edges GraphQL type
type MetadataStatusEdges struct {
Node MetadataStatusNode `graphql:"node" json:"node"`
}

// MetadataStatuses is a struct that represents the Metadata statuses GraphQL type
type MetadataStatuses struct {
Edges []MetadataStatusEdges `graphql:"edges" json:"edges"`
}

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

// Readable version of the above:
Expand All @@ -84,7 +112,24 @@ type IPAddress struct {
// ID string
// Owner string
// Name string
// IPAddressableFragment
// IPAddresses {
// id string
// ip string
// }
// 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
Loading