Skip to content

[API-858] Add Unit Tests to Baseline Code #2

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

Merged
merged 14 commits into from
Oct 10, 2017
Merged

[API-858] Add Unit Tests to Baseline Code #2

merged 14 commits into from
Oct 10, 2017

Conversation

solumos
Copy link
Contributor

@solumos solumos commented Sep 28, 2017

No description provided.

@solumos solumos requested a review from kevinbirch September 28, 2017 22:20
@solumos solumos self-assigned this Sep 28, 2017
Copy link
Member

@kevinbirch kevinbirch left a comment

Choose a reason for hiding this comment

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

the mock stuff is fine for what it is, but I prefer different approach. I'll discuss with you IRL.

log/logger.go Outdated
@@ -1,4 +1,4 @@
package log
package logx
Copy link
Member

Choose a reason for hiding this comment

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

This package should be called log. The other name was a holdover from PAM

@@ -14,14 +14,30 @@ const (
LoggerKey = "ContextLoggerKey"
)

type IContext interface {
Copy link
Member

Choose a reason for hiding this comment

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

interfaces in go shouldn't be named ISomething they should be named Somethinger instead.

Copy link
Member

Choose a reason for hiding this comment

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

also, this isn't used...

Copy link
Contributor Author

@solumos solumos Oct 5, 2017

Choose a reason for hiding this comment

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

I agree, for one-method interfaces. However, there doesn't seem to be an official "go" consensus beyond that (https://talks.golang.org/2014/names.slide#14)

Since it's just an interface that only embeds another interface, it's frivolous anyway (see https://github.com/golang/go/wiki/CodeReviewComments#interfaces)

}

func New(parent context.Context, id string, actor models.User, log log.Logger) *Context {
var _ IContext = &Context{}
Copy link
Member

Choose a reason for hiding this comment

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

what's this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

TIL. but, do we need it this extra interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No - I'm going to push an updated version shortly

"github.com/stretchr/testify/mock"
)

type FakeUser struct {
Copy link
Member

Choose a reason for hiding this comment

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

A fake for testing is going to be useful elsewhere, so could you move this into models/test/user.go that is package modeltest? Then you can have:

(models/test/user.go)

package modeltest

import (
	"github.com/percolate/shisa/models"
)
type FakeUser struct {
	id string
}

func (u *FakeUser) ID() string {
	return u.id
}

func MakeUser(id string) models.User {
	return &FakeUser{id: id}
}

context.Context
}

type ILoggableContext interface {
Copy link
Member

Choose a reason for hiding this comment

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

this isn't used, I don't thing we need this...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I think I got caught in this anti-pattern - https://github.com/golang/go/wiki/CodeReviewComments#interfaces

BUILD_DIR := build
COVERAGE_DIR := $(BUILD_DIR)/coverage

SHISA_PKGS := $(shell go list ./... | grep -Ev 'examples|test')
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 we would want to have test coverage for the test helpers. For example, the net/http/httptest package has test for those helpers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but as we just talked about, subpackages get tricky to test with the way we're generating the coverage reports

image

COVERAGE_DIR := $(BUILD_DIR)/coverage

SHISA_PKGS := $(shell go list ./... | grep -Ev 'examples|test')
SHISA_TEST_PKGS := $(addprefix coverage/,$(SHISA_PKGS))
Copy link
Member

Choose a reason for hiding this comment

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

Did you have a chance to look into generating a unified coverage report that includes cross-package coverage? We discussed taking some examples from this golang issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as we just discussed, it might make sense to handle incidental coverage in a subsequent PR

@@ -20,7 +21,7 @@ jobs:
- run:
name: Validate Markdown
command: |
mdl $(find . -type f -name '*.md')
mdl $(find . -path ./vendor -prune -o -type f -name '*.md' -print)
Copy link
Member

Choose a reason for hiding this comment

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

N.B. ignoring the vendor/ path for mdl


[[constraint]]
name = "github.com/stretchr/testify"
revision = "890a5c3458b43e6104ff5da8dfa139d013d77544"
Copy link
Member

Choose a reason for hiding this comment

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

N.B. explicitly using the latest commit since they haven't made a release in a loooong time

test: ${COVERAGE_DIR} ${SHISA_TEST_PKGS}

coverage/%:
go test -v -coverprofile=$(TOP_DIR)/$(COVERAGE_DIR)/$(@F)_coverage.out -covermode=atomic github.com/percolate/shisa/$(@F)
Copy link
Member

Choose a reason for hiding this comment

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

N.B. using full package path instead of changing into the package directory

@solumos solumos merged commit d5dd716 into master Oct 10, 2017
@solumos solumos deleted the add-tests branch October 10, 2017 18:20
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.

2 participants