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

Implement CRUD puppy with interface #538

Closed
wants to merge 3 commits into from

Conversation

patrickmarabeas
Copy link
Collaborator

Adds the Puppy, Storer, MapStore and SyncStore type definitions.

  • MapStore implements the Storer interface and supplies a NewMapStore factory function.
  • SyncStore implements the Storer interface and supplies a NewSyncStore factory function.
  • Uuid increment is handled internally by MapStore Create
  • Read will return an empty Puppy struct if provided uuid doesn't exist
  • Update will return the given Puppy struct if the uuid doesn't exist
  • Destroy returns a bool dependent on uuid existing

Fixes #537

Review of colleague's PR #536

Copy link
Collaborator

@pentaphobe pentaphobe left a comment

Choose a reason for hiding this comment

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

After a while staring at your code (and adding a few extra tests) I cannot work out what’s happening to your coverage.

However one thing which may help is if you conform to the go style of returning an error from functions which have an error condition and testing against that.

Still don't think that should matter, but never know... (also worth mentioning just as a stylistic nitpick)


FWIW: I sometimes use the HTML view of coverage to help see what the tool's seeing, but in this case it told me very little.

Either way, this is the command I used:

go test -v -race -coverprofile /tmp/cover.out -covermode=atomic ./... && go tool cover -html /tmp/cover.out -o /tmp/profile.html && open /tmp/profile.html

FWIW 2: Tests I tried out were things like:

  • doing non deep-equals checks of zero value returns
  • calling the offending functions on a nil store (which obviously just crashes - alas precluding any coverage result. Whilst it's arguable that one might need to check for such things, surely that would cause coverage issues on your other functions too)
  • started adding a custom error to your code (for my own edification) but the task exploded - and was discarded - once I realised I'd have to update signatures and calls across most files and it's 2am :)

@patrickmarabeas
Copy link
Collaborator Author

Hopefully it's not error related - as I removed all my error handling upon seeing Lab 07 outline!

06_puppy/patrickmarabeas/mapStore_test.go Outdated Show resolved Hide resolved
06_puppy/patrickmarabeas/mapStore_test.go Outdated Show resolved Hide resolved
06_puppy/patrickmarabeas/syncStore.go Outdated Show resolved Hide resolved
06_puppy/patrickmarabeas/mapStore.go Outdated Show resolved Hide resolved
06_puppy/patrickmarabeas/syncStore_test.go Outdated Show resolved Hide resolved
06_puppy/patrickmarabeas/syncStore_test.go Outdated Show resolved Hide resolved
06_puppy/patrickmarabeas/syncStore_test.go Outdated Show resolved Hide resolved
@juliaogris
Copy link
Contributor

Please fix broken build and address @anzdaddy 's comments

@patrickmarabeas patrickmarabeas force-pushed the lab-06-pm branch 2 times, most recently from 33a306c to 1229a14 Compare August 19, 2019 05:21
@codecov
Copy link

codecov bot commented Aug 19, 2019

Codecov Report

Merging #538 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #538   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files         182    185    +3     
  Lines        3446   3494   +48     
=====================================
+ Hits         3446   3494   +48
Impacted Files Coverage Δ
06_puppy/patrickmarabeas/mapStore.go 100% <100%> (ø)
06_puppy/patrickmarabeas/main.go 100% <100%> (ø)
06_puppy/patrickmarabeas/syncStore.go 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5fee262...5d53a52. Read the comment docs.

Copy link
Member

@anzboi anzboi left a comment

Choose a reason for hiding this comment

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

Great work, Just one think I would like to fix up.
From an interface level, we don't care about what ids are being created, only that they are different for any two Create calls. IMO the Create test should just create two puppies and check the generated ID's are different.
Feel free to disagree and I'll approve.

06_puppy/patrickmarabeas/types.go Outdated Show resolved Hide resolved
}

type SyncStore struct {
uuid int
Copy link
Member

Choose a reason for hiding this comment

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

Interesting interpretation of uuid you have there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to uint

a := assert.New(suite.T())
id := suite.store.Create(Puppy{Breed: "Boxer", Color: "Brown", Value: "300"})

a.Equal(id, 1)
Copy link
Member

Choose a reason for hiding this comment

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

I think what @anzdaddy was getting at here is that TestCreate should create 2 puppies, and check the second ones ID is incremented by 1 from the first, or at least different, think about what could be generating these id's if you don't know what the implementation is.
Otherwise, great tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Adds the Puppy, Storer and MapStore type definitions. MapStore implements
the Storer interface and supplies a NewMapStore factory function.

- Uuid increment is handled internally by MapStore Create
- Read will return an empty Puppy struct if provided uuid doesn't exist
- Update returns a bool whether a matching identifier was modified
- Destroy returns a bool whether a matching identifier was modified

Lab 06 (anz-bank#537)
SyncStore implements the Storer interface and supplies a NewSyncStore
factory function.

- Uuid increment is handled internally by SyncStore Create
- Read will return an empty Puppy struct if provided uuid doesn't exist
- Update returns a bool whether a matching identifier was modified
- Destroy returns a bool whether a matching identifier was modified

Lab 06 (anz-bank#537)
Add empty main function and tests to pass build requirements
Copy link
Member

@rokane rokane left a comment

Choose a reason for hiding this comment

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

Looking really good! Great suite of tests and really clean, well documented code. I have left a couple of comments throughout which I think would be nice to have. Also there is the empty main function, if you feel against what I have suggested then let me know, otherwise it would be nice to see something in there (even if it's simple)

package main

func main() {

Copy link
Member

Choose a reason for hiding this comment

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

I find it a little strange seeing a blank main program. I know the description of the lab doesn't state what you need to include in the main, so you have technically ticked all the boxes, but I feel it makes sense to maybe create a puppy or something to give context to the work being done. Happy to hear your thoughts otherwise.

@@ -0,0 +1,56 @@
package main

type MapStore struct {
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to see some documentation on the MapStore struct as well, since it is a part of the exported package.

"sync"
)

type SyncStore struct {
Copy link
Member

Choose a reason for hiding this comment

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

Again here with the documentation as well

Value string
}

type Storer interface {
Copy link
Member

Choose a reason for hiding this comment

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

Again here with the documentation.


func (suite *StoreSuite) TestReadNonExistent() {
a := assert.New(suite.T())
success := suite.store.Read(100)
Copy link
Member

Choose a reason for hiding this comment

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

success seems like a strange name for this variable. Maybe notFound or something which indicates that it didn't exist?

@juliaogris
Copy link
Contributor

The go-course is now closed. Thank you very much for participating.

@juliaogris juliaogris closed this Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lab 6 - CRUD puppy with interface
7 participants