예제 #1
0
func TestEcho(t *testing.T) {
	flag.Parse()

	tests := []string{
		"this is a test",
		"woo, more tests\n",
		"",
	}

	go main()

	echo, err := echoservice.DialEchoService(*server)
	if err != nil {
		t.Fatalf("dial: %s", err)
	}

	for _, test := range tests {
		in := &echoservice.Payload{Message: &test}
		out := &echoservice.Payload{}
		if err := echo.Echo(in, out); err != nil {
			t.Fatalf("echo: %s", err)
		}
		if out.Message == nil {
			t.Fatalf("echo: no message returned")
		}
		if got, want := *out.Message, test; got != want {
			t.Errorf("echo(%q) = %q, want %q", test, got, want)
		}
	}
}
예제 #2
0
func main() {
	echo, err := echoservice.DialEchoService(*server)
	if err != nil {
		log.Fatalf("dial: %s", err)
	}

	lines := bufio.NewReader(os.Stdin)
	for {
		os.Stdout.WriteString("> ")
		line, err := lines.ReadString('\n')
		if err != nil {
			if err == io.EOF {
				return
			}
			log.Fatalf("read: %s", err)
		}

		in := &echoservice.Payload{Message: &line}
		out := &echoservice.Payload{}
		if err := echo.Echo(in, out); err != nil {
			log.Fatalf("echo: %s", err)
		}
		if out.Message == nil {
			log.Fatalf("echo: no message returned")
		}
		os.Stdout.WriteString("< ")
		os.Stdout.WriteString(*out.Message)
	}
}