package apply import ( "strings" "testing" "github.com/novox/mesh-host/internal/store" ) // Defends novox/hq issue 104: a declaration is refused for the other mode than the node is in, // naming both and the act that changes it; a node no mode has been said to takes either. func TestADeclarationForTheOtherModeIsRefused(t *testing.T) { converged := parse(t, `{"declaration":1,"resources":[{"id":"a","type":"file","path":"/tmp/a","content":"x\n"}]}`) adopted := parse(t, `{"declaration":1,"adoption":{"taken":[]},"resources":[{"id":"a","type":"file","path":"/tmp/a","content":"x\n"}]}`) err := CheckMode(store.State{Mode: store.ModeAdopted}, converged) if err == nil || !strings.Contains(err.Error(), "this node is adopted; the declaration says converged") || !strings.Contains(err.Error(), "`converge`") { t.Errorf("a converged declaration on an adopted node: %v", err) } err = CheckMode(store.State{Mode: store.ModeConverged}, adopted) if err == nil || !strings.Contains(err.Error(), "this node is converged; the declaration says adopted") || !strings.Contains(err.Error(), "`adopt`") { t.Errorf("an adopted declaration on a converged node: %v", err) } if err := CheckMode(store.State{Mode: store.ModeAdopted}, adopted); err != nil { t.Errorf("the node's own mode was refused: %v", err) } if err := CheckMode(store.State{}, converged); err != nil { t.Errorf("a node in no mode yet refused a declaration: %v", err) } }