naming_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package goSam
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func TestClientLookupInvalid(t *testing.T) {
  7. var err error
  8. setup(t)
  9. defer teardown(t)
  10. addr, err := client.Lookup(`!(@#)`)
  11. if addr != "" || err == nil {
  12. t.Error("client.Lookup() should throw an error.")
  13. }
  14. repErr, ok := err.(ReplyError)
  15. if !ok {
  16. t.Fatalf("client.Lookup() should return a ReplyError")
  17. }
  18. if repErr.Result != ResultInvalidKey {
  19. t.Errorf("client.Lookup() should throw an ResultKeyNotFound error.\nGot:%+v\n", repErr)
  20. }
  21. }
  22. func ExampleClient_Lookup() {
  23. client, err := NewDefaultClient()
  24. if err != nil {
  25. fmt.Printf("NewDefaultClient() should not throw an error.\n%s\n", err)
  26. return
  27. }
  28. addr, err := client.Lookup("zzz.i2p")
  29. if err != nil {
  30. fmt.Printf("client.Lookup() should not throw an error.\n%s\n", err)
  31. return
  32. }
  33. fmt.Println("Address of zzz.i2p:")
  34. // Addresses change all the time
  35. fmt.Println(addr)
  36. // Output:
  37. //Address of zzz.i2p:
  38. //GKapJ8koUcBj~jmQzHsTYxDg2tpfWj0xjQTzd8BhfC9c3OS5fwPBNajgF-eOD6eCjFTqTlorlh7Hnd8kXj1qblUGXT-tDoR9~YV8dmXl51cJn9MVTRrEqRWSJVXbUUz9t5Po6Xa247Vr0sJn27R4KoKP8QVj1GuH6dB3b6wTPbOamC3dkO18vkQkfZWUdRMDXk0d8AdjB0E0864nOT~J9Fpnd2pQE5uoFT6P0DqtQR2jsFvf9ME61aqLvKPPWpkgdn4z6Zkm-NJOcDz2Nv8Si7hli94E9SghMYRsdjU-knObKvxiagn84FIwcOpepxuG~kFXdD5NfsH0v6Uri3usE3uSzpWS0EHmrlfoLr5uGGd9ZHwwCIcgfOATaPRMUEQxiK9q48PS0V3EXXO4-YLT0vIfk4xO~XqZpn8~PW1kFe2mQMHd7oO89yCk-3yizRG3UyFtI7-mO~eCI6-m1spYoigStgoupnC3G85gJkqEjMm49gUjbhfWKWI-6NwTj0ZnAAAA
  39. }