Exemplo n.º 1
0
func TestNoticeJobnet(t *testing.T) {

	err := config.Load(configFileName)
	if err != nil {
		t.Fatal(err)
	}

	server := httptest.NewServer(setupHandler())
	defer server.Close()

	cacheDir := filepath.Join(os.TempDir(), "gocuto")
	os.MkdirAll(cacheDir, 0777)
	cacheFile := filepath.Join(cacheDir, "testjobnet.json")
	f, err := os.Create(cacheFile)
	if err != nil {
		t.Fatalf("File create error: %s", err)
	}
	flow := `{
    "flow":"job1->job2->[job3,job4,job5->job6]->job7",
    "jobs":[
		{"name":"job1","path":"s3dladapter","param":"-b $WAPARAM1 -f $WAPARAM2"},
        {"name":"job2","node":"123.45.67.89","port":1234},
        {"name":"job7","env":"RESULT=$WAPARAM3"}
    ]
}`
	f.WriteString(flow)
	f.Close()
	defer os.Remove(cacheFile)

	form := make(url.Values)
	form.Set("jobnetwork", testJobnetName)
	form.Set("param1", "bucket1")
	form.Set("param2", "testdata")

	output := testPostFormMessages(t, server.URL+"/notice", form)
	if !strings.Contains(output, testJobnetName) {
		t.Errorf("output => %v, want contains(%v)", output, testJobnetName)
	}
}
Exemplo n.º 2
0
func main() {
	args := fetchArgs()
	if args.configPath == "" {
		args.configPath = defaultConfig
	}

	if err := config.Load(args.configPath); err != nil {
		fmt.Println("Could not load config:", err)
		return
	}

	if err := log.Init(); err != nil {
		fmt.Println("Could not initialize logger:", err)
		return
	}

	listenHost := fmt.Sprintf(":%d", config.Server.ListenPort)
	if err := http.ListenAndServe(listenHost, setupHandler()); err != nil {
		fmt.Println("Could not start to listen:", err)
		return
	}
}