Skip to content

Commit

Permalink
fix(logging/honeycomb): fix all relevant fields to be pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Dec 4, 2023
1 parent 0fde81b commit c07c2c4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 56 deletions.
35 changes: 9 additions & 26 deletions fastly/honeycomb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,28 @@ package fastly
import (
"fmt"
"net/url"
"sort"
"time"
)

// Honeycomb represents a honeycomb response from the Fastly API.
type Honeycomb struct {
CreatedAt *time.Time `mapstructure:"created_at"`
Dataset string `mapstructure:"dataset"`
Dataset *string `mapstructure:"dataset"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
Format string `mapstructure:"format"`
FormatVersion int `mapstructure:"format_version"`
Name string `mapstructure:"name"`
Placement string `mapstructure:"placement"`
ResponseCondition string `mapstructure:"response_condition"`
ServiceID string `mapstructure:"service_id"`
ServiceVersion int `mapstructure:"version"`
Token string `mapstructure:"token"`
Format *string `mapstructure:"format"`
FormatVersion *int `mapstructure:"format_version"`
Name *string `mapstructure:"name"`
Placement *string `mapstructure:"placement"`
ResponseCondition *string `mapstructure:"response_condition"`
ServiceID *string `mapstructure:"service_id"`
ServiceVersion *int `mapstructure:"version"`
Token *string `mapstructure:"token"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
}

// honeycombsByName is a sortable list of honeycombs.
type honeycombsByName []*Honeycomb

Check failure on line 26 in fastly/honeycomb.go

View workflow job for this annotation

GitHub Actions / lint

type honeycombsByName is unused (U1000)

// Len implement the sortable interface.
func (h honeycombsByName) Len() int {
return len(h)
}

// Swap implement the sortable interface.
func (h honeycombsByName) Swap(i, j int) {
h[i], h[j] = h[j], h[i]
}

// Less implement the sortable interface.
func (h honeycombsByName) Less(i, j int) bool {
return h[i].Name < h[j].Name
}

// ListHoneycombsInput is used as input to the ListHoneycombs function.
type ListHoneycombsInput struct {
// ServiceID is the ID of the service (required).
Expand Down Expand Up @@ -69,7 +53,6 @@ func (c *Client) ListHoneycombs(i *ListHoneycombsInput) ([]*Honeycomb, error) {
if err := decodeBodyMap(resp.Body, &hs); err != nil {
return nil, err
}
sort.Stable(honeycombsByName(hs))
return hs, nil
}

Expand Down
60 changes: 30 additions & 30 deletions fastly/honeycomb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ func TestClient_Honeycombs(t *testing.T) {
})
}()

if h.Name != "test-honeycomb" {
t.Errorf("bad name: %q", h.Name)
if *h.Name != "test-honeycomb" {
t.Errorf("bad name: %q", *h.Name)
}
if h.Format != "%h %l %u %t \"%r\" %>s %b" {
t.Errorf("bad format: %q", h.Format)
if *h.Format != "%h %l %u %t \"%r\" %>s %b" {
t.Errorf("bad format: %q", *h.Format)
}
if h.FormatVersion != 2 {
t.Errorf("bad format_version: %q", h.FormatVersion)
if *h.FormatVersion != 2 {
t.Errorf("bad format_version: %q", *h.FormatVersion)
}
if h.Placement != "waf_debug" {
t.Errorf("bad placement: %q", h.Placement)
if *h.Placement != "waf_debug" {
t.Errorf("bad placement: %q", *h.Placement)
}
if h.Token != "super-secure-token" {
t.Errorf("bad token: %q", h.Token)
if *h.Token != "super-secure-token" {
t.Errorf("bad token: %q", *h.Token)
}
if h.Dataset != "testDataset" {
t.Errorf("bad dataset: %q", h.Dataset)
if *h.Dataset != "testDataset" {
t.Errorf("bad dataset: %q", *h.Dataset)
}

// List
Expand Down Expand Up @@ -94,23 +94,23 @@ func TestClient_Honeycombs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if h.Name != nh.Name {
t.Errorf("bad name: %q", h.Name)
if *h.Name != *nh.Name {
t.Errorf("bad name: %q", *h.Name)
}
if h.Format != nh.Format {
t.Errorf("bad format: %q", h.Format)
if *h.Format != *nh.Format {
t.Errorf("bad format: %q", *h.Format)
}
if h.FormatVersion != nh.FormatVersion {
t.Errorf("bad format_version: %q", h.FormatVersion)
if *h.FormatVersion != *nh.FormatVersion {
t.Errorf("bad format_version: %q", *h.FormatVersion)
}
if h.Placement != nh.Placement {
t.Errorf("bad placement: %q", h.Placement)
if *h.Placement != *nh.Placement {
t.Errorf("bad placement: %q", *h.Placement)
}
if h.Token != nh.Token {
t.Errorf("bad token: %q", h.Token)
if *h.Token != *nh.Token {
t.Errorf("bad token: %q", *h.Token)
}
if h.Dataset != nh.Dataset {
t.Errorf("bad dataset: %q", h.Dataset)
if *h.Dataset != *nh.Dataset {
t.Errorf("bad dataset: %q", *h.Dataset)
}

// Update
Expand All @@ -128,14 +128,14 @@ func TestClient_Honeycombs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if us.Name != "new-test-honeycomb" {
t.Errorf("bad name: %q", us.Name)
if *us.Name != "new-test-honeycomb" {
t.Errorf("bad name: %q", *us.Name)
}
if us.Token != "new-token" {
t.Errorf("bad token: %q", us.Token)
if *us.Token != "new-token" {
t.Errorf("bad token: %q", *us.Token)
}
if us.Dataset != "newDataset" {
t.Errorf("bad dataset: %q", us.Dataset)
if *us.Dataset != "newDataset" {
t.Errorf("bad dataset: %q", *us.Dataset)
}

// Delete
Expand Down

0 comments on commit c07c2c4

Please sign in to comment.