Files
mesh-catalog/modules/mesh-vault/cmd/mesh-vault/notyet_test.go
T

49 lines
2.1 KiB
Go

package main
import (
"errors"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/seal"
)
// Issue 928: an assignment the vault could not read (the controller was being pushed, "no responders") is not a
// refusal the client keeps for ten minutes: it is "not yet", the answer the client waits on and asks again.
func TestAnAssignmentThatCannotBeReadIsNotYetAndNotARefusal(t *testing.T) {
down := errors.New("nats: no responders available for request")
read := func(string) ([]byte, error) { return nil, down }
v := newVault(t, Declared{Read: read})
asker, _ := seal.GenerateKeyPair()
for _, name := range []string{"own/g14/claude-code/token", "provision/novox/gitea-read/g14/claude-code"} {
_, err := v.Get("provisioner.g14", name, asker.PublicKey)
if err == nil {
t.Fatalf("%s: answered while the assignment cannot be read and the vault holds nothing", name)
}
if !strings.Contains(err.Error(), "holds no secret named") || !strings.Contains(err.Error(), "no responders") {
t.Errorf("%s: the answer is %q, not the not-yet the client waits on, with the reason", name, err)
}
}
hs, _ := v.Store.Handed(10)
for _, h := range hs {
if h.Outcome == "refused" {
t.Errorf("a read error was recorded as a refusal: %+v", h)
}
}
}
// A pair row asked for while the consumer's assignment cannot be read is not yet either, and a row whose
// assignment reads as absent stays "not on".
func TestAPairRowWhoseAssignmentCannotBeReadIsNotYet(t *testing.T) {
down := errors.New("nats: no responders available for request")
parts := []string{"pair", "novox", "db", "g14", "claude-code"}
why := pairRowRefusal(func(string) ([]byte, error) { return nil, down }, "g14", parts)
if !strings.HasPrefix(why, notYetPrefix) || !strings.Contains(why, "no responders") {
t.Errorf("a read error answered %q, want a not-yet carrying the reason", why)
}
why = pairRowRefusal(func(string) ([]byte, error) { return nil, nil }, "g14", parts)
if strings.HasPrefix(why, notYetPrefix) || !strings.Contains(why, "is not on g14") {
t.Errorf("an absent assignment answered %q, want the refusal 'not on'", why)
}
}