Skip to content

Commit

Permalink
integrate new function into abstraction and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Sep 3, 2021
1 parent 59cc264 commit e0df51e
Show file tree
Hide file tree
Showing 70 changed files with 78 additions and 75 deletions.
4 changes: 4 additions & 0 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ type ServiceDetailsOpts struct {

// ServiceDetails returns the Service ID and Service Version.
func ServiceDetails(opts ServiceDetailsOpts) (serviceID string, serviceVersion *fastly.Version, err error) {
if opts.VerboseMode {
DisplayServiceID(opts.Manifest, opts.Out)
}

serviceID, source := opts.Manifest.ServiceID()
if source == manifest.SourceUndefined {
return serviceID, serviceVersion, errors.ErrNoServiceID
Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ func (ac *OptionalAutoClone) Parse(v *fastly.Version, sid string, verbose bool,
}
if verbose {
msg := fmt.Sprintf("Service version %d is not editable, so it was automatically cloned because --autoclone is enabled. Now operating on version %d.", v.Number, version.Number)
text.Break(out)
text.Output(out, msg)
text.Break(out)
}
return version, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func TestACLList(t *testing.T) {
ListACLsFn: listACLs,
},
Args: args("acl list --service-id 123 --verbose --version 1"),
WantOutput: "Fastly API token not provided\nFastly API endpoint: https://api.fastly.com\n\nService ID: 123\nService Version: 1\n\nName: foo\nID: 456\n\nCreated at: 2021-06-15 23:00:00 +0000 UTC\nUpdated at: 2021-06-15 23:00:00 +0000 UTC\nDeleted at: 2021-06-15 23:00:00 +0000 UTC\n\nName: bar\nID: 789\n\nCreated at: 2021-06-15 23:00:00 +0000 UTC\nUpdated at: 2021-06-15 23:00:00 +0000 UTC\nDeleted at: 2021-06-15 23:00:00 +0000 UTC\n",
WantOutput: "Fastly API token not provided\nFastly API endpoint: https://api.fastly.com\nService ID (via --service-id): 123\n\nService Version: 1\n\nName: foo\nID: 456\n\nCreated at: 2021-06-15 23:00:00 +0000 UTC\nUpdated at: 2021-06-15 23:00:00 +0000 UTC\nDeleted at: 2021-06-15 23:00:00 +0000 UTC\n\nName: bar\nID: 789\n\nCreated at: 2021-06-15 23:00:00 +0000 UTC\nUpdated at: 2021-06-15 23:00:00 +0000 UTC\nDeleted at: 2021-06-15 23:00:00 +0000 UTC\n",
},
}

Expand Down
12 changes: 7 additions & 5 deletions pkg/commands/acl/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
}

if c.Globals.Verbose() {
c.printVerbose(out, serviceID, serviceVersion.Number, as)
c.printVerbose(out, serviceVersion.Number, as)
} else {
c.printSummary(out, as)
}
Expand All @@ -88,13 +88,13 @@ func (c *ListCommand) constructInput(serviceID string, serviceVersion int) *fast

