github.com/celestiaorg/celestia-node@v0.15.0-beta.1/nodebuilder/rpc/config_test.go (about)

     1  package rpc
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  // TestDefaultConfig tests that the default gateway config is correct.
    10  func TestDefaultConfig(t *testing.T) {
    11  	expected := Config{
    12  		Address: defaultBindAddress,
    13  		Port:    defaultPort,
    14  	}
    15  
    16  	assert.Equal(t, expected, DefaultConfig())
    17  }
    18  
    19  func TestConfigValidate(t *testing.T) {
    20  	tests := []struct {
    21  		name string
    22  		cfg  Config
    23  		err  bool
    24  	}{
    25  		{
    26  			name: "valid config",
    27  			cfg: Config{
    28  				Address: "127.0.0.1",
    29  				Port:    "8080",
    30  			},
    31  			err: false,
    32  		},
    33  		{
    34  			name: "invalid address",
    35  			cfg: Config{
    36  				Address: "invalid",
    37  				Port:    "8080",
    38  			},
    39  			err: true,
    40  		},
    41  		{
    42  			name: "invalid port",
    43  			cfg: Config{
    44  				Address: "127.0.0.1",
    45  				Port:    "invalid",
    46  			},
    47  			err: true,
    48  		},
    49  	}
    50  
    51  	for _, tt := range tests {
    52  		t.Run(tt.name, func(t *testing.T) {
    53  			err := tt.cfg.Validate()
    54  			if (err != nil) != tt.err {
    55  				t.Errorf("Config.Validate() error = %v, err %v", err, tt.err)
    56  			}
    57  		})
    58  	}
    59  }