github.com/inphi/go-ethereum@v1.9.7/cmd/utils/flags_test.go (about)

     1  // Copyright 2019 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  	"reflect"
    22  	"testing"
    23  )
    24  
    25  func Test_SplitTagsFlag(t *testing.T) {
    26  	tests := []struct {
    27  		name string
    28  		args string
    29  		want map[string]string
    30  	}{
    31  		{
    32  			"2 tags case",
    33  			"host=localhost,bzzkey=123",
    34  			map[string]string{
    35  				"host":   "localhost",
    36  				"bzzkey": "123",
    37  			},
    38  		},
    39  		{
    40  			"1 tag case",
    41  			"host=localhost123",
    42  			map[string]string{
    43  				"host": "localhost123",
    44  			},
    45  		},
    46  		{
    47  			"empty case",
    48  			"",
    49  			map[string]string{},
    50  		},
    51  		{
    52  			"garbage",
    53  			"smth=smthelse=123",
    54  			map[string]string{},
    55  		},
    56  	}
    57  	for _, tt := range tests {
    58  		t.Run(tt.name, func(t *testing.T) {
    59  			if got := SplitTagsFlag(tt.args); !reflect.DeepEqual(got, tt.want) {
    60  				t.Errorf("splitTagsFlag() = %v, want %v", got, tt.want)
    61  			}
    62  		})
    63  	}
    64  }