-
Notifications
You must be signed in to change notification settings - Fork 40
AddNew<type>Rule() as default way to create a rule #31
AddNew<type>Rule() as default way to create a rule #31
Conversation
ed550f7
to
00b7922
Compare
|
||
Convey("No error returned", func() { | ||
So(err, ShouldBeNil) | ||
}) | ||
|
||
Convey("Has interger rule", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of test is already done in the library tests. Do we still want to make this possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we do. It's for the unit test of rand.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, it looks fine. But I wish result check is not hard coded but as before in the expected results. The benefit is easy to change values if I like to test different scenarios or different values. Now I have to go into each line of code to change that.
} else { | ||
sr, err = NewStringRule(c.input.key, c.input.req) | ||
err = p.AddNewStringRule(c.input.ns, c.input.key, c.input.req) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing expected result comparison?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added expected result in config_policy_test.go
.
} | ||
|
||
func stringPassTestCases() []testCaseString { | ||
tc := []testCaseString{ | ||
testCaseString{ | ||
expected: stringRule{Key: "xyz", Required: true}, | ||
input: stringInput{key: "xyz", req: true}, | ||
input: stringInput{key: "xyz", req: true}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't keep expected here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved tests with expected result to config_policy_test.go
.
00b7922
to
43c3003
Compare
So(vv.Required, ShouldEqual, srule.Required) | ||
So(vv.HasDefault, ShouldEqual, srule.HasDefault) | ||
So(vv.Default, ShouldEqual, srule.Default) | ||
if kk == c.output.key { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keys should be always equal. Why do you need if statement here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v.GetRules()
still return previous test cases of the same type. In this PR there are 2 string test cases, and 2 bool test cases. So we don't want to test the current rule with a former one.
But we still verify that the rule is there with the exist
variable.
|
||
// SetDefaultBool Allows easy setting of the Default value for an boolRule. | ||
// Usage: | ||
// NewBoolRule(key, req, config.SetDefaultBool(default)) | ||
func SetDefaultBool(in bool) boolRuleOpt { | ||
return func(i *boolRule) { | ||
return func(i *rpc.BoolRule) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious what you think about potentially merging the type files into one since they no longer contain structs.
} else { | ||
br, err = NewBoolRule(c.input.key, c.input.req) | ||
err = p.AddNewBoolRule(c.input.ns, c.input.key, c.input.req) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this testing the same thing? Wouldn't we want to check that the rule that is created is the same was what was expected to keep parity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment than above #31 (comment)
Those tests have been moved to config_policy_test.go
.
expected: boolRule{}, | ||
input: input{key: "", req: false, opts: SetDefaultBool(false)}, | ||
testCaseBool{ | ||
input: boolInput{key: "", req: false, opts: SetDefaultBool(false)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line width.
// and optionally: | ||
// config.SetDefaultInt(int64), | ||
// config.SetMinInt(int64), | ||
// config.SetMaxInt(int64), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comment on the NewIntRule was already wrong, but this is no longer in the config package. Could you update the examples to plugin.Set()? Applies to the others also.
ret.BoolPolicy[k].Rules[v.Key] = r | ||
} | ||
|
||
return ret |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
} | ||
|
||
type integerRuleOpt func(*integerRule) | ||
type integerRuleOpt func(*rpc.IntegerRule) | ||
|
||
// SetDefaultInt Allows easy setting of the Default value for an integerRule. | ||
// Usage: | ||
// // NewIntegerRule(key, req, config.SetDefaultInt(default)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to modify these comments that reference functions that don't exists anymore.
This commit changes 3 things that are linked: - Fixes issue that was overwriting a same type rule when it was using a common key. - Change ConfigPolicy structure. Fields are now private and use same types than rpc ConfigPolicy. - Mix `New<typeRule()` and `Add<type>Rule()` in one function: `AddNew<type>Rule()`.
43c3003
to
a9366c7
Compare
This concern only 3 plugins that use the new Go library. It's an update after this PR got merged intelsdi-x/snap-plugin-lib-go#31
This commit changes 3 things that are linked:
common key.
same types than rpc ConfigPolicy.
New<typeRule()
andAdd<type>Rule()
in one function:AddNew<type>Rule()
.