Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
)

require (
github.com/fastly/go-fastly/v9 v9.0.1
github.com/fastly/go-fastly/v9 v9.2.0
github.com/hashicorp/cap v0.5.0
github.com/kennygrant/sanitize v1.2.4
github.com/mholt/archiver v3.1.1+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj6
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0 h1:90Ly+6UfUypEF6vvvW5rQIv9opIL8CbmW9FT20LDQoY=
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0/go.mod h1:V+Qd57rJe8gd4eiGzZyg4h54VLHmYVVw54iMnlAMrF8=
github.com/fastly/go-fastly/v9 v9.0.1 h1:964+VZGeEd6SMuJBGcdfdpBnS5631PT3lSHGPYq2KOU=
github.com/fastly/go-fastly/v9 v9.0.1/go.mod h1:5w2jgJBZqQEebOwM/rRg7wutAcpDTziiMYWb/6qdM7U=
github.com/fastly/go-fastly/v9 v9.2.0 h1:+tCE/5LV0fa9bMuIBKx5Xtc4N/dTlRjB02b3bSddRv4=
github.com/fastly/go-fastly/v9 v9.2.0/go.mod h1:5w2jgJBZqQEebOwM/rRg7wutAcpDTziiMYWb/6qdM7U=
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible h1:FhrXlfhgGCS+uc6YwyiFUt04alnjpoX7vgDKJxS6Qbk=
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible/go.mod h1:U8UynVoU1SQaqD2I4ZqgYd5lx3A1ipQYn4aSt2Y5h6c=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
Expand Down
20 changes: 19 additions & 1 deletion pkg/commands/compute/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"io"
"net/http"
"os"
"path/filepath"
"strings"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/mock"
"github.com/fastly/cli/pkg/testutil"
)

