Esempio n. 1
0
func TestMain(m *testing.M) {
	flag.Parse()
	kiteURL := testutil.GenKiteURL()

	sshkeys = kite.New("sshkeys", "0.0.1")
	sshkeys.Config.DisableAuthentication = true
	sshkeys.Config.Port = kiteURL.Port()
	sshkeys.HandleFunc("list", List)
	sshkeys.HandleFunc("add", Add)
	sshkeys.HandleFunc("delete", Delete)

	go sshkeys.Run()
	<-sshkeys.ServerReadyNotify()
	defer sshkeys.Close()

	u, err := user.Current()
	if err != nil {
		panic(err)
	}

	remoteKite := kite.New("remote", "0.0.1")
	remoteKite.Config.Username = u.Username
	remote = remoteKite.NewClient(kiteURL.String())
	err = remote.Dial()
	if err != nil {
		log.Fatalf("err")
	}
	defer remoteKite.Close()

	os.Exit(m.Run())
}
Esempio n. 2
0
func TestMain(m *testing.M) {
	flag.Parse()

	// NOTE(rjeczalik): copy testdata/testfile1.txt so after test execution
	// the file is not modified.
	if err := testutil.FileCopy("testdata/testfile1.txt", testfile1); err != nil {
		panic(err)
	}

	kiteURL := testutil.GenKiteURL()

	fs = kite.New("fs", "0.0.1")
	fs.Config.DisableAuthentication = true
	fs.Config.Port = kiteURL.Port()
	fs.HandleFunc("readDirectory", ReadDirectory)
	fs.HandleFunc("glob", Glob)
	fs.HandleFunc("readFile", ReadFile)
	fs.HandleFunc("writeFile", WriteFile)
	fs.HandleFunc("uniquePath", UniquePath)
	fs.HandleFunc("getInfo", GetInfo)
	fs.HandleFunc("setPermissions", SetPermissions)
	fs.HandleFunc("remove", Remove)
	fs.HandleFunc("rename", Rename)
	fs.HandleFunc("createDirectory", CreateDirectory)
	fs.HandleFunc("move", Move)
	fs.HandleFunc("copy", Copy)
	fs.HandleFunc("getDiskInfo", GetDiskInfo)

	go fs.Run()
	<-fs.ServerReadyNotify()
	defer fs.Close()

	remoteKite := kite.New("remote", "0.0.1")
	remoteKite.Config.Username = "******"
	remote = remoteKite.NewClient(kiteURL.String())
	err := remote.Dial()
	if err != nil {
		log.Fatalf("err")
	}
	defer remoteKite.Close()

	remoteKite2 := kite.New("remote2", "0.0.1")
	remoteKite2.Config.Username = "******"
	remote2 = remoteKite2.NewClient(kiteURL.String())
	err = remote2.Dial()
	if err != nil {
		log.Fatalf("err")
	}
	defer remoteKite2.Close()

	os.Exit(m.Run())
}
Esempio n. 3
0
func TestMain(m *testing.M) {
	flag.Parse()

	kiteURL := testutil.GenKiteURL()

	d = kite.New("docker", "0.0.1")
	d.Config.DisableAuthentication = true
	d.Config.Port = kiteURL.Port()
	d.Config.Username = "******"

	dockerHost := os.Getenv("DOCKER_HOST")
	if dockerHost == "" {
		dockerHost = "tcp://192.168.59.103:2376" // darwin, boot2docker
	}

	dockerCertPath := os.Getenv("DOCKER_CERT_PATH")
	if dockerCertPath == "" {
		panic("please set DOCKER_CERT_PATH")
	}

	certFile := dockerCertPath + "/cert.pem"
	keyFile := dockerCertPath + "/key.pem"
	caFile := dockerCertPath + "/ca.pem"

	client, _ := dockerclient.NewVersionnedTLSClient(dockerHost, certFile, keyFile, caFile, "1.16")
	dock := &Docker{
		client: client,
		log:    d.Log,
	}

	d.HandleFunc("create", dock.Create)
	d.HandleFunc("start", dock.Start)
	d.HandleFunc("connect", dock.Connect) // TODO: doesn't work inside our tests, look at it
	d.HandleFunc("stop", dock.Stop)
	d.HandleFunc("list", dock.List)
	d.HandleFunc("remove", dock.RemoveContainer)

	go d.Run()
	<-d.ServerReadyNotify()
	defer d.Close()

	remote = d.NewClient(kiteURL.String())
	err := remote.Dial()
	if err != nil {
		log.Fatalf("err")
	}
	defer remote.Close()

	os.Exit(m.Run())
}
Esempio n. 4
0
func TestTerminal(t *testing.T) {
	kiteURL := testutil.GenKiteURL()

	screen, err := exec.LookPath("screen")
	if err != nil {
		t.Fatalf("unable to find screen: %s", err)
	}

	terminal := kite.New("terminal", "0.0.1")
	terminal.Config.DisableConcurrency = true
	terminal.Config.DisableAuthentication = true
	terminal.Config.Port = kiteURL.Port()

	termInstance := New(testLog, screen)
	terminal.HandleFunc("connect", termInstance.Connect)

	go terminal.Run()
	<-terminal.ServerReadyNotify()
	defer terminal.Close()

	client := kite.New("client", "0.0.1")
	client.Config.DisableAuthentication = true
	client.Log = testLog

	remote := client.NewClient(kiteURL.String())
	err = remote.Dial()
	if err != nil {
		t.Fatal(err)
	}
	defer remote.Close()

	termClient := newTermHandler()

	result, err := remote.Tell("connect", struct {
		Remote       *termHandler
		Session      string
		SizeX, SizeY int
		Mode         string
	}{
		Remote: termClient,
		SizeX:  80,
		SizeY:  24,
		Mode:   "create",
	})
	if err != nil {
		t.Error(err)
		return
	}

	var term *remoteTerm
	err = result.Unmarshal(&term)
	if err != nil {
		t.Error(err.Error())
		return
	}

	// Two commands are run to make sure that the order of the keys are preserved.
	// If not, sometimes inputs are mixed in a way that is non-deterministic.
	err = term.Input.Call(`say kite`)
	if err != nil {
		t.Fatal(err)
	}

	// time.Sleep(100 * time.Millisecond)
	err = term.ControlSequence.Call("\r")
	if err != nil {
		t.Fatal(err)
	}

	// time.Sleep(100 * time.Millisecond)

	err = term.Input.Call(`python -c "print 123455+1"`)
	if err != nil {
		t.Fatal(err)
	}

	// time.Sleep(100 * time.Millisecond)
	err = term.ControlSequence.Call("\r")
	if err != nil {
		t.Fatal(err)
	}

	fullOutput := ""
	for {
		select {
		case output := <-termClient.output:
			// fmt.Printf("Received output from channel: %+v\n", output)
			fullOutput += output
			if strings.Contains(fullOutput, "123456") { // magic number
				return
			}
		case <-time.After(2 * time.Second):
			fmt.Println(fullOutput)
			t.Error("Timeout")
			return
		}
	}
}