Пример #1
0
func TestMain(m *testing.M) {
	// open database in memory for testing
	mailbox.OpenMemDB()
	err := mailbox.CreateDB()
	if err != nil {
		panic(err)
	}

	// create a default mailbox to use
	mb, err = mailbox.Create("mb")
	if err != nil {
		panic(err)
	}

	// create an access token for the default mailbox
	accessKey = &mailbox.AccessKey{FullAccess: true}
	accessKey.Create()

	// create a postmasterClient
	pmClient = client.Client{
		Host:          "localhost:4111",
		Mailbox:       mb.Id,
		AccessKeyName: accessKey.Name,
		AccessKey:     accessKey.Secret,
	}

	// Start up a test server to use
	server.EnableLongPolling = false
	go server.Start(":4111")
	retCode := m.Run()

	// cleanup
	mailbox.CloseDB()
	os.Exit(retCode)
}
Пример #2
0
func TestMain(m *testing.M) {
	mailbox.OpenMemDB()
	mailbox.CreateDB()

	retCode := m.Run()

	mailbox.CloseDB()
	os.Exit(retCode)
}
Пример #3
0
func TestMain(m *testing.M) {
	mailbox.OpenMemDB()
	mailbox.CreateDB()

	server.EnableLongPolling = false
	server.ThrottleDelay = 0

	go server.Start(":4111")

	retCode := m.Run()

	mailbox.CloseDB()
	os.Exit(retCode)
}
Пример #4
0
func TestAgentCommand(t *testing.T) {
	mailbox.OpenMemDB()
	key := mailbox.AccessKey{FullAccess: true}
	key.Create()
	agent.Address = ":6112"
	agent.AccessKey = key.Secret
	go agent.Start()
	engine.Agents["test"] = ":6112"
	engine.AgentAccessKey = key.Secret
	eng := engine.New()
	err := eng.Execute(`$agent("test", function() { console.log("test"); });`)
	if err != nil {
		t.Fatal(err)
	}
}
Пример #5
0
func TestDeploy(t *testing.T) {
	mailbox.OpenMemDB()
	mailbox.CreateDB()
	os.Create("test.js")
	file, err := os.OpenFile("test.js", os.O_APPEND|os.O_WRONLY, 0644)
	file.WriteString("console.log('test');")
	file.Close()

	mb, err := mailbox.Create("test.test")
	if err != nil {
		t.Fatal(err)
	}
	if err != nil {
		t.Fatal(err)
	}

	key := mailbox.AccessKey{FullAccess: true}
	err = key.Create()
	if err != nil {
		t.Fatal(err)
	}

	viper.Set("host", ":5112")
	viper.Set("mailbox", mb.Id)
	viper.Set("access_key", key.Secret)
	viper.Set("access_key_name", key.Name)
	viper.Set("show_requests", true)

	go serverCmd.Run(serverCmd, []string{})
	deployCmd.ParseFlags([]string{"-x"})
	deployCmd.Run(deployCmd, []string{"test.js", "test.test"})

	os.Remove("test.js")

	msg, err := mb.GetMessage()
	if err != nil {
		t.Fatal(err)
	}
	if msg == nil {
		t.Fatal("No message waiting")
	}
}
Пример #6
0
func TestAsset(t *testing.T) {

	mailbox.OpenMemDB()
	mailbox.CreateDB()

	mb, err := mailbox.Create("test.asset")
	if err != nil {
		t.Fatal(err)
	}
	if err != nil {
		t.Fatal(err)
	}

	key := mailbox.AccessKey{FullAccess: true}
	err = key.Create()
	if err != nil {
		t.Fatal(err)
	}

	viper.Set("host", ":5112")
	viper.Set("mailbox", mb.Id)
	viper.Set("access_key", key.Secret)
	viper.Set("access_key_name", key.Name)
	viper.Set("show_requests", true)
	client, err := ClientFromConfig()
	if err != nil {
		t.Fatal(err)
	}

	resp, err := client.CheckRemoteFile("324e63777cae0113d708633836c9cb18")
	if err != nil {
		t.Fatal(err)
	}

	if resp != false {
		t.Fatal("Check file came back true before upload.")
	}

	os.Create("test.js")
	file, err := os.OpenFile("test.js", os.O_APPEND|os.O_WRONLY, 0644)
	file.WriteString("console.log('test');")
	file.Close()

	go serverCmd.Run(serverCmd, []string{})
	deployCmd.ParseFlags([]string{"-x", "-a", "test.js"})
	deployCmd.Run(deployCmd, []string{"test.js", "test.asset"})

	defer os.Remove("test.js")

	resp, err = client.CheckRemoteFile("324e63777cae0113d708633836c9cb18")
	if err != nil {
		t.Fatal(err)
	}

	if resp != true {
		t.Fatal("File check came back false after upload")
	}

	fname, err := client.DownloadAsset("324e63777cae0113d708633836c9cb18")
	if err != nil {
		t.Fatal(err)
	}

	defer os.Remove(fname)

	fData, err := ioutil.ReadFile(fname)
	if err != nil {
		t.Fatal(err)
	}
	if string(fData) != "console.log('test');" {
		t.Fatal("File data is wrong")
	}
}