func main() { flags.Parse(os.Args[1:]) // Override config file by the CONFIG env var, if specified. if os.Getenv("CONFIG") != "" { *confFile = os.Getenv("CONFIG") } // Read Config. conf, err := config.New(*confFile) if err != nil { log.Fatal(err) } // Run QMD. app, err := qmd.New(conf) if err != nil { log.Fatal(err) } go app.WatchScripts() go app.StartWorkers() go app.ListenQueue() graceful.AddSignal(syscall.SIGINT, syscall.SIGTERM) graceful.PreHook(app.Close) // Start the API server. log.Printf("Starting QMD API at %s\n", conf.Bind) err = graceful.ListenAndServe(conf.Bind, rest.Routes(app)) if err != nil { log.Fatal(err) } graceful.Wait() }
func TestPing(t *testing.T) { conf, _ := config.New("../etc/qmd.conf.sample") qmd := &qmd.Qmd{ Config: conf, DB: nil, Queue: nil, ClosingListenQueue: make(chan struct{}), ClosingWorkers: make(chan struct{}), } ts := httptest.NewServer(rest.Routes(qmd)) defer ts.Close() res, err := http.Get(ts.URL + "/ping") if err != nil { t.Error(err) } dot, err := ioutil.ReadAll(res.Body) if err != nil { t.Error(err) } defer res.Body.Close() if res.StatusCode != 200 { t.Error("unexpected response status code") } if string(dot) != "." { t.Error("unexpected response body") } }