engine: resources: Receive keys should match mcl, not golang
The capitalization of these keys was wrong and they weren't getting seen. Add a test as well.
This commit is contained in:
@@ -1226,9 +1226,9 @@ func (obj *FileRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
||||
// might not have a new value to copy, and therefore we won't see this
|
||||
// notification of change. Therefore, it is important to process these
|
||||
// promptly, if they must not be lost, such as for cache invalidation.
|
||||
if val, exists := obj.init.Recv()["Content"]; exists && val.Changed {
|
||||
if val, exists := obj.init.Recv()["content"]; exists && val.Changed {
|
||||
// if we received on Content, and it changed, invalidate the cache!
|
||||
obj.init.Logf("contentCheckApply: invalidating sha256sum of `Content`")
|
||||
obj.init.Logf("contentCheckApply: invalidating sha256sum of `content`")
|
||||
obj.sha256sum = "" // invalidate!!
|
||||
}
|
||||
|
||||
|
||||
@@ -282,9 +282,9 @@ func (obj *KVRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
||||
}
|
||||
}()
|
||||
|
||||
if val, exists := obj.init.Recv()["Value"]; exists && val.Changed {
|
||||
if val, exists := obj.init.Recv()["value"]; exists && val.Changed {
|
||||
// if we received on Value, and it changed, wooo, nothing to do.
|
||||
obj.init.Logf("CheckApply: `Value` was updated!")
|
||||
obj.init.Logf("CheckApply: `value` was updated!")
|
||||
}
|
||||
|
||||
value, exists, err := obj.kvGet(ctx, obj.getKey())
|
||||
|
||||
@@ -85,9 +85,9 @@ func (obj *PrintRes) Watch(ctx context.Context) error {
|
||||
// CheckApply method for Print resource. Does nothing, returns happy!
|
||||
func (obj *PrintRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
||||
obj.init.Logf("CheckApply: %t", apply)
|
||||
if val, exists := obj.init.Recv()["Msg"]; exists && val.Changed {
|
||||
if val, exists := obj.init.Recv()["msg"]; exists && val.Changed {
|
||||
// if we received on Msg, and it changed, log message
|
||||
obj.init.Logf("CheckApply: Received `Msg` of: %s", obj.Msg)
|
||||
obj.init.Logf("CheckApply: Received `msg` of: %s", obj.Msg)
|
||||
}
|
||||
|
||||
var refresh = obj.init.Refresh()
|
||||
|
||||
@@ -91,12 +91,13 @@ type TestRes struct {
|
||||
// Func1 passes the value 42 to the input and returns a string.
|
||||
Func1 func(int) string `lang:"func1" yaml:"func1"`
|
||||
|
||||
ValidateBool bool `lang:"validatebool" yaml:"validate_bool"` // set to true to cause a validate error
|
||||
ValidateError string `lang:"validateerror" yaml:"validate_error"` // set to cause a validate error
|
||||
AlwaysGroup bool `lang:"alwaysgroup" yaml:"always_group"` // set to true to cause auto grouping
|
||||
CompareFail bool `lang:"comparefail" yaml:"compare_fail"` // will compare fail?
|
||||
SendValue string `lang:"sendvalue" yaml:"send_value"` // what value should we send?
|
||||
OnlyShow []string `lang:"onlyshow" yaml:"only_show"` // what values do we show?
|
||||
ValidateBool bool `lang:"validatebool" yaml:"validate_bool"` // set to true to cause a validate error
|
||||
ValidateError string `lang:"validateerror" yaml:"validate_error"` // set to cause a validate error
|
||||
AlwaysGroup bool `lang:"alwaysgroup" yaml:"always_group"` // set to true to cause auto grouping
|
||||
CompareFail bool `lang:"comparefail" yaml:"compare_fail"` // will compare fail?
|
||||
SendValue string `lang:"sendvalue" yaml:"send_value"` // what value should we send?
|
||||
ExpectRecv *[]string `lang:"expectrecv" yaml:"expect_recv"` // what keys should we expect from send/recv?
|
||||
OnlyShow []string `lang:"onlyshow" yaml:"only_show"` // what values do we show?
|
||||
|
||||
// TODO: add more fun properties!
|
||||
|
||||
@@ -146,14 +147,20 @@ func (obj *TestRes) Watch(ctx context.Context) error {
|
||||
|
||||
// CheckApply method for Test resource. Does nothing, returns happy!
|
||||
func (obj *TestRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
||||
expectRecv := []string{}
|
||||
for key, val := range obj.init.Recv() {
|
||||
obj.init.Logf("CheckApply: Received `%s`, changed: %t", key, val.Changed)
|
||||
expectRecv = append(expectRecv, key)
|
||||
}
|
||||
|
||||
if obj.init.Refresh() {
|
||||
obj.init.Logf("Received a notification!")
|
||||
}
|
||||
|
||||
if obj.ExpectRecv != nil && len(*obj.ExpectRecv) != len(expectRecv) {
|
||||
return false, fmt.Errorf("the received keys differ from expected, got: %+v", expectRecv)
|
||||
}
|
||||
|
||||
fakeLogf := func(format string, v ...interface{}) {
|
||||
key := format[0:strings.LastIndex(format, ":")]
|
||||
if len(obj.OnlyShow) == 0 || util.StrInList(key, obj.OnlyShow) {
|
||||
@@ -372,6 +379,19 @@ func (obj *TestRes) Cmp(r engine.Res) error {
|
||||
if obj.SendValue != res.SendValue {
|
||||
return fmt.Errorf("the SendValue differs")
|
||||
}
|
||||
if (obj.ExpectRecv == nil) != (res.ExpectRecv == nil) { // xor
|
||||
return fmt.Errorf("the ExpectRecv differs")
|
||||
}
|
||||
if obj.ExpectRecv != nil && res.ExpectRecv != nil {
|
||||
if len(*obj.ExpectRecv) != len(*res.ExpectRecv) {
|
||||
return fmt.Errorf("the length of ExpectRecv differs")
|
||||
}
|
||||
for i, x := range *obj.ExpectRecv {
|
||||
if x != (*res.ExpectRecv)[i] {
|
||||
return fmt.Errorf("the item at ExpectRecv index %d differs", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(obj.OnlyShow) != len(res.OnlyShow) {
|
||||
return fmt.Errorf("the length of OnlyShow differs")
|
||||
}
|
||||
|
||||
@@ -168,6 +168,7 @@ func TestLowerStructFieldNameToFieldName2(t *testing.T) {
|
||||
"alwaysgroup": "AlwaysGroup",
|
||||
"comparefail": "CompareFail",
|
||||
"sendvalue": "SendValue",
|
||||
"expectrecv": "ExpectRecv",
|
||||
"onlyshow": "OnlyShow",
|
||||
|
||||
"comment": "Comment",
|
||||
|
||||
@@ -126,9 +126,9 @@ func (obj *ValueRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
||||
received := false
|
||||
different := false
|
||||
checkOK := false
|
||||
if val, exists := obj.init.Recv()["Any"]; exists && val.Changed {
|
||||
if val, exists := obj.init.Recv()["any"]; exists && val.Changed {
|
||||
// if we received on Any, and it changed, invalidate the cache!
|
||||
obj.init.Logf("CheckApply: received on `Any`")
|
||||
obj.init.Logf("CheckApply: received on `any`")
|
||||
obj.isSet = true // we received something
|
||||
obj.cachedAny = obj.Any
|
||||
received = true // we'll always need to send below when we recv
|
||||
|
||||
Reference in New Issue
Block a user