Give a service's held state its own field and key, so main compiles again
#64/#65 and #66 each added Applied.Declared: a directory's declared owner and
mode (string) and a service's held state (*FoundUnit), both under the JSON key
"declared". The directory's is already on nodes, written by d28ca95, so it
keeps the name and key; the service's becomes DeclaredUnit, "declared_unit".
#66 never deployed, so no node holds a record under the new key.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// A directory used as found and a service's held state are two records that both say "declared"
|
||||
// (novox/hq issue 339, ADR 0269). The directory's was on nodes first, under the key "declared", and a
|
||||
// record a node already holds must keep reading back; the service's has a key of its own.
|
||||
func TestADirectorysDeclaredAndAUnitsDeclaredKeepTheirOwnKeys(t *testing.T) {
|
||||
onDisk := []byte(`{"id":"notes.data","type":"directory","as_found":true,"declared":"root, mode 755",` +
|
||||
`"declared_unit":{"unit":"a.timer","state":"stopped","boot":"disabled"}}`)
|
||||
var a Applied
|
||||
if err := json.Unmarshal(onDisk, &a); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a.Declared != "root, mode 755" {
|
||||
t.Errorf("the directory's declared owner and mode read back as %q", a.Declared)
|
||||
}
|
||||
if a.DeclaredUnit == nil || a.DeclaredUnit.State != "stopped" || a.DeclaredUnit.Boot != "disabled" {
|
||||
t.Errorf("the unit's held state read back as %+v", a.DeclaredUnit)
|
||||
}
|
||||
body, err := json.Marshal(a)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var keys map[string]json.RawMessage
|
||||
if err := json.Unmarshal(body, &keys); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(keys["declared"]) != `"root, mode 755"` || keys["declared_unit"] == nil {
|
||||
t.Errorf("written as %s", body)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user