Expand Down Expand Up @@ -42,6 +44,8 @@ func TestInit(t *testing.T) {
name string
args []string
configFile config.File
httpClientRes []*http.Response
httpClientErr []error
manifest string
wantFiles []string
unwantedFiles []string
Expand All @@ -54,7 +58,17 @@ func TestInit(t *testing.T) {
{
name: "broken endpoint",
args: args("compute init --from https://example.com/i-dont-exist"),
wantError: "failed to get package: 404 Not Found",
wantError: "failed to get package: Not Found",
httpClientRes: []*http.Response{
{
Body: io.NopCloser(strings.NewReader("")),
Status: http.StatusText(http.StatusNotFound),
StatusCode: http.StatusNotFound,
},
},
httpClientErr: []error{
nil,
},
},
{
name: "name prompt",
Expand Down Expand Up @@ -364,6 +378,10 @@ func TestInit(t *testing.T) {
opts := testutil.MockGlobalData(testcase.args, &stdout)
opts.Config = testcase.configFile

if testcase.httpClientRes != nil || testcase.httpClientErr != nil {
opts.HTTPClient = mock.HTMLClient(testcase.httpClientRes, testcase.httpClientErr)
}

// we need to define stdin as the init process prompts the user multiple
// times, but we don't need to provide any values as all our prompts will
// fallback to default values if the input is unrecognised.
Expand Down
10 changes: 5 additions & 5 deletions pkg/commands/logging/scalyr/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type CreateCommand struct {
Placement argparser.OptionalString
Region argparser.OptionalString
ResponseCondition argparser.OptionalString
ProjectID argparser.OptionalString
}

// NewCreateCommand returns a usable command registered under the parent.
Expand Down Expand Up @@ -60,6 +61,7 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
common.Format(c.CmdClause, &c.Format)
common.FormatVersion(c.CmdClause, &c.FormatVersion)
common.Placement(c.CmdClause, &c.Placement)
c.CmdClause.Flag("project-id", "The name of the logfile field sent to Scalyr").Action(c.ProjectID.Set).StringVar(&c.ProjectID.Value)
c.CmdClause.Flag("region", "The region that log data will be sent to. One of US or EU. Defaults to US if undefined").Action(c.Region.Set).StringVar(&c.Region.Value)
common.ResponseCondition(c.CmdClause, &c.ResponseCondition)
c.RegisterFlag(argparser.StringFlagOpts{
Expand Down Expand Up @@ -89,26 +91,24 @@ func (c *CreateCommand) ConstructInput(serviceID string, serviceVersion int) (*f
if c.Token.WasSet {
input.Token = &c.Token.Value
}

if c.Region.WasSet {
input.Region = &c.Region.Value
}

if c.Format.WasSet {
input.Format = &c.Format.Value
}

if c.FormatVersion.WasSet {
input.FormatVersion = &c.FormatVersion.Value
}

if c.ResponseCondition.WasSet {
input.ResponseCondition = &c.ResponseCondition.Value
}

if c.Placement.WasSet {
input.Placement = &c.Placement.Value
}
if c.ProjectID.WasSet {
input.ProjectID = &c.ProjectID.Value
}

return &input, nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/logging/scalyr/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
"Format": fastly.ToValue(o.Format),
"Name": fastly.ToValue(o.Name),
"Placement": fastly.ToValue(o.Placement),
"Project ID": fastly.ToValue(o.ProjectID),
"Region": fastly.ToValue(o.Region),
"Response condition": fastly.ToValue(o.ResponseCondition),
"Token": fastly.ToValue(o.Token),
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/logging/scalyr/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
fmt.Fprintf(out, "\t\tFormat version: %d\n", fastly.ToValue(scalyr.FormatVersion))
fmt.Fprintf(out, "\t\tResponse condition: %s\n", fastly.ToValue(scalyr.ResponseCondition))
fmt.Fprintf(out, "\t\tPlacement: %s\n", fastly.ToValue(scalyr.Placement))
fmt.Fprintf(out, "\t\tProject ID: %s\n", fastly.ToValue(scalyr.ProjectID))
}
fmt.Fprintln(out)

Expand Down
6 changes: 6 additions & 0 deletions pkg/commands/logging/scalyr/scalyr_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ func listScalyrsOK(i *fastly.ListScalyrsInput) ([]*fastly.Scalyr, error) {
FormatVersion: fastly.ToPointer(2),
ResponseCondition: fastly.ToPointer("Prevent default logging"),
Placement: fastly.ToPointer("none"),
ProjectID: fastly.ToPointer("example-project"),
},
{
ServiceID: fastly.ToPointer(i.ServiceID),
Expand All @@ -343,6 +344,7 @@ func listScalyrsOK(i *fastly.ListScalyrsInput) ([]*fastly.Scalyr, error) {
FormatVersion: fastly.ToPointer(2),
ResponseCondition: fastly.ToPointer("Prevent default logging"),
Placement: fastly.ToPointer("none"),
ProjectID: fastly.ToPointer("example-project"),
},
}, nil
}
Expand Down Expand Up @@ -374,6 +376,7 @@ Version: 1
Format version: 2
Response condition: Prevent default logging
Placement: none
Project ID: example-project
Scalyr 2/2
Service ID: 123
Version: 1
Expand All @@ -384,6 +387,7 @@ Version: 1
Format version: 2
Response condition: Prevent default logging
Placement: none
Project ID: example-project
`) + "\n\n"

func getScalyrOK(i *fastly.GetScalyrInput) (*fastly.Scalyr, error) {
Expand All @@ -397,6 +401,7 @@ func getScalyrOK(i *fastly.GetScalyrInput) (*fastly.Scalyr, error) {
FormatVersion: fastly.ToPointer(2),
ResponseCondition: fastly.ToPointer("Prevent default logging"),
Placement: fastly.ToPointer("none"),
ProjectID: fastly.ToPointer("example-project"),
}, nil
}

Expand All @@ -409,6 +414,7 @@ Format: %h %l %u %t "%r" %>s %b
Format version: 2
Name: logs
Placement: none
Project ID: example-project
Region: US
Response condition: Prevent default logging
Service ID: 123
Expand Down
4 changes: 4 additions & 0 deletions pkg/commands/logging/scalyr/scalyr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestCreateScalyrInput(t *testing.T) {
Format: fastly.ToPointer(`%h %l %u %t "%r" %>s %b`),
ResponseCondition: fastly.ToPointer("Prevent default logging"),
Placement: fastly.ToPointer("none"),
ProjectID: fastly.ToPointer("example-project"),
},
},
{
Expand Down Expand Up @@ -128,6 +129,7 @@ func TestUpdateScalyrInput(t *testing.T) {
ResponseCondition: fastly.ToPointer("new4"),
Placement: fastly.ToPointer("new5"),
Region: fastly.ToPointer("new6"),
ProjectID: fastly.ToPointer("new7"),
},
},
{
Expand Down Expand Up @@ -251,6 +253,7 @@ func createCommandAll() *scalyr.CreateCommand {
FormatVersion: argparser.OptionalInt{Optional: argparser.Optional{WasSet: true}, Value: 2},
ResponseCondition: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "Prevent default logging"},
Placement: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "none"},
ProjectID: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "example-project"},
}
}

Expand Down Expand Up @@ -330,6 +333,7 @@ func updateCommandAll() *scalyr.UpdateCommand {
ResponseCondition: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "new4"},
Placement: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "new5"},
Region: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "new6"},
ProjectID: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "new7"},
}
}

Expand Down
13 changes: 5 additions & 8 deletions pkg/commands/logging/scalyr/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type UpdateCommand struct {
Region argparser.OptionalString
ResponseCondition argparser.OptionalString
Placement argparser.OptionalString
ProjectID argparser.OptionalString
}

// NewUpdateCommand returns a usable command registered under the parent.
Expand Down Expand Up @@ -62,6 +63,7 @@ func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateComman
common.FormatVersion(c.CmdClause, &c.FormatVersion)
c.CmdClause.Flag("new-name", "New name of the Scalyr logging object").Action(c.NewName.Set).StringVar(&c.NewName.Value)
common.Placement(c.CmdClause, &c.Placement)
c.CmdClause.Flag("project-id", "The name of the logfile field sent to Scalyr").Action(c.ProjectID.Set).StringVar(&c.ProjectID.Value)
c.CmdClause.Flag("region", "The region that log data will be sent to. One of US or EU. Defaults to US if undefined").Action(c.Region.Set).StringVar(&c.Region.Value)
common.ResponseCondition(c.CmdClause, &c.ResponseCondition)
c.RegisterFlag(argparser.StringFlagOpts{
Expand All @@ -86,35 +88,30 @@ func (c *UpdateCommand) ConstructInput(serviceID string, serviceVersion int) (*f
ServiceVersion: serviceVersion,
Name: c.EndpointName,
}

if c.NewName.WasSet {
input.NewName = &c.NewName.Value
}

if c.Format.WasSet {
input.Format = &c.Format.Value
}

if c.FormatVersion.WasSet {
input.FormatVersion = &c.FormatVersion.Value
}

if c.Token.WasSet {
input.Token = &c.Token.Value
}

if c.Region.WasSet {
input.Region = &c.Region.Value
}

if c.ResponseCondition.WasSet {
input.ResponseCondition = &c.ResponseCondition.Value
}

if c.Placement.WasSet {
input.Placement = &c.Placement.Value
}

if c.ProjectID.WasSet {
input.ProjectID = &c.ProjectID.Value
}
return &input, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/mock/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (c HTTPClient) Get(p string, _ *fastly.RequestOptions) (*http.Response, err

// Do mocks a HTTP Client Do operation.
func (c HTTPClient) Do(r *http.Request) (*http.Response, error) {
fmt.Printf("r.URL: %#v\n", r.URL.String())
fmt.Printf("r: %#v\n", r)
c.Index++
return c.Responses[c.Index], c.Errors[c.Index]
Expand Down