Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Date minimum/maximum constraints #57

Merged

Conversation

cored
Copy link
Contributor

@cored cored commented Oct 4, 2017

for issue #44

@coveralls
Copy link

coveralls commented Oct 4, 2017

Coverage Status

Coverage increased (+0.1%) to 94.456% when pulling b1f4590 on cored:add-date-min-max-constraint into 74e0168 on frictionlessdata:master.

Copy link
Collaborator

@danielfireman danielfireman left a comment

Choose a reason for hiding this comment

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

Only minor changes.

Furthermore, could you please move those changes to date.go and date_test.go? I've started this move with time{_test}.go but didn't finish.

Thanks!

func decodeDate(format, value string, c Constraints) (time.Time, error) {
y, err := decodeDateWithoutChecks(format, value)
if err != nil {
return time.Now(), err
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please return v here? This was discussed and changed #54,

if c.Maximum != "" {
max, err = decodeDateWithoutChecks(format, c.Maximum)
if err != nil {
return time.Now(), err
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same above. Please return max.

if c.Minimum != "" {
min, err = decodeDateWithoutChecks(format, c.Minimum)
if err != nil {
return time.Now(), err
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same above, please return min, err

@cored
Copy link
Contributor Author

cored commented Oct 5, 2017

@danielfireman I'm following same patterns in the codebase, however, there are some things that I don't quite understand. Why is it that the test does assertions against private functions? Wouldn't be better to use schema_test package for the tests and just test public functions?. If the reason is that these functions support a higher level component why not just add the test at that level?

Rename castDate to be decodeDateWithoutChecks to follow similar pattern
as the decodeYearMonthWithoutChecks function.
@cored cored force-pushed the add-date-min-max-constraint branch from f2ecb50 to 1d175fb Compare October 5, 2017 15:58
@coveralls
Copy link

coveralls commented Oct 5, 2017

Coverage Status

Coverage increased (+0.1%) to 94.028% when pulling 1d175fb on cored:add-date-min-max-constraint into f0344dc on frictionlessdata:master.

@coveralls
Copy link

coveralls commented Oct 5, 2017

Coverage Status

Coverage increased (+0.1%) to 94.028% when pulling 1d175fb on cored:add-date-min-max-constraint into f0344dc on frictionlessdata:master.

@danielfireman danielfireman merged commit 694a9f5 into frictionlessdata:master Oct 5, 2017
@danielfireman
Copy link
Collaborator

Hi @cored, thanks for your contributions!

About your question:

@danielfireman I'm following same patterns in the codebase, however, there are some things that I don't quite understand. Why is it that the test does assertions against private functions? Wouldn't be better to use schema_test package for the tests and just test public functions?. If the reason is that these functions support a higher level component why not just add the test at that level?

As the code gets more complex, it is usually better to rely more heavily on unit testing. There are many reasons for that, including easier maintenance, faster, simpler (more benefits here).

Let's say we decide to test that against the public Field.Decode. That simple test would involve: i) creating a field as a string, ii) call json.Unmarshal and iii) either check error or success. That still quite simple, but I its much simpler to assume the Field struct knows how to perform steps i and ii and check the third step as a unit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants