diff --git a/config/config_defaults.go b/config/config_defaults.go
index b33379be0..5c4e8adbd 100755
--- a/config/config_defaults.go
+++ b/config/config_defaults.go
@@ -18,13 +18,6 @@ along with this program. If not, see
package config
-import (
- "fmt"
- "os"
- "path"
- "strings"
-)
-
const CGRATES_CFG_JSON = `
{
@@ -790,24 +783,3 @@ const CGRATES_CFG_JSON = `
},
}`
-
-func writeDefaultCofig() error {
- f, err := os.OpenFile(path.Join("/usr", "share", "cgrates", "conf", "cgrates", "cgrates.json"), os.O_WRONLY|os.O_CREATE, 0755)
- if err != nil {
- return err
- }
- defer f.Close()
- rows := strings.Split(CGRATES_CFG_JSON, "\n")[1:] // remove first empty row
- for i, row := range rows {
- if i == 0 || i == len(rows)-1 { // do not comment first and last row
- fmt.Fprintln(f, row)
- continue
- }
- if withoutSpace := strings.TrimSpace(row); len(withoutSpace) == 0 || strings.HasPrefix(row, "//") { // do not comment empty rows and alerady commented ones
- fmt.Fprintln(f, row)
- continue
- }
- fmt.Fprintf(f, "// %s\n", row)
- }
- return nil
-}
diff --git a/config/config_defaults_test.go b/config/config_defaults_test.go
index 7c098e072..e72b5b0e2 100644
--- a/config/config_defaults_test.go
+++ b/config/config_defaults_test.go
@@ -1,4 +1,4 @@
-// +build integration
+// +build generate
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
@@ -20,11 +20,37 @@ along with this program. If not, see
package config
import (
+ "fmt"
+ "os"
+ "path"
+ "strings"
"testing"
)
+func writeDefaultCofig(fileName string) error {
+ f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE, 0755)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+ rows := strings.Split(CGRATES_CFG_JSON, "\n")[1:] // remove first empty row
+ for i, row := range rows {
+ if i == 0 || i == len(rows)-1 { // do not comment first and last row
+ fmt.Fprintln(f, row)
+ continue
+ }
+ if withoutSpace := strings.TrimSpace(row); len(withoutSpace) == 0 || strings.HasPrefix(row, "//") { // do not comment empty rows and alerady commented ones
+ fmt.Fprintln(f, row)
+ continue
+ }
+ fmt.Fprintf(f, "// %s\n", row)
+ }
+ return nil
+}
+
+// used only to generate the commented configuration file
func TestWriteDefaultCofig(t *testing.T) {
- if err := writeDefaultCofig(); err != nil {
+ if err := writeDefaultCofig(path.Join("/usr", "share", "cgrates", "conf", "cgrates", "cgrates.json")); err != nil {
t.Fatal(err)
}
}
diff --git a/data/scripts/generate_config.sh b/data/scripts/generate_config.sh
new file mode 100755
index 000000000..18a6e9755
--- /dev/null
+++ b/data/scripts/generate_config.sh
@@ -0,0 +1,3 @@
+#! /usr/bin/env sh
+
+go test github.com/cgrates/cgrates/config -tags=generate | echo "Generating configuration file ..."