github.com/aergoio/aergo@v1.3.1/config/config_test.go (about)

     1  /**
     2   *  @file
     3   *  @copyright defined in aergo/LICENSE.txt
     4   */
     5  package config
     6  
     7  import (
     8  	"io/ioutil"
     9  	"path"
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/assert"
    13  )
    14  
    15  func TestSetParamConfPath(t *testing.T) {
    16  	// create a temporary directory
    17  	tmpDir, err := ioutil.TempDir("", "test")
    18  	if err != nil {
    19  		assert.Fail(t, err.Error())
    20  	}
    21  	// generate a random conf file path and set to the conf
    22  	generatedConfFilePath := path.Join(tmpDir, "aergo.toml")
    23  
    24  	// create a default config
    25  	serverCxt := NewServerContext("", generatedConfFilePath)
    26  	defaultConf := serverCxt.GetDefaultConfig()
    27  	var loadedConf Config
    28  
    29  	// create a config
    30  	err = serverCxt.LoadOrCreateConfig(defaultConf)
    31  	if err != nil {
    32  		assert.Fail(t, err.Error())
    33  	}
    34  
    35  	// load a saved config file
    36  	if err := serverCxt.LoadOrCreateConfig(&loadedConf); err != nil {
    37  		assert.Fail(t, err.Error())
    38  	}
    39  
    40  	// compare each other
    41  	assert.Equal(t, defaultConf.(*Config), &loadedConf)
    42  }