Skip to content

Commit

Permalink
fix(gcs): fix all relevant fields to be pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Nov 29, 2023
1 parent 2fc87bb commit a4e0774
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 124 deletions.
57 changes: 19 additions & 38 deletions fastly/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,32 @@ package fastly
import (
"fmt"
"net/url"
"sort"
"time"
)

// GCS represents an GCS logging response from the Fastly API.
type GCS struct {
AccountName string `mapstructure:"account_name"`
Bucket string `mapstructure:"bucket_name"`
CompressionCodec string `mapstructure:"compression_codec"`
AccountName *string `mapstructure:"account_name"`
Bucket *string `mapstructure:"bucket_name"`
CompressionCodec *string `mapstructure:"compression_codec"`
CreatedAt *time.Time `mapstructure:"created_at"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
Format string `mapstructure:"format"`
FormatVersion int `mapstructure:"format_version"`
GzipLevel int `mapstructure:"gzip_level"`
MessageType string `mapstructure:"message_type"`
Name string `mapstructure:"name"`
Path string `mapstructure:"path"`
Period int `mapstructure:"period"`
Placement string `mapstructure:"placement"`
ProjectID string `mapstructure:"project_id"`
ResponseCondition string `mapstructure:"response_condition"`
SecretKey string `mapstructure:"secret_key"`
ServiceID string `mapstructure:"service_id"`
ServiceVersion int `mapstructure:"version"`
TimestampFormat string `mapstructure:"timestamp_format"`
Format *string `mapstructure:"format"`
FormatVersion *int `mapstructure:"format_version"`
GzipLevel *int `mapstructure:"gzip_level"`
MessageType *string `mapstructure:"message_type"`
Name *string `mapstructure:"name"`
Path *string `mapstructure:"path"`
Period *int `mapstructure:"period"`
Placement *string `mapstructure:"placement"`
ProjectID *string `mapstructure:"project_id"`
ResponseCondition *string `mapstructure:"response_condition"`
SecretKey *string `mapstructure:"secret_key"`
ServiceID *string `mapstructure:"service_id"`
ServiceVersion *int `mapstructure:"version"`
TimestampFormat *string `mapstructure:"timestamp_format"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
User string `mapstructure:"user"`
}

// gcsesByName is a sortable list of gcses.
type gcsesByName []*GCS

// Len implement the sortable interface.
func (s gcsesByName) Len() int {
return len(s)
}

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

// Less implement the sortable interface.
func (s gcsesByName) Less(i, j int) bool {
return s[i].Name < s[j].Name
User *string `mapstructure:"user"`
}

// ListGCSsInput is used as input to the ListGCSs function.
Expand All @@ -72,12 +53,12 @@ func (c *Client) ListGCSs(i *ListGCSsInput) ([]*GCS, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()

var gcses []*GCS
if err := decodeBodyMap(resp.Body, &gcses); err != nil {
return nil, err
}
sort.Stable(gcsesByName(gcses))
return gcses, nil
}

Expand Down
168 changes: 82 additions & 86 deletions fastly/gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,64 +140,62 @@ func TestClient_GCSs(t *testing.T) {
})
}()

