github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmn/tests/config_test.go (about)

     1  // Package test provides tests for common low-level types and utilities for all aistore projects
     2  /*
     3   * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package tests_test
     6  
     7  import (
     8  	"path/filepath"
     9  	"runtime"
    10  	"testing"
    11  
    12  	"github.com/NVIDIA/aistore/api/apc"
    13  	"github.com/NVIDIA/aistore/cmn"
    14  	"github.com/NVIDIA/aistore/cmn/jsp"
    15  	"github.com/NVIDIA/aistore/tools/tassert"
    16  )
    17  
    18  func TestConfigTestEnv(t *testing.T) {
    19  	oldConfig := cmn.GCO.Get()
    20  	defer func() {
    21  		cmn.GCO.BeginUpdate()
    22  		cmn.GCO.CommitUpdate(oldConfig)
    23  	}()
    24  
    25  	confPath := filepath.Join(thisFileDir(t), "configs", "config.json")
    26  	localConfPath := filepath.Join(thisFileDir(t), "configs", "confignet.json")
    27  	newConfig := cmn.Config{}
    28  	err := cmn.LoadConfig(confPath, localConfPath, apc.Proxy, &newConfig)
    29  	tassert.CheckFatal(t, err)
    30  }
    31  
    32  func TestConfigFSPaths(t *testing.T) {
    33  	var (
    34  		oldConfig     = cmn.GCO.Get()
    35  		confPath      = filepath.Join(thisFileDir(t), "configs", "config.json")
    36  		localConfPath = filepath.Join(thisFileDir(t), "configs", "configmpaths.json")
    37  	)
    38  	defer func() {
    39  		cmn.GCO.BeginUpdate()
    40  		cmn.GCO.CommitUpdate(oldConfig)
    41  	}()
    42  
    43  	var localConf cmn.LocalConfig
    44  	_, err := jsp.LoadMeta(localConfPath, &localConf)
    45  	tassert.CheckFatal(t, err)
    46  	newConfig := cmn.Config{}
    47  	err = cmn.LoadConfig(confPath, localConfPath, apc.Target, &newConfig)
    48  	tassert.CheckFatal(t, err)
    49  
    50  	mpaths := localConf.FSP.Paths
    51  	tassert.Fatalf(t, len(newConfig.FSP.Paths) == len(mpaths), "mountpath count %v != %v", len(newConfig.FSP.Paths), len(mpaths))
    52  	for p := range mpaths {
    53  		tassert.Fatalf(t, newConfig.FSP.Paths.Contains(p), "%q not in config FSP", p)
    54  	}
    55  }
    56  
    57  func thisFileDir(t *testing.T) string {
    58  	_, filename, _, ok := runtime.Caller(1)
    59  	tassert.Fatalf(t, ok, "Taking path of a file failed")
    60  	return filepath.Dir(filename)
    61  }
    62  
    63  func TestValidateMpath(t *testing.T) {
    64  	mpaths := []string{
    65  		"tmp", // not absolute path
    66  		"/",   // root
    67  	}
    68  	for _, mpath := range mpaths {
    69  		_, err := cmn.ValidateMpath(mpath)
    70  		if err == nil {
    71  			t.Errorf("validation of invalid mountpath: %q succeeded", mpath)
    72  		}
    73  	}
    74  }