From a991ee2430b3feea327105d62ac3c971cfa8c0ed Mon Sep 17 00:00:00 2001 From: Derick Rentz Date: Thu, 20 Jul 2023 10:17:05 -0300 Subject: [PATCH] chore: remove indentation from chain serve output to make it easier to properly copy and paste (#3522) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: remove identation from chain serve output to make it easier to properly copy and paste * refactor: accountview tests to follow tt patterns * fix: adding missing changelog for chain serve indentation changes * refactor: following naming convention on tests for account string Co-authored-by: Jerónimo Albi --------- Co-authored-by: Derick Rentz Co-authored-by: Jerónimo Albi Co-authored-by: Danilo Pantani --- changelog.md | 1 + ignite/pkg/cliui/view/accountview/account.go | 8 +---- .../cliui/view/accountview/account_test.go | 36 +++++++++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 ignite/pkg/cliui/view/accountview/account_test.go diff --git a/changelog.md b/changelog.md index 60ab0ff5ee..19b5b85e34 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ - [#3581](https://github.com/ignite/cli/pull/3581) Bump cometbft and cometbft-db in the template - [#3559](https://github.com/ignite/cli/pull/3559) Bump network plugin version to `v0.1.1` +- [#3522](https://github.com/ignite/cli/pull/3522) Remove indentation from `chain serve` output ## [`v0.27.0`](https://github.com/ignite/cli/releases/tag/v0.27.0) diff --git a/ignite/pkg/cliui/view/accountview/account.go b/ignite/pkg/cliui/view/accountview/account.go index 57270298f8..801f9a8a97 100644 --- a/ignite/pkg/cliui/view/accountview/account.go +++ b/ignite/pkg/cliui/view/accountview/account.go @@ -4,9 +4,6 @@ import ( "fmt" "strings" - "github.com/muesli/reflow/indent" - "github.com/muesli/reflow/wordwrap" - "github.com/ignite/cli/ignite/pkg/cliui/colors" "github.com/ignite/cli/ignite/pkg/cliui/icons" ) @@ -48,10 +45,7 @@ func (a Account) String() string { // The account is new when the mnemonic is available if a.Mnemonic != "" { - m := wordwrap.String(a.Mnemonic, 80) - m = indent.String(m, 2) - - return fmt.Sprintf(fmtNewAccount, icons.OK, name, a.Address, colors.Mnemonic(m)) + return fmt.Sprintf(fmtNewAccount, icons.OK, name, a.Address, colors.Mnemonic(a.Mnemonic)) } return fmt.Sprintf(fmtExistingAccount, icons.User, name, a.Address) diff --git a/ignite/pkg/cliui/view/accountview/account_test.go b/ignite/pkg/cliui/view/accountview/account_test.go new file mode 100644 index 0000000000..218d9375cc --- /dev/null +++ b/ignite/pkg/cliui/view/accountview/account_test.go @@ -0,0 +1,36 @@ +package accountview_test + +import ( + "testing" + + "github.com/ignite/cli/ignite/pkg/cliui/view/accountview" + "github.com/stretchr/testify/assert" +) + +func TestAccountString(t *testing.T) { + tests := []struct { + name string + account accountview.Account + want string + }{ + { + name: "new account (mnemonic available) to string is not idented", + account: accountview.NewAccount("alice", "cosmos193he38n21khnmb2", accountview.WithMnemonic("person estate daughter box chimney clay bronze ring story truck make excess ring frame desk start food leader sleep predict item rifle stem boy")), + want: "✔ Added account \x1b[1malice\x1b[0m with address cosmos193he38n21khnmb2 and mnemonic:\nperson estate daughter box chimney clay bronze ring story truck make excess ring frame desk start food leader sleep predict item rifle stem boy\n", + }, + { + name: "existent account to string is not idented", + account: accountview.NewAccount("alice", "cosmos193he38n21khnmb2"), + want: "👤 \x1b[1malice\x1b[0m's account address: cosmos193he38n21khnmb2\n", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := tt.account.String() + + assert.NotEmpty(t, result) + assert.Equal(t, tt.want, result) + }) + } +}