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
8 changes: 5 additions & 3 deletions pkg/commands/dictionary/dictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"strings"
"testing"

"github.com/fastly/go-fastly/v8/fastly"

"github.com/fastly/cli/pkg/app"
"github.com/fastly/cli/pkg/mock"
"github.com/fastly/cli/pkg/testutil"
"github.com/fastly/go-fastly/v8/fastly"
)

func TestDictionaryDescribe(t *testing.T) {
Expand Down Expand Up @@ -292,6 +293,7 @@ func TestUpdateDictionary(t *testing.T) {
opts := testutil.NewRunOpts(testcase.args, &stdout)
opts.APIClient = mock.APIClient(testcase.api)
err := app.Run(opts)
t.Log(stdout.String())
testutil.AssertErrorContains(t, err, testcase.wantError)
testutil.AssertString(t, testcase.wantOutput, stdout.String())
})
Expand Down Expand Up @@ -468,8 +470,8 @@ var updateDictionaryOutputVerbose = strings.Join(
"",
"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.",
"Service version 1 is not editable, so it was automatically cloned because --autoclone is enabled. Now operating on",
"version 4.",
"",
strings.TrimSpace(updateDictionaryNameOutput),
updateDictionaryOutputVersionCloned,
Expand Down
22 changes: 12 additions & 10 deletions pkg/commands/vcl/snippet/snippet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bytes"
"testing"

"github.com/fastly/go-fastly/v8/fastly"

"github.com/fastly/cli/pkg/app"
"github.com/fastly/cli/pkg/mock"
"github.com/fastly/cli/pkg/testutil"
"github.com/fastly/go-fastly/v8/fastly"
)

func TestVCLSnippetCreate(t *testing.T) {
Expand Down Expand Up @@ -65,7 +66,7 @@ func TestVCLSnippetCreate(t *testing.T) {
},
},
Args: args("vcl snippet create --content ./testdata/snippet.vcl --name foo --service-id 123 --type recv --version 3"),
WantOutput: "Created VCL snippet 'foo' (service: 123, version: 3, dynamic: false, snippet id: 123,\ntype: recv, priority: 0)",
WantOutput: "Created VCL snippet 'foo' (service: 123, version: 3, dynamic: false, snippet id: 123, type: recv, priority: 0)",
},
{
Name: "validate CreateSnippet API success for dynamic Snippet",
Expand Down Expand Up @@ -94,7 +95,7 @@ func TestVCLSnippetCreate(t *testing.T) {
},
},
Args: args("vcl snippet create --content ./testdata/snippet.vcl --dynamic --name foo --service-id 123 --type recv --version 3"),
WantOutput: "Created VCL snippet 'foo' (service: 123, version: 3, dynamic: true, snippet id: 123,\ntype: recv, priority: 0)",
WantOutput: "Created VCL snippet 'foo' (service: 123, version: 3, dynamic: true, snippet id: 123, type: recv, priority: 0)",
},
{
Name: "validate Priority set",
Expand Down Expand Up @@ -124,7 +125,7 @@ func TestVCLSnippetCreate(t *testing.T) {
},
},
Args: args("vcl snippet create --content ./testdata/snippet.vcl --name foo --priority 1 --service-id 123 --type recv --version 3"),
WantOutput: "Created VCL snippet 'foo' (service: 123, version: 3, dynamic: false, snippet id: 123,\ntype: recv, priority: 1)",
WantOutput: "Created VCL snippet 'foo' (service: 123, version: 3, dynamic: false, snippet id: 123, type: recv, priority: 1)",
},
{
Name: "validate --autoclone results in cloned service version",
Expand Down Expand Up @@ -154,7 +155,7 @@ func TestVCLSnippetCreate(t *testing.T) {
},
},
Args: args("vcl snippet create --autoclone --content ./testdata/snippet.vcl --name foo --service-id 123 --type recv --version 1"),
WantOutput: "Created VCL snippet 'foo' (service: 123, version: 4, dynamic: false, snippet id: 123,\ntype: recv, priority: 0)",
WantOutput: "Created VCL snippet 'foo' (service: 123, version: 4, dynamic: false, snippet id: 123, type: recv, priority: 0)",
},
{
Name: "validate CreateSnippet API success with inline Snippet content",
Expand Down Expand Up @@ -183,7 +184,7 @@ func TestVCLSnippetCreate(t *testing.T) {
},
},
Args: args("vcl snippet create --content inline_vcl --name foo --service-id 123 --type recv --version 3"),
WantOutput: "Created VCL snippet 'foo' (service: 123, version: 3, dynamic: false, snippet id: 123,\ntype: recv, priority: 0)",
WantOutput: "Created VCL snippet 'foo' (service: 123, version: 3, dynamic: false, snippet id: 123, type: recv, priority: 0)",
},
}

