func TestRepeatReadData(t *testing.T) { fmt.Println("\n\n>>>>>>>>>>>>>>>>>>> TestRepeatReadData <<<<<<<<<<<<<<<<<<<<<<<<<<") if err := data.Init("../data.json"); err == nil { t.Errorf("Duplicate calls to data.Init() should have resulted in a warning") } fmt.Println(" (Should have just received a WARN error 'Duplicate calls...')") }
func TestReadDataInvalidJSON(t *testing.T) { fmt.Println("\n\n>>>>>>>>>>>>>>>>>>> TestReadDataInvalidJSON <<<<<<<<<<<<<<<<<<<<<<<<<<") // Load Data if err := data.Init("tests/data_faulty.json"); err == nil { t.Errorf("Attempting to load a faulty file should have caused an error: %q", err) } fmt.Println(" (Should have just received a CRIT error 'Invalid JSON...')") }
func TestReadDataInvalidPath(t *testing.T) { fmt.Println("\n>>>>>>>>>>>>>>>>>>> TestReadDataInvalidPath <<<<<<<<<<<<<<<<<<<<<<<<<<") // Load Data if err := data.Init("../dataxxx.json"); err == nil { t.Errorf("Attempting to load an invalid file should have caused an error: %q", err) } fmt.Println(" (Should have just received a CRIT error 'Failed to open...')") }
func TestReadData(t *testing.T) { fmt.Println("\n\n>>>>>>>>>>>>>>>>>>> TestReadData <<<<<<<<<<<<<<<<<<<<<<<<<<") // Load Data if err := data.Init("../data.json"); err != nil { t.Errorf("Error %q occurred when loading the data.", err) } fmt.Printf("%v", data.DisplayReports()) }
func init() { if err := config.Init("../config.json"); err != nil { fmt.Printf("Error loading config file: %s\n", err) } if err := data.Init("../data.json"); err != nil { fmt.Printf("Error loading config file: %s\n", err) } }
func init() { var port int64 flag.BoolVar(&Debug, "debug", false, "Activate debug prints to the console. Active if either this or the value in 'config.json' are set.") flag.Int64Var(&port, "port", 0, "Port. If set, this flag will override the value in 'config.json'.") flag.Parse() logs.Init(Debug) if err := config.Init("config.json", port); err != nil { log.Error("Error loading config file: %s\n", err) } if err := data.Init("data.json"); err != nil { log.Error("Error loading config file: %s\n", err) } log.Info("Running on port: %d", config.Port()) go SignalHandler(make(chan os.Signal, 1)) fmt.Println("Press Ctrl-C to shutdown...") }