-
Notifications
You must be signed in to change notification settings - Fork 1
[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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
context/context.go
Outdated
@@ -14,14 +14,30 @@ const ( | |||
LoggerKey = "ContextLoggerKey" | |||
) | |||
|
|||
type IContext interface { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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)
context/context.go
Outdated
} | ||
|
||
func New(parent context.Context, id string, actor models.User, log log.Logger) *Context { | ||
var _ IContext = &Context{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinbirch It's a compile-time check that Context
implements IContext
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
context/context_test.go
Outdated
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type FakeUser struct { |
There was a problem hiding this comment.
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.go
Outdated
context.Context | ||
} | ||
|
||
type ILoggableContext interface { |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
COVERAGE_DIR := $(BUILD_DIR)/coverage | ||
|
||
SHISA_PKGS := $(shell go list ./... | grep -Ev 'examples|test') | ||
SHISA_TEST_PKGS := $(addprefix coverage/,$(SHISA_PKGS)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
No description provided.