func TestReceiver(t *testing.T) { s := smpptest.NewServer() defer s.Close() rc := make(chan pdu.Body) r := &Receiver{ Addr: s.Addr(), User: smpptest.DefaultUser, Passwd: smpptest.DefaultPasswd, Handler: func(p pdu.Body) { rc <- p }, } defer r.Close() conn := <-r.Bind() switch conn.Status() { case Connected: default: t.Fatal(conn.Error()) } // trigger inbound message from server p := pdu.NewGenericNACK() s.BroadcastMessage(p) // check response. select { case m := <-rc: want, have := *p.Header(), *m.Header() if want != have { t.Fatalf("unexpected PDU: want %#v, have %#v", want, have) } case <-time.After(time.Second): t.Fatal("timeout waiting for server to echo") } }
func TestConn(t *testing.T) { s := smpptest.NewServer() defer s.Close() c, err := Dial(s.Addr(), nil) if err != nil { t.Fatal(err) } defer c.Close() p := pdu.NewBindTransmitter() f := p.Fields() f.Set(pdufield.SystemID, smpptest.DefaultUser) f.Set(pdufield.Password, smpptest.DefaultPasswd) f.Set(pdufield.InterfaceVersion, 0x34) if err = c.Write(p); err != nil { t.Fatal(err) } if _, err = c.Read(); err != nil { t.Fatal(err) } }