github.com/lingyao2333/mo-zero@v1.4.1/core/discov/config_test.go (about)

     1  package discov
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestConfig(t *testing.T) {
    10  	tests := []struct {
    11  		EtcdConf
    12  		pass bool
    13  	}{
    14  		{
    15  			EtcdConf: EtcdConf{},
    16  			pass:     false,
    17  		},
    18  		{
    19  			EtcdConf: EtcdConf{
    20  				Key: "any",
    21  			},
    22  			pass: false,
    23  		},
    24  		{
    25  			EtcdConf: EtcdConf{
    26  				Hosts: []string{"any"},
    27  			},
    28  			pass: false,
    29  		},
    30  		{
    31  			EtcdConf: EtcdConf{
    32  				Hosts: []string{"any"},
    33  				Key:   "key",
    34  			},
    35  			pass: true,
    36  		},
    37  	}
    38  
    39  	for _, test := range tests {
    40  		if test.pass {
    41  			assert.Nil(t, test.EtcdConf.Validate())
    42  		} else {
    43  			assert.NotNil(t, test.EtcdConf.Validate())
    44  		}
    45  	}
    46  }
    47  
    48  func TestEtcdConf_HasAccount(t *testing.T) {
    49  	tests := []struct {
    50  		EtcdConf
    51  		hasAccount bool
    52  	}{
    53  		{
    54  			EtcdConf: EtcdConf{
    55  				Hosts: []string{"any"},
    56  				Key:   "key",
    57  			},
    58  			hasAccount: false,
    59  		},
    60  		{
    61  			EtcdConf: EtcdConf{
    62  				Hosts: []string{"any"},
    63  				Key:   "key",
    64  				User:  "foo",
    65  			},
    66  			hasAccount: false,
    67  		},
    68  		{
    69  			EtcdConf: EtcdConf{
    70  				Hosts: []string{"any"},
    71  				Key:   "key",
    72  				User:  "foo",
    73  				Pass:  "bar",
    74  			},
    75  			hasAccount: true,
    76  		},
    77  	}
    78  
    79  	for _, test := range tests {
    80  		assert.Equal(t, test.hasAccount, test.EtcdConf.HasAccount())
    81  	}
    82  }