Skip to content

Commit

Permalink
Remove text.ServiceType abstraction (#449)
Browse files Browse the repository at this point in the history
* remove ServiceType abstraction as the API appears to return 'vcl' now

* fix tests
  • Loading branch information
Integralist authored Oct 21, 2021
1 parent 3324949 commit b405d4d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pkg/commands/service/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
}
}

tw.AddLine(service.Name, service.ID, text.ServiceType(service.Type), activeVersion, updatedAt)
tw.AddLine(service.Name, service.ID, service.Type, activeVersion, updatedAt)
}
tw.Print()
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func listServicesOK(i *fastly.ListServicesInput) ([]*fastly.Service, error) {
{
ID: "789",
Name: "Baz",
Type: "",
Type: "vcl",
CustomerID: "mycustomerid",
ActiveVersion: 1,
// nil UpdatedAt
Expand Down
16 changes: 2 additions & 14 deletions pkg/text/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ import (
"github.com/segmentio/textio"
)

// ServiceType is a utility function which returns the given type string if
// non-empty otherwise returns the default `vcl`. This should be used until the
// API properly returns Service.Type for non-wasm services.
// TODO(phamann): remove once API returns correct type.
func ServiceType(t string) string {
st := "vcl"
if t != "" {
st = t
}
return st
}

// PrintService pretty prints a fastly.Service structure in verbose format
// to a given io.Writer. Consumers can provide a prefix string which will
// be used as a prefix to each line, useful for indentation.
Expand All @@ -29,7 +17,7 @@ func PrintService(out io.Writer, prefix string, s *fastly.Service) {

fmt.Fprintf(out, "ID: %s\n", s.ID)
fmt.Fprintf(out, "Name: %s\n", s.Name)
fmt.Fprintf(out, "Type: %s\n", ServiceType(s.Type))
fmt.Fprintf(out, "Type: %s\n", s.Type)
if s.Comment != "" {
fmt.Fprintf(out, "Comment: %s\n", s.Comment)
}
Expand Down Expand Up @@ -67,7 +55,7 @@ func PrintServiceDetail(out io.Writer, indent string, s *fastly.ServiceDetail) {

fmt.Fprintf(out, "ID: %s\n", s.ID)
fmt.Fprintf(out, "Name: %s\n", s.Name)
fmt.Fprintf(out, "Type: %s\n", ServiceType(s.Type))
fmt.Fprintf(out, "Type: %s\n", s.Type)
if s.Comment != "" {
fmt.Fprintf(out, "Comment: %s\n", s.Comment)
}
Expand Down
37 changes: 4 additions & 33 deletions pkg/text/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,6 @@ import (
"github.com/fastly/go-fastly/v5/fastly"
)

func TestServiceType(t *testing.T) {
for _, testcase := range []struct {
name string
in string
wantResult string
}{
{
name: "empty",
in: "",
wantResult: "vcl",
},
{
name: "vcl",
in: "vcl",
wantResult: "vcl",
},
{
name: "wasm",
in: "wasm",
wantResult: "wasm",
},
} {
t.Run(testcase.name, func(t *testing.T) {
result := text.ServiceType(testcase.in)
testutil.AssertString(t, testcase.wantResult, result)
})
}
}

func TestPrintService(t *testing.T) {
for _, testcase := range []struct {
name string
Expand All @@ -49,13 +20,13 @@ func TestPrintService(t *testing.T) {
name: "without prefix",
prefix: "",
service: &fastly.Service{},
wantOutput: "ID: \nName: \nType: vcl\nCustomer ID: \nActive version: 0\nVersions: 0\n",
wantOutput: "ID: \nName: \nType: \nCustomer ID: \nActive version: 0\nVersions: 0\n",
},
{
name: "with prefix",
prefix: "\t",
service: &fastly.Service{},
wantOutput: "\tID: \n\tName: \n\tType: vcl\n\tCustomer ID: \n\tActive version: 0\n\tVersions: 0\n",
wantOutput: "\tID: \n\tName: \n\tType: \n\tCustomer ID: \n\tActive version: 0\n\tVersions: 0\n",
},
} {
t.Run(testcase.name, func(t *testing.T) {
Expand All @@ -77,13 +48,13 @@ func TestPrintServiceDetail(t *testing.T) {
name: "without prefix",
prefix: "",
service: &fastly.ServiceDetail{},
wantOutput: "ID: \nName: \nType: vcl\nCustomer ID: \nActive version: none\nVersions: 0\n",
wantOutput: "ID: \nName: \nType: \nCustomer ID: \nActive version: none\nVersions: 0\n",
},
{
name: "with prefix",
prefix: "\t",
service: &fastly.ServiceDetail{},
wantOutput: "\tID: \n\tName: \n\tType: vcl\n\tCustomer ID: \n\tActive version: none\n\tVersions: 0\n",
wantOutput: "\tID: \n\tName: \n\tType: \n\tCustomer ID: \n\tActive version: none\n\tVersions: 0\n",
},
} {
t.Run(testcase.name, func(t *testing.T) {
Expand Down

0 comments on commit b405d4d

Please sign in to comment.