if gcsCreateResp1.Name != "test-gcs" {
t.Errorf("bad name: %q", gcsCreateResp1.Name)
if *gcsCreateResp1.Name != "test-gcs" {
t.Errorf("bad name: %q", *gcsCreateResp1.Name)
}
if gcsCreateResp1.ProjectID != "logging-project" {
t.Errorf("bad project id: %q", gcsCreateResp1.ProjectID)
if *gcsCreateResp1.ProjectID != "logging-project" {
t.Errorf("bad project id: %q", *gcsCreateResp1.ProjectID)
}
if gcsCreateResp1.Bucket != "bucket" {
t.Errorf("bad bucket: %q", gcsCreateResp1.Bucket)
if *gcsCreateResp1.Bucket != "bucket" {
t.Errorf("bad bucket: %q", *gcsCreateResp1.Bucket)
}
if gcsCreateResp1.User != "user" {
t.Errorf("bad user: %q", gcsCreateResp1.User)
if *gcsCreateResp1.User != "user" {
t.Errorf("bad user: %q", *gcsCreateResp1.User)
}
if gcsCreateResp1.AccountName != "service-account" {
t.Errorf("bad service account name: %q", gcsCreateResp1.AccountName)
if *gcsCreateResp1.AccountName != "service-account" {
t.Errorf("bad service account name: %q", *gcsCreateResp1.A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dXUv8eLy+6Dcq1SWQtfCWKEor++IIp\n1RwWmFHfYriHGkmxSkkEkLFvL8old9xM5YWbEXc4QIXvnfR4BZxdyJHVzIDdbI2i\nFgcn17U3GwKBgDd1njMY7ENIuWHJt16k7m7wRwfwkH4DxQ89ieNn0+cgE/p3fC6R\nptCYWg7WMXThmhNwDi3lMrvnWTdZ0uL6XyEkHwKtmdfkIV3UZZPglv5uf6JEgSkg\nv3YCOXk3+y5HyWTjUIejtc334kVY1XFPThrFKTeJSSnRsP2l7IgkYBqhAoGAYGsr\nM3z1FrDF2nWw5odIfKJ30UAw2LRyB0eGH0uqhLgyzvwKcK2E98sLqYUi9llN6zOK\n1IEA8xM5hxl97AFxY4sdJEMbbi55wim7uZ5Q51nbvbbNUsmM/Lm6C/JWI8pzpVeU\nIR7EjYp50AE1WOsD6CyFQ0W35pWkn0jWvL4L938CgYEAlax4dLE5+YCG5DeLT1/N\nin6kQjl7JS4oCNlPEj6aRPLX2OJresI7oOn+uNatKvlVyfPm6rdxeHCmER1FpR7Q\nA/aNVjPeViKT/R4nK9ytsa+s/1IJVrwLFHJK3toGE660g5w3vKrCjWisMdP4yzzQ\nbv1KwcKoQbNVXwauH79JKc0=\n-----END PRIVATE KEY-----\n" {
t.Errorf("bad secret_key: %q", gcsCreateResp1.SecretKey)
if *gcsCreateResp1.SecretKey != "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC9aQoqdHVA86oq\nTdRQ5HqwMfpiLBBMKNQcAJsO71RKNrDWwJJZiyYbvM4FOWRZFtRSdPIDgX0C0Wg1\nNnqWYvHDyA5Ug+T8kowiQDn56dU6Km2FWO4wnqZeA8q5G7rQVXlqdibuiP7FglHA\neURUzFsqyymXMUGrqDPqrHsVWC2E3NTJEb4QlywtrwI13qbhlvTx6/9oRfUjytXJ\nRuUIE5xL8yhRCagNr5ZW250aa+wBwu5DSCk5fDNr0eDuZjw84WHDll+mHxBFGV+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l97AFxY4sdJEMbbi55wim7uZ5Q51nbvbbNUsmM/Lm6C/JWI8pzpVeU\nIR7EjYp50AE1WOsD6CyFQ0W35pWkn0jWvL4L938CgYEAlax4dLE5+YCG5DeLT1/N\nin6kQjl7JS4oCNlPEj6aRPLX2OJresI7oOn+uNatKvlVyfPm6rdxeHCmER1FpR7Q\nA/aNVjPeViKT/R4nK9ytsa+s/1IJVrwLFHJK3toGE660g5w3vKrCjWisMdP4yzzQ\nbv1KwcKoQbNVXwauH79JKc0=\n-----END PRIVATE KEY-----\n" {
t.Errorf("bad secret_key: %q", *gcsCreateResp1.SecretKey)
}
if gcsCreateResp1.Path != "/path" {
t.Errorf("bad path: %q", gcsCreateResp1.Path)
if *gcsCreateResp1.Path != "/path" {
t.Errorf("bad path: %q", *gcsCreateResp1.Path)
}
if gcsCreateResp1.Period != 12 {
t.Errorf("bad period: %q", gcsCreateResp1.Period)
if *gcsCreateResp1.Period != 12 {
t.Errorf("bad period: %q", *gcsCreateResp1.Period)
}
if gcsCreateResp1.CompressionCodec != "snappy" {
t.Errorf("bad compression_codec: %q", gcsCreateResp1.CompressionCodec)
if *gcsCreateResp1.CompressionCodec != "snappy" {
t.Errorf("bad compression_codec: %q", *gcsCreateResp1.CompressionCodec)
}
if gcsCreateResp1.GzipLevel != 0 {
t.Errorf("bad gzip_level: %q", gcsCreateResp1.GzipLevel)
if *gcsCreateResp1.GzipLevel != 0 {
t.Errorf("bad gzip_level: %q", *gcsCreateResp1.GzipLevel)
}
if gcsCreateResp1.FormatVersion != 2 {
t.Errorf("bad format_version: %q", gcsCreateResp1.FormatVersion)
if *gcsCreateResp1.FormatVersion != 2 {
t.Errorf("bad format_version: %q", *gcsCreateResp1.FormatVersion)
}
if gcsCreateResp1.Format != "format" {
t.Errorf("bad format: %q", gcsCreateResp1.Format)
if *gcsCreateResp1.Format != "format" {
t.Errorf("bad format: %q", *gcsCreateResp1.Format)
}
if gcsCreateResp1.TimestampFormat != "%Y" {
t.Errorf("bad timestamp_format: %q", gcsCreateResp1.TimestampFormat)
if *gcsCreateResp1.TimestampFormat != "%Y" {
t.Errorf("bad timestamp_format: %q", *gcsCreateResp1.TimestampFormat)
}
if gcsCreateResp1.MessageType != "blank" {
t.Errorf("bad message_type: %q", gcsCreateResp1.MessageType)
if *gcsCreateResp1.MessageType != "blank" {
t.Errorf("bad message_type: %q", *gcsCreateResp1.MessageType)
}
if gcsCreateResp1.Placement != "waf_debug" {
t.Errorf("bad placement: %q", gcsCreateResp1.Placement)
if *gcsCreateResp1.Placement != "waf_debug" {
t.Errorf("bad placement: %q", *gcsCreateResp1.Placement)
}

if gcsCreateResp2.CompressionCodec != "" {
t.Errorf("bad compression_codec: %q", gcsCreateResp1.CompressionCodec)
if gcsCreateResp2.CompressionCodec != nil {
t.Errorf("bad compression_codec: %q", *gcsCreateResp1.CompressionCodec)
}
if gcsCreateResp2.GzipLevel != 8 {
t.Errorf("bad gzip_level: %q", gcsCreateResp1.GzipLevel)
if *gcsCreateResp2.GzipLevel != 8 {
t.Errorf("bad gzip_level: %q", *gcsCreateResp1.GzipLevel)
}

if gcsCreateResp3.CompressionCodec != "snappy" {
t.Errorf("bad compression_codec: %q", gcsCreateResp1.CompressionCodec)
if *gcsCreateResp3.CompressionCodec != "snappy" {
t.Errorf("bad compression_codec: %q", *gcsCreateResp1.CompressionCodec)
}
if gcsCreateResp3.GzipLevel != 0 {
t.Errorf("bad gzip_level: %q", gcsCreateResp1.GzipLevel)
if *gcsCreateResp3.GzipLevel != 0 {
t.Errorf("bad gzip_level: %q", *gcsCreateResp1.GzipLevel)
}

// List
Expand Down Expand Up @@ -227,47 +225,47 @@ func TestClient_GCSs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if gcsCreateResp1.Name != gcsGetResp.Name {
t.Errorf("bad name: %q", gcsCreateResp1.Name)
if *gcsCreateResp1.Name != *gcsGetResp.Name {
t.Errorf("bad name: %q", *gcsCreateResp1.Name)
}
if gcsCreateResp1.ProjectID != "logging-project" {
t.Errorf("bad project id: %q", gcsCreateResp1.ProjectID)
if *gcsCreateResp1.ProjectID != "logging-project" {
t.Errorf("bad project id: %q", *gcsCreateResp1.ProjectID)
}
if gcsCreateResp1.Bucket != gcsGetResp.Bucket {
t.Errorf("bad bucket: %q", gcsCreateResp1.Bucket)
if *gcsCreateResp1.Bucket != *gcsGetResp.Bucket {
t.Errorf("bad bucket: %q", *gcsCreateResp1.Bucket)
}
if gcsCreateResp1.User != gcsGetResp.User {
t.Errorf("bad user: %q", gcsCreateResp1.User)
if *gcsCreateResp1.User != *gcsGetResp.User {
t.Errorf("bad user: %q", *gcsCreateResp1.User)
}
if gcsCreateResp1.SecretKey != gcsGetResp.SecretKey {
t.Errorf("bad secret_key: %q", gcsCreateResp1.SecretKey)
if *gcsCreateResp1.SecretKey != *gcsGetResp.SecretKey {
t.Errorf("bad secret_key: %q", *gcsCreateResp1.SecretKey)
}
if gcsCreateResp1.Path != gcsGetResp.Path {
t.Errorf("bad path: %q", gcsCreateResp1.Path)
if *gcsCreateResp1.Path != *gcsGetResp.Path {
t.Errorf("bad path: %q", *gcsCreateResp1.Path)
}
if gcsCreateResp1.Period != gcsGetResp.Period {
t.Errorf("bad period: %q", gcsCreateResp1.Period)
if *gcsCreateResp1.Period != *gcsGetResp.Period {
t.Errorf("bad period: %q", *gcsCreateResp1.Period)
}
if gcsCreateResp1.CompressionCodec != gcsGetResp.CompressionCodec {
t.Errorf("bad compression_codec: %q", gcsCreateResp1.CompressionCodec)
if *gcsCreateResp1.CompressionCodec != *gcsGetResp.CompressionCodec {
t.Errorf("bad compression_codec: %q", *gcsCreateResp1.CompressionCodec)
}
if gcsCreateResp1.GzipLevel != gcsGetResp.GzipLevel {
t.Errorf("bad gzip_level: %q", gcsCreateResp1.GzipLevel)
if *gcsCreateResp1.GzipLevel != *gcsGetResp.GzipLevel {
t.Errorf("bad gzip_level: %q", *gcsCreateResp1.GzipLevel)
}
if gcsCreateResp1.FormatVersion != gcsGetResp.FormatVersion {
t.Errorf("bad format_version: %q", gcsCreateResp1.FormatVersion)
if *gcsCreateResp1.FormatVersion != *gcsGetResp.FormatVersion {
t.Errorf("bad format_version: %q", *gcsCreateResp1.FormatVersion)
}
if gcsCreateResp1.Format != gcsGetResp.Format {
t.Errorf("bad format: %q", gcsCreateResp1.Format)
if *gcsCreateResp1.Format != *gcsGetResp.Format {
t.Errorf("bad format: %q", *gcsCreateResp1.Format)
}
if gcsCreateResp1.TimestampFormat != gcsGetResp.TimestampFormat {
t.Errorf("bad timestamp_format: %q", gcsCreateResp1.TimestampFormat)
if *gcsCreateResp1.TimestampFormat != *gcsGetResp.TimestampFormat {
t.Errorf("bad timestamp_format: %q", *gcsCreateResp1.TimestampFormat)
}
if gcsCreateResp1.MessageType != gcsGetResp.MessageType {
t.Errorf("bad message_type: %q", gcsCreateResp1.MessageType)
if *gcsCreateResp1.MessageType != *gcsGetResp.MessageType {
t.Errorf("bad message_type: %q", *gcsCreateResp1.MessageType)
}
if gcsCreateResp1.Placement != gcsGetResp.Placement {
t.Errorf("bad placement: %q", gcsCreateResp1.Placement)
if *gcsCreateResp1.Placement != *gcsGetResp.Placement {
t.Errorf("bad placement: %q", *gcsCreateResp1.Placement)
}

// Update
Expand Down Expand Up @@ -310,31 +308,29 @@ func TestClient_GCSs(t *testing.T) {
t.Fatal(err)
}

if gcsUpdateResp1.Name != "new-test-gcs" {
t.Errorf("bad name: %q", gcsUpdateResp1.Name)
if *gcsUpdateResp1.Name != "new-test-gcs" {
t.Errorf("bad name: %q", *gcsUpdateResp1.Name)
}
if gcsUpdateResp1.MessageType != "classic" {
t.Errorf("bad message_type: %q", gcsUpdateResp1.MessageType)
if *gcsUpdateResp1.MessageType != "classic" {
t.Errorf("bad message_type: %q", *gcsUpdateResp1.MessageType)
}
if gcsUpdateResp1.CompressionCodec != "" {
t.Errorf("bad compression_codec: %q", gcsUpdateResp1.CompressionCodec)
if gcsUpdateResp1.CompressionCodec != nil {
t.Errorf("bad compression_codec: %q", *gcsUpdateResp1.CompressionCodec)
}
if gcsUpdateResp1.GzipLevel != 9 {
t.Errorf("bad gzip_level: %q", gcsUpdateResp1.GzipLevel)
if *gcsUpdateResp1.GzipLevel != 9 {
t.Errorf("bad gzip_level: %q", *gcsUpdateResp1.GzipLevel)
}

if gcsUpdateResp2.CompressionCodec != "zstd" {
t.Errorf("bad compression_codec: %q", gcsUpdateResp2.CompressionCodec)
if *gcsUpdateResp2.CompressionCodec != "zstd" {
t.Errorf("bad compression_codec: %q", *gcsUpdateResp2.CompressionCodec)
}
if gcsUpdateResp2.GzipLevel != 0 {
t.Errorf("bad gzip_level: %q", gcsUpdateResp2.GzipLevel)
if *gcsUpdateResp2.GzipLevel != 0 {
t.Errorf("bad gzip_level: %q", *gcsUpdateResp2.GzipLevel)
}

if gcsUpdateResp3.CompressionCodec != "" {
t.Errorf("bad compression_codec: %q", gcsUpdateResp3.CompressionCodec)
if gcsUpdateResp3.CompressionCodec != nil {
t.Errorf("bad compression_codec: %q", *gcsUpdateResp3.CompressionCodec)
}
if gcsUpdateResp3.GzipLevel != 9 {
t.Errorf("bad gzip_level: %q", gcsUpdateResp3.GzipLevel)
if *gcsUpdateResp3.GzipLevel != 9 {
t.Errorf("bad gzip_level: %q", *gcsUpdateResp3.GzipLevel)
}

// Delete
Expand Down

0 comments on commit a4e0774

Please sign in to comment.