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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor generator validation #15

Merged
merged 2 commits into from May 19, 2017
Merged

Refactor generator validation #15

merged 2 commits into from May 19, 2017

Conversation

KevinGimbel
Copy link
Collaborator

This patch reverts the changes made in #10 and places the generator
validation inside the NewColumns function.
Tests have been adjusted so that they can handle expected error cases for unknown generators.

I manually tested it and ran the tests locally with make test and I believe this time nothing is broken! 馃槃

This commit reverts the changes made in #10 and places the generator
validation inside the NewColumns function. This function iterates and
"parses" all keys so we do not need to re-implement all parsing.

Tests have been adjusted so that they can handle expected error cases.
@KevinGimbel KevinGimbel changed the title Refactor generator validation; Updates #12 Refactor generator validation May 19, 2017
@lucapette
Copy link
Owner

@KevinGimbel this looks great!

One small detail: we changed the test assertion to if actual, err := fakedata.NewColumns(tt.input); !reflect.DeepEqual(actual, tt.expected) && ((err != nil) != tt.wantErr) which makes sense because NewColumns now can return an error. But we don't print the error if the test fail.

I'm thinking maybe we should extract actual, err := fakedata.NewColumns(tt.input) and have an assertion for actual and another for err. It'd make it very explicit we're testing both things.

I can take care of it if you don't have the time. The code looks pretty good already as it is. Thank you very much!

@KevinGimbel
Copy link
Collaborator Author

Thanks for the kind words!

I'm thinking maybe we should extract actual, err := fakedata.NewColumns(tt.input) and have an assertion for actual and another for err. It'd make it very explicit we're testing both things.

That makes sense. Handling both cases would mean changing all Column tests to something like this?

t.Run(tt.name, func(t *testing.T) {
	actual, err := fakedata.NewColumns(tt.input)
	
	// Test fails with unexpected result
	if !reflect.DeepEqual(actual, tt.expected) {
		t.Errorf("NewColumns() = %v, want %v", actual, tt.expected)
	}

	// Dont't want error but got error
	if (err != nil) && !tt.wantErr {
		t.Errorf("NewColumns() = Dont want error but got: %v", err)
	}
})

Printing the "expected" errors from NewColumns would not make much sense or am I missing something? When we have wantErr: true we expect an error from the function, so no need to print it. When we have wantErr: false and get an error, there is something wrong.

I can make the changes in my lunch break today. :)

@lucapette
Copy link
Owner

@KevinGimbel that looks perfect to me!

@KevinGimbel
Copy link
Collaborator Author

@lucapette yay! 馃帀 I'll implemented it later today then.

@KevinGimbel
Copy link
Collaborator Author

I made the changes to all tests in column_test.go so they handle the newly returned error. I had to slightly adjust the check for actual .

if !reflect.DeepEqual(actual, tt.expected) && !tt.wantErr {
    t.Errorf("NewColumns() = %v, want %v", actual, tt.expected)
}

For tests that should fail we need the check for !tt.wantErr, otherwise the tests fail the DeepEqual check as seen below.

    --- FAIL: TestNewColumns/two_columns,_one_column_fails (0.00s)
        column_test.go:28: NewColumns() = [{email email } {domain domain } {unsupportedgenerator unsupportedgenerator }], want []
    --- FAIL: TestNewColumns/one_column,_all_fails (0.00s)
        column_test.go:28: NewColumns() = [{madeupgenerator madeupgenerator }], want []

These two tests are defined with wantErr: true so by checking && !tt.wantErr we can skip the error reporting here.

@lucapette
Copy link
Owner

@KevinGimbel so cool! thank you again!

@lucapette lucapette merged commit 078593f into lucapette:master May 19, 2017
@KevinGimbel
Copy link
Collaborator Author

@lucapette you're welcome! It's been fun to work on some "real" Go code. :D if you ever want some more help hit me up.

@lucapette
Copy link
Owner

@KevinGimbel I have a small list of generators and some little gardening I'd like to do. I'll be opening issues in the coming days. If you'd like to take over one of the issues, I'd very grateful and happy to help!

@KevinGimbel
Copy link
Collaborator Author

@lucapette I'll keep an eye on issues and will let you know when I have the time to work on one or more. It's a good exercise for me, both in Go and general GitHub workflow/contributing to other people's code. Thank you again for being so welcoming!

@KevinGimbel KevinGimbel deleted the patch/12/refactorValidation branch May 19, 2017 16:12
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.

None yet

2 participants