Commit fe52c88f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 2e9d1053
...@@ -41,6 +41,8 @@ import ( ...@@ -41,6 +41,8 @@ import (
// - shared memory or file, // - shared memory or file,
// - ... // - ...
type registry interface { type registry interface {
// XXX + network name?
// Announce announces host to registry. // Announce announces host to registry.
// //
// The host is named as hostname on lonet network and is listening for // The host is named as hostname on lonet network and is listening for
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package lonet package lonet
import ( import (
"context"
"io/ioutil" "io/ioutil"
"os" "os"
"testing" "testing"
...@@ -39,8 +40,38 @@ func TestRegistrySQLite(t *testing.T) { ...@@ -39,8 +40,38 @@ func TestRegistrySQLite(t *testing.T) {
r, err := openRegistrySQLite(dbpath) r, err := openRegistrySQLite(dbpath)
X(err) X(err)
// quert checks that result of Query(hostname) is as expect
//
// if expect is error - it checks that Query returns error with cause == expect.
// otherwise expect must be string and it will check that Query
// succeeds and returns osladdr == expect.
query := func(r *sqliteRegistry, hostname string, expect interface{}) {
// XXX ^^^ -> `r registry` (needs .Network() to get network name) ?
t.Helper()
osladdr, err := r.Query(context.Background(), hostname)
if cause, iserr := expect.(error); iserr {
// error expected
e, ok := err.(*registryError)
if !(ok && e.Err == cause && osladdr == "") {
t.Fatalf("%s: query %q:\nwant: \"\", %v\nhave: %q, %v",
r.uri, hostname, cause, osladdr, err)
}
} else {
// !error expected
laddr := expect.(string)
if !(osladdr == laddr && err == nil) {
t.Fatalf("%s: query %q:\nwant: %q, nil\nhave: %q, %v",
r.uri, hostname, laddr, osladdr, err)
}
}
}
ø := errNoHost
// r.Network() == ... // r.Network() == ...
// r.Query("α") == ø // r.Query("α") == ø
query(r, "α", ø)
// r.Announce("α", "alpha:1234") // r.Announce("α", "alpha:1234")
// r.Query("α") == "alpha:1234") // r.Query("α") == "alpha:1234")
// r.Query("β") == ø // r.Query("β") == ø
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment