github.com/ethereum/go-ethereum@v1.14.4-0.20240516095835-473ee8fc07a3/cmd/utils/prompt_test.go (about)

     1  // Copyright 2020 The go-ethereum Authors
     2  // This file is part of go-ethereum.
     3  //
     4  // go-ethereum is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // go-ethereum is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // Package utils contains internal helper functions for go-ethereum commands.
    18  package utils
    19  
    20  import (
    21  	"testing"
    22  )
    23  
    24  func TestGetPassPhraseWithList(t *testing.T) {
    25  	t.Parallel()
    26  	type args struct {
    27  		text         string
    28  		confirmation bool
    29  		index        int
    30  		passwords    []string
    31  	}
    32  	tests := []struct {
    33  		name string
    34  		args args
    35  		want string
    36  	}{
    37  		{
    38  			"test1",
    39  			args{
    40  				"text1",
    41  				false,
    42  				0,
    43  				[]string{"zero", "one", "two"},
    44  			},
    45  			"zero",
    46  		},
    47  		{
    48  			"test2",
    49  			args{
    50  				"text2",
    51  				false,
    52  				5,
    53  				[]string{"zero", "one", "two"},
    54  			},
    55  			"two",
    56  		},
    57  		{
    58  			"test3",
    59  			args{
    60  				"text3",
    61  				true,
    62  				1,
    63  				[]string{"zero", "one", "two"},
    64  			},
    65  			"one",
    66  		},
    67  	}
    68  	for _, tt := range tests {
    69  		tt := tt
    70  		t.Run(tt.name, func(t *testing.T) {
    71  			t.Parallel()
    72  			if got := GetPassPhraseWithList(tt.args.text, tt.args.confirmation, tt.args.index, tt.args.passwords); got != tt.want {
    73  				t.Errorf("GetPassPhraseWithList() = %v, want %v", got, tt.want)
    74  			}
    75  		})
    76  	}
    77  }