Example #1
0
func TestConfig(t *testing.T) {
	conf := &config{42, 69.97543, "Hello World!"}

	testMessage(t, message.Types["config"], func(w io.Writer) error {
		return builder.SendConfig(w, conf)
	}, func(conn *message.Conn, t *testing.T) {
		rconf := &config{}
		err := handler.ReadConfig(conn, rconf)
		if err != nil {
			t.Fatal("Error while reading config:", err)
		}

		if conf.Int != rconf.Int {
			t.Fatal("Sent config item Int with value", conf.Int, "but received", rconf.Int)
		}
		if conf.Float != rconf.Float {
			t.Fatal("Sent config item Float with value", conf.Float, "but received", rconf.Float)
		}
		if conf.String != rconf.String {
			t.Fatal("Sent config item String with value", conf.String, "but received", rconf.String)
		}
	})
}
Example #2
0
			err := conn.Write(func(w io.Writer) error {
				return builder.SendExit(w, code)
			})
			if err != nil {
				return err
			}

			if err := conn.Close(); err != nil {
				return err
			}
		} else {
			log.Println("Sending config to client")
			conn.State = message.Accepted

			err := conn.Write(func(w io.Writer) error {
				return builder.SendConfig(w, ctx.Config)
			})
			if err != nil {
				return err
			}
		}

		return nil
	},
	message.Types["exit"]: func(ctx *message.Context, conn *message.Conn) error {
		code := ReadExit(conn)
		log.Println("Client disconnected with code:", code)

		if err := conn.Close(); err != nil {
			return err
		}