code.vegaprotocol.io/vega@v0.79.0/cmd/vegawallet/commands/permissions_purge_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 TestPurgePermissionsFlags(t *testing.T) { 30 t.Run("Valid flags succeeds", testPurgePermissionsFlagsValidFlagsSucceeds) 31 t.Run("Missing flags fails", testPurgePermissionsFlagsMissingFlagsFails) 32 } 33 34 func testPurgePermissionsFlagsValidFlagsSucceeds(t *testing.T) { 35 // given 36 testDir := t.TempDir() 37 expectedPassphrase, passphraseFilePath := NewPassphraseFile(t, testDir) 38 f := &cmd.PurgePermissionsFlags{ 39 Wallet: vgrand.RandomStr(10), 40 PassphraseFile: passphraseFilePath, 41 Force: true, 42 } 43 44 // when 45 req, passphrase, err := f.Validate() 46 47 // then 48 require.NoError(t, err) 49 assert.Equal(t, f.Wallet, req.Wallet) 50 assert.Equal(t, expectedPassphrase, passphrase) 51 } 52 53 func testPurgePermissionsFlagsMissingFlagsFails(t *testing.T) { 54 testDir := t.TempDir() 55 _, passphraseFilePath := NewPassphraseFile(t, testDir) 56 57 tcs := []struct { 58 name string 59 flags *cmd.PurgePermissionsFlags 60 missingFlag string 61 }{ 62 { 63 name: "without wallet", 64 flags: &cmd.PurgePermissionsFlags{ 65 Wallet: "", 66 PassphraseFile: passphraseFilePath, 67 }, 68 missingFlag: "wallet", 69 }, 70 } 71 72 for _, tc := range tcs { 73 t.Run(tc.name, func(tt *testing.T) { 74 // when 75 req, _, err := tc.flags.Validate() 76 77 // then 78 assert.ErrorIs(t, err, flags.MustBeSpecifiedError(tc.missingFlag)) 79 require.Empty(t, req) 80 }) 81 } 82 }