code.vegaprotocol.io/vega@v0.79.0/cmd/vegawallet/commands/network_describe_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 TestDescribeNetworkFlags(t *testing.T) {
    31  	t.Run("Valid flags with Network succeeds", testDescribeNetworkValidFlagsWithNetworkSucceeds)
    32  	t.Run("Invalid flags without Network fails", testDescribeNetworkInvalidFlagsWithoutNetworkFails)
    33  }
    34  
    35  func testDescribeNetworkValidFlagsWithNetworkSucceeds(t *testing.T) {
    36  	// given
    37  	networkName := vgrand.RandomStr(10)
    38  
    39  	f := &cmd.DescribeNetworkFlags{
    40  		Network: networkName,
    41  	}
    42  
    43  	expectedReq := api.AdminDescribeNetworkParams{
    44  		Name: networkName,
    45  	}
    46  	// when
    47  	req, err := f.Validate()
    48  
    49  	// then
    50  	require.NoError(t, err)
    51  	require.NotNil(t, req)
    52  	assert.Equal(t, expectedReq, req)
    53  }
    54  
    55  func testDescribeNetworkInvalidFlagsWithoutNetworkFails(t *testing.T) {
    56  	// given
    57  	f := &cmd.DescribeNetworkFlags{}
    58  
    59  	// when
    60  	req, err := f.Validate()
    61  
    62  	// then
    63  	assert.ErrorIs(t, err, flags.MustBeSpecifiedError("network"))
    64  	require.Empty(t, req)
    65  }