2014-02-09 18:40:51 +01:00
|
|
|
package goSam
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestClientLookupInvalid(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
|
2014-10-31 10:52:33 +01:00
|
|
|
setup(t)
|
|
|
|
defer teardown(t)
|
2014-02-09 18:40:51 +01:00
|
|
|
|
2018-08-21 16:20:04 +02:00
|
|
|
addr, err := client.Lookup(`!(@#)`)
|
2014-02-09 18:40:51 +01:00
|
|
|
if addr != "" || err == nil {
|
|
|
|
t.Error("client.Lookup() should throw an error.")
|
|
|
|
}
|
|
|
|
|
|
|
|
repErr, ok := err.(ReplyError)
|
2014-10-31 10:52:33 +01:00
|
|
|
if !ok {
|
|
|
|
t.Fatalf("client.Lookup() should return a ReplyError")
|
|
|
|
}
|
2018-08-21 16:20:04 +02:00
|
|
|
if repErr.Result != ResultInvalidKey {
|
2014-10-31 10:52:33 +01:00
|
|
|
t.Errorf("client.Lookup() should throw an ResultKeyNotFound error.\nGot:%+v\n", repErr)
|
2014-02-09 18:40:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleClient_Lookup() {
|
2014-10-31 10:52:33 +01:00
|
|
|
client, err := NewDefaultClient()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("NewDefaultClient() should not throw an error.\n%s\n", err)
|
|
|
|
return
|
|
|
|
}
|
2014-02-09 18:40:51 +01:00
|
|
|
|
2018-08-21 16:20:04 +02:00
|
|
|
addr, err := client.Lookup("zzz.i2p")
|
2014-02-09 18:40:51 +01:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("client.Lookup() should not throw an error.\n%s\n", err)
|
2014-10-31 10:52:33 +01:00
|
|
|
return
|
2014-02-09 18:40:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Address of zzz.i2p:")
|
|
|
|
// Addresses change all the time
|
2018-08-21 16:20:04 +02:00
|
|
|
fmt.Println(addr)
|
2014-02-09 18:40:51 +01:00
|
|
|
|
|
|
|
// Output:
|
|
|
|
//Address of zzz.i2p:
|
2018-08-21 16:20:04 +02:00
|
|
|
//GKapJ8koUcBj~jmQzHsTYxDg2tpfWj0xjQTzd8BhfC9c3OS5fwPBNajgF-eOD6eCjFTqTlorlh7Hnd8kXj1qblUGXT-tDoR9~YV8dmXl51cJn9MVTRrEqRWSJVXbUUz9t5Po6Xa247Vr0sJn27R4KoKP8QVj1GuH6dB3b6wTPbOamC3dkO18vkQkfZWUdRMDXk0d8AdjB0E0864nOT~J9Fpnd2pQE5uoFT6P0DqtQR2jsFvf9ME61aqLvKPPWpkgdn4z6Zkm-NJOcDz2Nv8Si7hli94E9SghMYRsdjU-knObKvxiagn84FIwcOpepxuG~kFXdD5NfsH0v6Uri3usE3uSzpWS0EHmrlfoLr5uGGd9ZHwwCIcgfOATaPRMUEQxiK9q48PS0V3EXXO4-YLT0vIfk4xO~XqZpn8~PW1kFe2mQMHd7oO89yCk-3yizRG3UyFtI7-mO~eCI6-m1spYoigStgoupnC3G85gJkqEjMm49gUjbhfWKWI-6NwTj0ZnAAAA
|
2014-02-09 18:40:51 +01:00
|
|
|
}
|