code.vegaprotocol.io/vega@v0.79.0/wallet/service/config_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 service_test
    17  
    18  import (
    19  	"testing"
    20  
    21  	"code.vegaprotocol.io/vega/libs/encoding"
    22  	"code.vegaprotocol.io/vega/wallet/service"
    23  
    24  	"github.com/stretchr/testify/assert"
    25  )
    26  
    27  func TestServiceConfig(t *testing.T) {
    28  	t.Run("test default config valid", testDefaultConfigValid)
    29  	t.Run("test invalid configurations", testInvalidConfigurations)
    30  }
    31  
    32  func testDefaultConfigValid(t *testing.T) {
    33  	// setup
    34  	cfg := service.DefaultConfig()
    35  	assert.NoError(t, cfg.Validate())
    36  }
    37  
    38  func testInvalidConfigurations(t *testing.T) {
    39  	tests := []struct {
    40  		name        string
    41  		expectedErr error
    42  		cfg         service.Config
    43  	}{
    44  		{
    45  			name:        "unset hostname",
    46  			expectedErr: service.ErrServerHostUnset,
    47  			cfg: service.Config{
    48  				Server: service.ServerConfig{
    49  					Port: 1789,
    50  				},
    51  			},
    52  		},
    53  		{
    54  			name:        "unset port",
    55  			expectedErr: service.ErrServerPortUnset,
    56  			cfg: service.Config{
    57  				Server: service.ServerConfig{
    58  					Host: "localhost",
    59  				},
    60  			},
    61  		},
    62  		{
    63  			name:        "invalid log level",
    64  			expectedErr: service.ErrInvalidLogLevelValue,
    65  			cfg: service.Config{
    66  				Server: service.ServerConfig{
    67  					Host: "localhost",
    68  					Port: 1789,
    69  				},
    70  				LogLevel: encoding.LogLevel{
    71  					Level: -100,
    72  				},
    73  			},
    74  		},
    75  	}
    76  	for _, tt := range tests {
    77  		t.Run(tt.name, func(t *testing.T) {
    78  			assert.ErrorIs(t, tt.cfg.Validate(), tt.expectedErr)
    79  		})
    80  	}
    81  }