// printVerbose displays the information returned from the API in a verbose
// format.
func (c *ListCommand) printVerbose(out io.Writer, serviceID string, serviceVersion int, as []*fastly.ACL) {
fmt.Fprintf(out, "\nService ID: %s\n", serviceID)
fmt.Fprintf(out, "Service Version: %d\n", serviceVersion)
func (c *ListCommand) printVerbose(out io.Writer, serviceVersion int, as []*fastly.ACL) {
fmt.Fprintf(out, "Service Version: %d\n\n", serviceVersion)

for _, a := range as {
fmt.Fprintf(out, "\nName: %s\n", a.Name)
fmt.Fprintf(out, "Name: %s\n", a.Name)
fmt.Fprintf(out, "ID: %s\n\n", a.ID)

if a.CreatedAt != nil {
fmt.Fprintf(out, "Created at: %s\n", a.CreatedAt)
}
Expand All @@ -104,6 +104,8 @@ func (c *ListCommand) printVerbose(out io.Writer, serviceID string, serviceVersi
if a.DeletedAt != nil {
fmt.Fprintf(out, "Deleted at: %s\n", a.DeletedAt)
}

fmt.Fprintf(out, "\n")
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/commands/aclentry/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (c *ListCommand) printVerbose(out io.Writer, as []*fastly.ACLEntry) {
if a.DeletedAt != nil {
fmt.Fprintf(out, "Deleted at: %s\n", a.DeletedAt)
}

fmt.Fprintf(out, "\n")
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ SERVICE VERSION NAME ADDRESS PORT COMMENT
var listBackendsVerboseOutput = strings.Join([]string{
"Fastly API token not provided",
"Fastly API endpoint: https://api.fastly.com",
"Service ID: 123",
"Service ID (via --service-id): 123",
"",
"Version: 1",
" Backend 1/2",
" Name: test.com",
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/backend/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, backend := range backends {
fmt.Fprintf(out, "\tBackend %d/%d\n", i+1, len(backends))
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/domain/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ SERVICE VERSION NAME COMMENT
var listDomainsVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
Domain 1/2
Name: www.test.com
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/domain/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, domain := range domains {
fmt.Fprintf(out, "\tDomain %d/%d\n", i+1, len(domains))
Expand Down
4 changes: 3 additions & 1 deletion pkg/commands/edgedictionary/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func (c *DescribeCommand) Exec(in io.Reader, out io.Writer) error {
return err
}

text.Output(out, "Service ID: %s", dictionary.ServiceID)
if !c.Globals.Verbose() {
text.Output(out, "Service ID: %s", dictionary.ServiceID)
}
text.Output(out, "Version: %d", dictionary.ServiceVersion)
text.PrintDictionary(out, "", dictionary)

Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/edgedictionary/edgedictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,18 +448,17 @@ var updateDictionaryOutputVerbose = strings.Join(
[]string{
"Fastly API token not provided",
"Fastly API endpoint: https://api.fastly.com",
"Service ID (via --service-id): 123",
"",
"Service version 1 is not editable, so it was automatically cloned because --autoclone is",
"enabled. Now operating on version 4.",
"",
"",
strings.TrimSpace(updateDictionaryNameOutput),
updateDictionaryOutputVersionCloned,
},
"\n")

var updateDictionaryOutputVersionCloned = strings.TrimSpace(`
Service ID: 123
Version: 4
ID: 456
Name: dict-1
Expand Down Expand Up @@ -492,7 +491,8 @@ Deleted (UTC): 2001-02-03 04:05
var describeDictionaryOutputVerbose = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
ID: 456
Name: dict-1
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/edgedictionary/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ func (c *UpdateCommand) Exec(in io.Reader, out io.Writer) error {
text.Success(out, "Updated dictionary %s (service %s version %d)", d.Name, d.ServiceID, d.ServiceVersion)

if c.Globals.Verbose() {
text.Output(out, "Service ID: %s", d.ServiceID)
text.Output(out, "Version: %d", d.ServiceVersion)
text.PrintDictionary(out, "", d)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/healthcheck/healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ SERVICE VERSION NAME METHOD HOST PATH
var listHealthChecksVerboseOutput = strings.Join([]string{
"Fastly API token not provided",
"Fastly API endpoint: https://api.fastly.com",
"Service ID: 123",
"Service ID (via --service-id): 123",
"",
"Version: 1",
" Healthcheck 1/2",
" Name: test",
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/healthcheck/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, healthCheck := range healthChecks {
fmt.Fprintf(out, "\tHealthcheck %d/%d\n", i+1, len(healthChecks))
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/logging/azureblob/azureblob_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ SERVICE VERSION NAME
var listBlobStoragesVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
BlobStorage 1/2
Service ID: 123
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/logging/azureblob/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, azureblob := range azureblobs {
fmt.Fprintf(out, "\tBlobStorage %d/%d\n", i+1, len(azureblobs))
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/logging/bigquery/bigquery_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ SERVICE VERSION NAME
var listBigQueriesVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
BigQuery 1/2
Service ID: 123
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/logging/bigquery/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, bq := range bqs {
fmt.Fprintf(out, "\tBigQuery %d/%d\n", i+1, len(bqs))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ SERVICE VERSION NAME
var listCloudfilesVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
Cloudfiles 1/2
Service ID: 123
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/logging/cloudfiles/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, cloudfile := range cloudfiles {
fmt.Fprintf(out, "\tCloudfiles %d/%d\n", i+1, len(cloudfiles))
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/logging/datadog/datadog_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ SERVICE VERSION NAME
var listDatadogsVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
Datadog 1/2
Service ID: 123
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/logging/datadog/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, datadog := range datadogs {
fmt.Fprintf(out, "\tDatadog %d/%d\n", i+1, len(datadogs))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ SERVICE VERSION NAME
var listDigitalOceansVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
DigitalOcean 1/2
Service ID: 123
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/logging/digitalocean/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, digitalocean := range digitaloceans {
fmt.Fprintf(out, "\tDigitalOcean %d/%d\n", i+1, len(digitaloceans))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ SERVICE VERSION NAME
var listElasticsearchsVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
Elasticsearch 1/2
Service ID: 123
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/logging/elasticsearch/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, elasticsearch := range elasticsearchs {
fmt.Fprintf(out, "\tElasticsearch %d/%d\n", i+1, len(elasticsearchs))
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/logging/ftp/ftp_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ SERVICE VERSION NAME
var listFTPsVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
FTP 1/2
Service ID: 123
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/logging/ftp/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, ftp := range ftps {
fmt.Fprintf(out, "\tFTP %d/%d\n", i+1, len(ftps))
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/logging/gcs/gcs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ SERVICE VERSION NAME
var listGCSsVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
GCS 1/2
Service ID: 123
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/logging/gcs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, gcs := range gcss {
fmt.Fprintf(out, "\tGCS %d/%d\n", i+1, len(gcss))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ SERVICE VERSION NAME
var listGooglePubSubsVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
Google Cloud Pub/Sub 1/2
Service ID: 123
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/logging/googlepubsub/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, googlepubsub := range googlepubsubs {
fmt.Fprintf(out, "\tGoogle Cloud Pub/Sub %d/%d\n", i+1, len(googlepubsubs))
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/logging/heroku/heroku_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ SERVICE VERSION NAME
var listHerokusVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
Heroku 1/2
Service ID: 123
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/logging/heroku/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, heroku := range herokus {
fmt.Fprintf(out, "\tHeroku %d/%d\n", i+1, len(herokus))
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/logging/honeycomb/honeycomb_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ SERVICE VERSION NAME
var listHoneycombsVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
Honeycomb 1/2
Service ID: 123
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/logging/honeycomb/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, honeycomb := range honeycombs {
fmt.Fprintf(out, "\tHoneycomb %d/%d\n", i+1, len(honeycombs))
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/logging/https/https_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ SERVICE VERSION NAME
var listHTTPSsVerboseOutput = strings.TrimSpace(`
Fastly API token not provided
Fastly API endpoint: https://api.fastly.com
Service ID: 123
Service ID (via --service-id): 123
Version: 1
HTTPS 1/2
Service ID: 123
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/logging/https/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, https := range httpss {
fmt.Fprintf(out, "\tHTTPS %d/%d\n", i+1, len(httpss))
Expand Down

0 comments on commit e0df51e

Please sign in to comment.