mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Covered tests in config file
This commit is contained in:
committed by
Dan Christian Bogos
parent
461a7003e5
commit
2175c7f2bb
@@ -1403,6 +1403,7 @@ func (cfg *CGRConfig) reloadSections(sections ...string) (err error) {
|
||||
switch section {
|
||||
default:
|
||||
return fmt.Errorf("Invalid section: <%s>", section)
|
||||
case ConfigSJson:
|
||||
case GENERAL_JSN: // nothing to reload
|
||||
case RPCConnsJsonName: // nothing to reload
|
||||
cfg.rldChans[RPCConnsJsonName] <- struct{}{}
|
||||
@@ -1541,7 +1542,7 @@ func (cfg *CGRConfig) V1ReloadConfigFromPath(args *ConfigReloadWithOpts, reply *
|
||||
}
|
||||
// lock all sections
|
||||
cfg.rLockSections()
|
||||
|
||||
fmt.Println(cfg.ralsCfg.Enabled, 12)
|
||||
err = cfg.checkConfigSanity()
|
||||
|
||||
cfg.rUnlockSections() // unlock before checking the error
|
||||
@@ -1689,16 +1690,13 @@ func (cfg *CGRConfig) V1ReloadConfig(args *ArgsReloadWithOpts, reply *string) (e
|
||||
for section := range args.Config {
|
||||
sections = append(sections, section)
|
||||
}
|
||||
|
||||
var b []byte
|
||||
if b, err = json.Marshal(args.Config); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = cfg.loadCfgFromJSONWithLocks(bytes.NewBuffer(b), sections); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// lock all sections
|
||||
cfg.rLockSections()
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -19,7 +19,6 @@ package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
@@ -294,6 +293,54 @@ func TestEnvReaderreplaceEnv(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleJSONErrorNil(t *testing.T) {
|
||||
os.Setenv("Test_VAR1", "5")
|
||||
os.Setenv("Test_VAR2", "aVeryLongEnviormentalVariable")
|
||||
envR := NewRjReaderFromBytes([]byte(`*env:Test_VAR1,/*comment*/ }*env:Test_VAR2"`))
|
||||
var expected error = nil
|
||||
if err := envR.replaceEnv(0); err != nil {
|
||||
t.Error(err)
|
||||
} else if newErr := envR.HandleJSONError(err); newErr != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, newErr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleJSONErrorInvalidUTF8(t *testing.T) {
|
||||
rjr := NewRjReaderFromBytes([]byte("{}"))
|
||||
expectedErr := new(json.InvalidUTF8Error)
|
||||
if err := rjr.HandleJSONError(expectedErr); err == nil || err.Error() != expectedErr.Error() {
|
||||
t.Errorf("Expected %+v, received %+v", expectedErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleJSONErrorInvalidUnmarshalError(t *testing.T) {
|
||||
rjr := NewRjReaderFromBytes([]byte("{}"))
|
||||
err := json.NewDecoder(rjr).Decode(nil)
|
||||
if err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = rjr.HandleJSONError(err)
|
||||
expectedErr := &json.InvalidUnmarshalError{Type: reflect.TypeOf(nil)}
|
||||
if err == nil || err.Error() != expectedErr.Error() {
|
||||
t.Errorf("Expected %+v, received %+v", expectedErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleJSONErrorUnmarshalTypeError(t *testing.T) {
|
||||
rjr := NewRjReaderFromBytes([]byte("{}"))
|
||||
err := &json.UnmarshalTypeError{
|
||||
Offset: 0,
|
||||
Value: "2",
|
||||
Type: reflect.TypeOf(""),
|
||||
Struct: "configs",
|
||||
Field: "field",
|
||||
}
|
||||
expMessage := fmt.Sprintf("%s at line 0 around position 0", err.Error())
|
||||
if err := rjr.HandleJSONError(err); err == nil || err.Error() != expMessage {
|
||||
t.Errorf("Expected %+v, received %+v", expMessage, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnvReadercheckMeta(t *testing.T) {
|
||||
envR := NewRjReaderFromBytes([]byte("*env:Var"))
|
||||
envR.indx = 1
|
||||
|
||||
Reference in New Issue
Block a user