github.com/cloudwego/kitex@v0.9.0/pkg/utils/config_test.go (about)

     1  /*
     2   * Copyright 2021 CloudWeGo Authors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package utils
    18  
    19  import (
    20  	"os"
    21  	"path"
    22  	"testing"
    23  
    24  	"github.com/cloudwego/kitex/internal/test"
    25  )
    26  
    27  func TestGetConfDir(t *testing.T) {
    28  	os.Setenv(EnvConfDir, "test_conf")
    29  	confDir := GetConfDir()
    30  	test.Assert(t, confDir == "test_conf")
    31  
    32  	os.Setenv(EnvConfDir, "")
    33  	confDir = GetConfDir()
    34  	test.Assert(t, confDir == DefaultConfDir)
    35  }
    36  
    37  func TestGetConfFile(t *testing.T) {
    38  	os.Setenv(EnvConfFile, "test.yml")
    39  	confFile := GetConfFile()
    40  	test.Assert(t, confFile == path.Join(GetConfDir(), "test.yml"))
    41  
    42  	os.Setenv(EnvConfFile, "")
    43  	confFile = GetConfFile()
    44  	test.Assert(t, confFile == path.Join(GetConfDir(), DefaultConfFile))
    45  }
    46  
    47  func TestGetEnvLogDir(t *testing.T) {
    48  	os.Setenv(EnvLogDir, "test_log")
    49  	logDir := GetEnvLogDir()
    50  	test.Assert(t, logDir == "test_log")
    51  
    52  	os.Unsetenv(EnvLogDir)
    53  	logDir = GetEnvLogDir()
    54  	test.Assert(t, logDir == "")
    55  }
    56  
    57  func TestGetLogDir(t *testing.T) {
    58  	os.Setenv(EnvLogDir, "test_log")
    59  	logDir := GetLogDir()
    60  	test.Assert(t, logDir == "test_log")
    61  
    62  	os.Unsetenv(EnvLogDir)
    63  	logDir = GetLogDir()
    64  	test.Assert(t, logDir == DefaultLogDir)
    65  }