Files
cgrates/config/config_defaults_test.go
2019-06-21 15:35:01 +02:00

57 lines
1.6 KiB
Go

// +build generate
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
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(path.Join("/usr", "share", "cgrates", "conf", "cgrates", "cgrates.json")); err != nil {
t.Fatal(err)
}
}