code.vegaprotocol.io/vega@v0.79.0/cmd/vegawallet/commands/network_rename_test.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package cmd_test 17 18 import ( 19 "testing" 20 21 cmd "code.vegaprotocol.io/vega/cmd/vegawallet/commands" 22 "code.vegaprotocol.io/vega/cmd/vegawallet/commands/flags" 23 vgrand "code.vegaprotocol.io/vega/libs/rand" 24 "code.vegaprotocol.io/vega/wallet/api" 25 26 "github.com/stretchr/testify/assert" 27 "github.com/stretchr/testify/require" 28 ) 29 30 func TestRenameNetworkFlags(t *testing.T) { 31 t.Run("Valid flags succeeds", testRenameNetworkFlagsValidFlagsSucceeds) 32 t.Run("Missing wallet fails", testRenameNetworkFlagsMissingNetworkFails) 33 t.Run("Missing new name fails", testRenameNetworkFlagsMissingNewNameFails) 34 } 35 36 func testRenameNetworkFlagsValidFlagsSucceeds(t *testing.T) { 37 // given 38 walletName := vgrand.RandomStr(10) 39 newName := vgrand.RandomStr(10) 40 f := &cmd.RenameNetworkFlags{ 41 Network: walletName, 42 NewName: newName, 43 } 44 45 expectedReq := api.AdminRenameNetworkParams{ 46 Network: walletName, 47 NewName: newName, 48 } 49 50 // when 51 req, err := f.Validate() 52 53 // then 54 require.NoError(t, err) 55 require.NotNil(t, req) 56 assert.Equal(t, expectedReq, req) 57 } 58 59 func testRenameNetworkFlagsMissingNetworkFails(t *testing.T) { 60 // given 61 f := newRenameNetworkFlags(t) 62 f.Network = "" 63 64 // when 65 req, err := f.Validate() 66 67 // then 68 assert.ErrorIs(t, err, flags.MustBeSpecifiedError("network")) 69 assert.Empty(t, req) 70 } 71 72 func testRenameNetworkFlagsMissingNewNameFails(t *testing.T) { 73 // given 74 f := newRenameNetworkFlags(t) 75 f.NewName = "" 76 77 // when 78 req, err := f.Validate() 79 80 // then 81 assert.ErrorIs(t, err, flags.MustBeSpecifiedError("new-name")) 82 assert.Empty(t, req) 83 } 84 85 func newRenameNetworkFlags(t *testing.T) *cmd.RenameNetworkFlags { 86 t.Helper() 87 return &cmd.RenameNetworkFlags{ 88 Network: vgrand.RandomStr(10), 89 NewName: vgrand.RandomStr(10), 90 } 91 }