Expand All @@ -194,8 +195,9 @@ func TestVCLSnippetCreate(t *testing.T) {
opts := testutil.NewRunOpts(testcase.Args, &stdout)
opts.APIClient = mock.APIClient(testcase.API)
err := app.Run(opts)
t.Log(stdout.String())
testutil.AssertErrorContains(t, err, testcase.WantError)
testutil.AssertStringContains(t, stdout.String(), testcase.WantOutput)
testutil.AssertStringContains(t, testutil.StripNewLines(stdout.String()), testcase.WantOutput)
testutil.AssertPathContentFlag("content", testcase.WantError, testcase.Args, "snippet.vcl", content, t)
})
}
Expand Down Expand Up @@ -508,7 +510,7 @@ func TestVCLSnippetUpdate(t *testing.T) {
},
},
Args: args("vcl snippet update --content inline_vcl --name foo --new-name bar --service-id 123 --type recv --version 3"),
WantOutput: "Updated VCL snippet 'bar' (previously: 'foo', service: 123, version: 3, type: recv,\npriority: 100)",
WantOutput: "Updated VCL snippet 'bar' (previously: 'foo', service: 123, version: 3, type: recv, priority: 100)",
},
{
Name: "validate UpdateDynamicSnippet API success",
Expand Down Expand Up @@ -548,7 +550,7 @@ func TestVCLSnippetUpdate(t *testing.T) {
},
},
Args: args("vcl snippet update --autoclone --content inline_vcl --name foo --new-name bar --priority 1 --service-id 123 --type recv --version 1"),
WantOutput: "Updated VCL snippet 'bar' (previously: 'foo', service: 123, version: 4, type: recv,\npriority: 1)",
WantOutput: "Updated VCL snippet 'bar' (previously: 'foo', service: 123, version: 4, type: recv, priority: 1)",
},
}

Expand All @@ -560,7 +562,7 @@ func TestVCLSnippetUpdate(t *testing.T) {
opts.APIClient = mock.APIClient(testcase.API)
err := app.Run(opts)
testutil.AssertErrorContains(t, err, testcase.WantError)
testutil.AssertStringContains(t, stdout.String(), testcase.WantOutput)
testutil.AssertStringContains(t, testutil.StripNewLines(stdout.String()), testcase.WantOutput)
testutil.AssertPathContentFlag("content", testcase.WantError, testcase.Args, "snippet.vcl", content, t)
})
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/testutil/string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package testutil

import "strings"

// StripNewLines removes all newline delimiters.
func StripNewLines(s string) string {
return strings.ReplaceAll(s, "\n", "")
}
2 changes: 1 addition & 1 deletion pkg/text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

// DefaultTextWidth is the width that should be passed to Wrap for most
// general-purpose blocks of text intended for the user.
const DefaultTextWidth = 90
const DefaultTextWidth = 120

// Wrap a string at word boundaries with a maximum line length of width. Each
// newline-delimited line in the text is trimmed of whitespace before being
Expand Down