Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

AddNew<type>Rule() as default way to create a rule #31

Merged
merged 1 commit into from
Sep 30, 2016

Conversation

kindermoumoute
Copy link
Contributor

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().

@kindermoumoute kindermoumoute force-pushed the fix_glitch_and_new_feature branch from ed550f7 to 00b7922 Compare September 28, 2016 22:26

Convey("No error returned", func() {
So(err, ShouldBeNil)
})

Convey("Has interger rule", func() {
Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor

@candysmurf candysmurf left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing expected result comparison?

Copy link
Contributor Author

@kindermoumoute kindermoumoute Sep 29, 2016

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},
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@kindermoumoute kindermoumoute force-pushed the fix_glitch_and_new_feature branch from 00b7922 to 43c3003 Compare September 29, 2016 18:22
So(vv.Required, ShouldEqual, srule.Required)
So(vv.HasDefault, ShouldEqual, srule.HasDefault)
So(vv.Default, ShouldEqual, srule.Default)
if kk == c.output.key {
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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)},
Copy link
Contributor

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),
Copy link
Contributor

@IRCody IRCody Sep 30, 2016

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
Copy link
Contributor

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))
Copy link
Contributor

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()`.
@kindermoumoute kindermoumoute force-pushed the fix_glitch_and_new_feature branch from 43c3003 to a9366c7 Compare September 30, 2016 16:33
@IRCody IRCody merged commit d7be151 into intelsdi-x:master Sep 30, 2016
kindermoumoute added a commit to kindermoumoute/snap that referenced this pull request Sep 30, 2016
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants