github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/utils/config_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"bytes"
     5  	"io"
     6  	"os"
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestLoadConfig(t *testing.T) {
    14  	f1 := "test"
    15  	buffer := bytes.NewBufferString(f1)
    16  	fname, err := TempFile(io.NopCloser(buffer))
    17  	assert.NoError(t, err)
    18  	_, err = LoadConfig(fname)
    19  	assert.Error(t, err)
    20  	os.Remove(fname)
    21  
    22  	f1 = `log_level: "DEBUG"
    23  bind: ":5001"
    24  statsd: "127.0.0.1:8125"
    25  profile: ":12346"
    26  global_timeout: 300s
    27  
    28  auth:
    29      username: admin
    30      password: password
    31  etcd:
    32      machines:
    33          - "http://127.0.0.1:2379"
    34      lock_prefix: "core/_lock"
    35  git:
    36      public_key: "***REMOVED***"
    37      private_key: "***REMOVED***"
    38      token: "***REMOVED***"
    39      scm_type: "github"
    40  docker:
    41      network_mode: "bridge"
    42      cert_path: "/etc/eru/tls"
    43      hub: "hub.docker.com"
    44      namespace: "projecteru2"
    45      build_pod: "eru-test"
    46      local_dns: true
    47  `
    48  
    49  	buffer = bytes.NewBufferString(f1)
    50  	fname, err = TempFile(io.NopCloser(buffer))
    51  	assert.NoError(t, err)
    52  	config, err := LoadConfig(fname)
    53  	assert.NoError(t, err)
    54  	assert.Equal(t, config.LockTimeout, time.Duration(time.Second*30))
    55  	assert.Equal(t, config.GlobalTimeout, time.Duration(time.Second*300))
    56  	assert.Equal(t, config.Etcd.Prefix, "/eru")
    57  	assert.Equal(t, config.Docker.Log.Type, "journald")
    58  	assert.Equal(t, config.Docker.APIVersion, "1.32")
    59  	assert.Equal(t, config.Scheduler.MaxShare, -1)
    60  	assert.Equal(t, config.Scheduler.ShareBase, 100)
    61  	os.Remove(fname)
    62  }