code.vegaprotocol.io/vega@v0.79.0/cmd/vegawallet/commands/network_delete_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 25 "github.com/stretchr/testify/assert" 26 "github.com/stretchr/testify/require" 27 ) 28 29 func TestDeleteNetworkFlags(t *testing.T) { 30 t.Run("Valid flags succeeds", testDeleteNetworkFlagsValidFlagsSucceeds) 31 t.Run("Missing network fails", testDeleteNetworkFlagsMissingNetworkFails) 32 } 33 34 func testDeleteNetworkFlagsValidFlagsSucceeds(t *testing.T) { 35 // given 36 f := &cmd.DeleteNetworkFlags{ 37 Network: vgrand.RandomStr(10), 38 Force: true, 39 } 40 41 // when 42 req, err := f.Validate() 43 44 // then 45 require.NoError(t, err) 46 require.NotNil(t, req) 47 assert.Equal(t, f.Network, req.Name) 48 } 49 50 func testDeleteNetworkFlagsMissingNetworkFails(t *testing.T) { 51 // given 52 f := newDeleteNetworkFlags(t) 53 f.Network = "" 54 55 // when 56 req, err := f.Validate() 57 58 // then 59 assert.ErrorIs(t, err, flags.MustBeSpecifiedError("network")) 60 assert.Empty(t, req) 61 } 62 63 func newDeleteNetworkFlags(t *testing.T) *cmd.DeleteNetworkFlags { 64 t.Helper() 65 66 return &cmd.DeleteNetworkFlags{ 67 Network: vgrand.RandomStr(10), 68 } 69 }