diff --git a/pkg/metadata/errors.go b/pkg/metadata/errors.go deleted file mode 100644 index d903c1154..000000000 --- a/pkg/metadata/errors.go +++ /dev/null @@ -1,11 +0,0 @@ -package metadata - -import "errors" - -var ( - // ErrStatusNotFound is returned when a status is not found in the payload - ErrStatusNotFound = errors.New("status not found") - - // ErrInvalidStatusData is returned when the status json data is invalid - ErrInvalidStatusData = errors.New("invalid status json data") -) diff --git a/pkg/metadata/metadata.go b/pkg/metadata/metadata.go index e79bbd2e8..587e223b5 100644 --- a/pkg/metadata/metadata.go +++ b/pkg/metadata/metadata.go @@ -1,14 +1,5 @@ package metadata -import ( - "encoding/json" - "fmt" - - "go.infratographer.com/x/gidx" - - "go.infratographer.com/load-balancer-api/pkg/client" -) - // LoadBalancerState state of a load balancer type LoadBalancerState string @@ -19,28 +10,7 @@ const ( LoadBalancerStateActive LoadBalancerState = "active" LoadBalancerStateDeleted LoadBalancerState = "deleted" LoadBalancerStateUpdating LoadBalancerState = "updating" -) -// LoadBalancerStatus is the status of a load balancer -type LoadBalancerStatus struct { - State LoadBalancerState `json:"state"` -} - -// GetLoadbalancerStatus returns the status of a load balancer -func GetLoadbalancerStatus(metadataStatuses client.MetadataStatuses, statusNamespaceID gidx.PrefixedID) (*LoadBalancerStatus, error) { - if metadataStatuses.TotalCount > 0 { - for _, s := range metadataStatuses.Edges { - if s.Node.StatusNamespaceID == statusNamespaceID.String() { - status := &LoadBalancerStatus{} - - if err := json.Unmarshal(s.Node.Data, status); err != nil { - return nil, fmt.Errorf("%w: %s", ErrInvalidStatusData, err) - } - - return status, nil - } - } - } - - return nil, ErrStatusNotFound -} + LoadBalancerStateIPAssigned LoadBalancerState = "ip-address.assigned" + LoadBalancerStateIPUnassigned LoadBalancerState = "ip-address.unassigned" +) diff --git a/pkg/metadata/metadata_test.go b/pkg/metadata/metadata_test.go deleted file mode 100644 index fe8dd9014..000000000 --- a/pkg/metadata/metadata_test.go +++ /dev/null @@ -1,87 +0,0 @@ -package metadata - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "go.infratographer.com/load-balancer-api/pkg/client" -) - -func TestGetLoadbalancerStatus(t *testing.T) { - t.Run("valid status", func(t *testing.T) { - statuses := client.MetadataStatuses{ - TotalCount: 2, - Edges: []client.MetadataStatusEdges{ - { - Node: client.MetadataStatusNode{ - StatusNamespaceID: "metasns-loadbalancer-status", - Data: json.RawMessage(`{"state": "active"}`), - }, - }, - { - Node: client.MetadataStatusNode{ - StatusNamespaceID: "metasns-some-other-namespace", - Data: json.RawMessage(`{"key": "value"}`), - }, - }, - }, - } - - status, err := GetLoadbalancerStatus(statuses, "metasns-loadbalancer-status") - require.Nil(t, err) - assert.Equal(t, LoadBalancerStateActive, status.State) - }) - - t.Run("bad json data", func(t *testing.T) { - statuses := client.MetadataStatuses{ - TotalCount: 1, - Edges: []client.MetadataStatusEdges{ - { - Node: client.MetadataStatusNode{ - StatusNamespaceID: "metasns-loadbalancer-status", - Data: json.RawMessage(`{"state"}`), - }, - }, - }, - } - - status, err := GetLoadbalancerStatus(statuses, "metasns-loadbalancer-status") - require.NotNil(t, err) - require.Nil(t, status) - assert.ErrorIs(t, err, ErrInvalidStatusData) - }) - - t.Run("status not found", func(t *testing.T) { - statuses := client.MetadataStatuses{ - TotalCount: 0, - Edges: []client.MetadataStatusEdges{}, - } - - status, err := GetLoadbalancerStatus(statuses, "metasns-loadbalancer-status") - require.NotNil(t, err) - require.Nil(t, status) - assert.ErrorIs(t, err, ErrStatusNotFound) - }) - - t.Run("no status data", func(t *testing.T) { - statuses := client.MetadataStatuses{ - TotalCount: 1, - Edges: []client.MetadataStatusEdges{ - { - Node: client.MetadataStatusNode{ - StatusNamespaceID: "metasns-loadbalancer-status", - Data: json.RawMessage(``), - }, - }, - }, - } - - status, err := GetLoadbalancerStatus(statuses, "metasns-loadbalancer-status") - assert.NotNil(t, err) - assert.Nil(t, status) - assert.ErrorIs(t, err, ErrInvalidStatusData) - }) -}