示例#1
0
func TestNewWithUserConfigFileWithErrors(t *testing.T) {
	util.WriteStringToFile(string(yamlConfig1), usrRexRayFile)
	defer os.RemoveAll(usrRexRayFile)

	os.Chmod(usrRexRayFile, 0000)
	New()
}
示例#2
0
func TestCopy(t *testing.T) {
	newPrefixDir("TestCopy", t)

	etcRexRayCfg := util.EtcFilePath("config.yml")
	t.Logf("etcRexRayCfg=%s", etcRexRayCfg)
	util.WriteStringToFile(string(yamlConfig1), etcRexRayCfg)

	c := New()

	assertLogLevel(t, c, "error")
	assertStorageDrivers(t, c)
	assertOsDrivers1(t, c)

	cc, _ := c.Copy()

	assertLogLevel(t, cc, "error")
	assertStorageDrivers(t, cc)
	assertOsDrivers1(t, cc)

	cJSON, _ := c.ToJSON()
	ccJSON, _ := cc.ToJSON()

	cMap := map[string]interface{}{}
	ccMap := map[string]interface{}{}
	json.Unmarshal([]byte(cJSON), cMap)
	json.Unmarshal([]byte(ccJSON), ccJSON)

	if !reflect.DeepEqual(cMap, ccMap) {
		t.Fail()
	}
}
示例#3
0
func TestNew(t *testing.T) {

	usrRexRayDir := fmt.Sprintf("%s/.rexray", util.HomeDir())
	os.MkdirAll(usrRexRayDir, 0755)
	usrRexRayFile := fmt.Sprintf("%s/%s.%s", usrRexRayDir, "config", "yml")
	usrRexRayFileBak := fmt.Sprintf("%s.bak", usrRexRayFile)

	os.Remove(usrRexRayFileBak)
	os.Rename(usrRexRayFile, usrRexRayFileBak)
	defer func() {
		os.Remove(usrRexRayFile)
		os.Rename(usrRexRayFileBak, usrRexRayFile)
	}()

	util.WriteStringToFile(string(yamlConfig1), usrRexRayFile)

	c := New()

	assertLogLevel(t, c, "error")
	assertStorageDrivers(t, c)
	assertOsDrivers1(t, c)

	if err := c.ReadConfig(bytes.NewReader(yamlConfig2)); err != nil {
		t.Fatal(err)
	}

	assertLogLevel(t, c, "debug")
	assertStorageDrivers(t, c)
	assertOsDrivers2(t, c)
}
示例#4
0
func TestNewWithGlobalConfigFileWithErrors(t *testing.T) {
	newPrefixDir("TestNewWithGlobalConfigFileWithErrors", t)

	etcRexRayCfg := util.EtcFilePath("config.yml")
	t.Logf("etcRexRayCfg=%s", etcRexRayCfg)
	util.WriteStringToFile(string(yamlConfig1), etcRexRayCfg)

	os.Chmod(etcRexRayCfg, 0000)
	New()
}
示例#5
0
func TestNewWithUserConfigFile(t *testing.T) {
	util.WriteStringToFile(string(yamlConfig1), usrRexRayFile)
	defer os.RemoveAll(usrRexRayFile)

	c := New()

	assertLogLevel(t, c, "error")
	assertStorageDrivers(t, c)
	assertOsDrivers1(t, c)

	if err := c.ReadConfig(bytes.NewReader(yamlConfig2)); err != nil {
		t.Fatal(err)
	}

	assertLogLevel(t, c, "debug")
	assertStorageDrivers(t, c)
	assertOsDrivers2(t, c)
}
示例#6
0
func TestNewWithGlobalConfigFile(t *testing.T) {
	newPrefixDir("TestNewWithGlobalConfigFile", t)

	etcRexRayCfg := util.EtcFilePath("config.yml")
	t.Logf("etcRexRayCfg=%s", etcRexRayCfg)
	util.WriteStringToFile(string(yamlConfig1), etcRexRayCfg)

	c := New()

	assertLogLevel(t, c, "error")
	assertStorageDrivers(t, c)
	assertOsDrivers1(t, c)

	if err := c.ReadConfig(bytes.NewReader(yamlConfig2)); err != nil {
		t.Fatal(err)
	}

	assertLogLevel(t, c, "debug")
	assertStorageDrivers(t, c)
	assertOsDrivers2(t, c)
}
示例#7
0
func TestCopy(t *testing.T) {
	newPrefixDir("TestCopy", t)
	wipeEnv()
	Register(testRegistration())

	etcRexRayCfg := util.EtcFilePath("config.yml")
	t.Logf("etcRexRayCfg=%s", etcRexRayCfg)
	util.WriteStringToFile(string(yamlConfig1), etcRexRayCfg)

	c := New()

	assertString(t, c, "logLevel", "error")
	assertStorageDrivers(t, c)
	assertOsDrivers1(t, c)

	cc, _ := c.Copy()

	assertString(t, cc, "logLevel", "error")
	assertStorageDrivers(t, cc)
	assertOsDrivers1(t, cc)

	cJSON, _ := c.ToJSON()
	ccJSON, _ := cc.ToJSON()

	cMap := map[string]interface{}{}
	ccMap := map[string]interface{}{}

	if err := json.Unmarshal([]byte(cJSON), &cMap); err != nil {
		t.Fatal(err)
	}
	if err := json.Unmarshal([]byte(ccJSON), &ccMap); err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(cMap, ccMap) {
		t.Fail()
	}
}