Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .ginkgo/templates/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package {{.Package}}

import (
"testing"

"github.com/tidepool-org/platform/test"
)

func TestSuite(t *testing.T) {
test.Test(t)
}
15 changes: 15 additions & 0 deletions .ginkgo/templates/generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{.BuildTags}}
package {{.Package}}

import (
{{.GinkgoImport}}
{{.GomegaImport}}
. "github.com/onsi/gomega/gstruct"

{{if .ImportPackage}}"{{.PackageImportPath}}"{{end}}
"github.com/tidepool-org/platform/test"
)

var _ = {{.GinkgoPackage}}Describe("{{.Subject}}", func() {
// TODO
})
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ _tmp
# Development
.gvm_local
.idea
.vscode
*.code-workspace
109 changes: 0 additions & 109 deletions .vscode/launch.json

This file was deleted.

38 changes: 34 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ GINKGO_FLAGS += --require-suite --poll-progress-after=10s --poll-progress-interv
GINKGO_CI_WATCH_FLAGS += --randomize-all --succinct --fail-on-pending --cover --trace --race
GINKGO_CI_FLAGS += $(GINKGO_CI_WATCH_FLAGS) --randomize-suites --keep-going

ifdef TEST
TEST_PACKAGE=$(shell [ -d "$(TEST)" ] && echo "$(TEST)" || dirname "$(TEST)")
TEST_PACKAGE_NAME=$(notdir $(TEST_PACKAGE))
TEST_DIRECTORY=$(realpath $(TEST_PACKAGE))
TEST_FILE=$(notdir $(TEST))
endif

TEST_REPEAT ?= 0

DOCKER_LOGIN_CMD ?= docker login
DOCKER_BUILD_CMD ?= docker build
DOCKER_PUSH_CMD ?= docker push
Expand Down Expand Up @@ -265,10 +274,15 @@ test-ginkgo: ginkgo
@cd $(ROOT_DIRECTORY) && \
. ./env.test.sh && GOWORK=off $(TIMING_CMD) ginkgo $(GINKGO_FLAGS) $${GOWORK_FLAGS:-} $(TEST)

test-ginkgo-until-repeat: ginkgo
@echo "ginkgo $(GINKGO_FLAGS) --repeat $(TEST_REPEAT) $(TEST)"
@cd $(ROOT_DIRECTORY) && \
. ./env.test.sh && GOWORK=off ginkgo $(GINKGO_FLAGS) --repeat $(TEST_REPEAT) $${GOWORK_FLAGS:-} $(TEST)

test-ginkgo-until-failure: ginkgo
@echo "ginkgo $(GINKGO_FLAGS) -untilItFails $(TEST)"
@echo "ginkgo $(GINKGO_FLAGS) --until-it-fails $(TEST)"
@cd $(ROOT_DIRECTORY) && \
. ./env.test.sh && GOWORK=off ginkgo $(GINKGO_FLAGS) -untilItFails $${GOWORK_FLAGS:-} $(TEST)
. ./env.test.sh && GOWORK=off ginkgo $(GINKGO_FLAGS) --until-it-fails $${GOWORK_FLAGS:-} $(TEST)

test-ginkgo-watch: ginkgo
@echo "ginkgo watch $(GINKGO_FLAGS) $(TEST)"
Expand All @@ -280,10 +294,15 @@ ci-test-ginkgo: ginkgo
@cd $(ROOT_DIRECTORY) && \
. ./env.test.sh && GOWORK=off $(TIMING_CMD) ginkgo $(GINKGO_FLAGS) $(GINKGO_CI_FLAGS) $${GOWORK_FLAGS:-} $(TEST)

ci-test-ginkgo-repeat: ginkgo
@echo "ginkgo $(GINKGO_FLAGS) $(GINKGO_CI_FLAGS) --repeat $(TEST_REPEAT) $(TEST)"
@cd $(ROOT_DIRECTORY) && \
. ./env.test.sh && GOWORK=off ginkgo $(GINKGO_FLAGS) $(GINKGO_CI_FLAGS) --repeat $(TEST_REPEAT) $${GOWORK_FLAGS:-} $(TEST)

ci-test-ginkgo-until-failure: ginkgo
@echo "ginkgo $(GINKGO_FLAGS) $(GINKGO_CI_FLAGS) -untilItFails $(TEST)"
@echo "ginkgo $(GINKGO_FLAGS) $(GINKGO_CI_FLAGS) --until-it-fails $(TEST)"
@cd $(ROOT_DIRECTORY) && \
. ./env.test.sh && GOWORK=off ginkgo $(GINKGO_FLAGS) $(GINKGO_CI_FLAGS) -untilItFails $${GOWORK_FLAGS:-} $(TEST)
. ./env.test.sh && GOWORK=off ginkgo $(GINKGO_FLAGS) $(GINKGO_CI_FLAGS) --until-it-fails $${GOWORK_FLAGS:-} $(TEST)

ci-test-ginkgo-watch: ginkgo
@echo "ginkgo watch $(GINKGO_FLAGS) $(GINKGO_CI_WATCH_FLAGS) $(TEST)"
Expand All @@ -300,6 +319,17 @@ ci-test-go: GOTEST_FLAGS += -count=1 -race -shuffle=on -cover
ci-test-go: GOTEST_PKGS = ./...
ci-test-go: test-go

ginkgo-bootstrap: ginkgo
@echo "ginkgo bootstrap $(TEST_PACKAGE)"
@cd "$(TEST_DIRECTORY)" && \
[ -f "$(TEST_PACKAGE_NAME)_suite_test.go" ] || \
ginkgo bootstrap --template "$(ROOT_DIRECTORY)/.ginkgo/templates/bootstrap"

ginkgo-generate: ginkgo-bootstrap
Comment thread
darinkrauss marked this conversation as resolved.
@echo "ginkgo generate $(TEST)"
@cd "$(TEST_DIRECTORY)" && \
ginkgo generate --template "$(ROOT_DIRECTORY)/.ginkgo/templates/generate" $(TEST_FILE)

service-build:
ifdef SERVICE
@$(MAKE) build BUILD=$${SERVICE}
Expand Down
20 changes: 10 additions & 10 deletions alerts/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var _ = Describe("Config", func() {
}
}`, mockUserID1, mockUserID2, mockUploadID)
conf := &Config{}
err := request.DecodeObject(context.Background(), nil, buf, conf)
err := request.DecodeStream(context.Background(), nil, buf, conf)
Expect(err).ToNot(HaveOccurred())
Expect(conf.UserID).To(Equal(mockUserID1))
Expect(conf.FollowedUserID).To(Equal(mockUserID2))
Expand Down Expand Up @@ -358,7 +358,7 @@ var _ = Describe("Config", func() {
It("validates threshold units", func() {
buf := buff(`{"urgentLow": {"threshold": {"units":"%s","value":42}}`, "garbage")
threshold := &Threshold{}
err := request.DecodeObject(context.Background(), nil, buf, threshold)
err := request.DecodeStream(context.Background(), nil, buf, threshold)
Expect(err).To(MatchError("json is malformed"))
})
It("validates repeat minutes (negative)", func() {
Expand All @@ -376,7 +376,7 @@ var _ = Describe("Config", func() {
}
}`, mockUserID1, mockUserID2, mockUploadID, glucose.MgdL)
cfg := &Config{}
err := request.DecodeObject(context.Background(), nil, buf, cfg)
err := request.DecodeStream(context.Background(), nil, buf, cfg)
Expect(err).To(MatchError("value -11m0s is not greater than or equal to 15m0s"))
})
It("validates repeat minutes (string)", func() {
Expand All @@ -393,7 +393,7 @@ var _ = Describe("Config", func() {
}
}`, mockUserID1, mockUserID2, glucose.MgdL)
cfg := &Config{}
err := request.DecodeObject(context.Background(), nil, buf, cfg)
err := request.DecodeStream(context.Background(), nil, buf, cfg)
Expect(err).To(MatchError("json is malformed"))
})
})
Expand All @@ -414,7 +414,7 @@ var _ = Describe("Config", func() {
}
}`, mockUserID1, mockUserID2, mockUploadID)
conf := &Config{}
err := request.DecodeObject(context.Background(), nil, buf, conf)
err := request.DecodeStream(context.Background(), nil, buf, conf)
Expect(err).To(Succeed())
Expect(conf.Low.Repeat).To(Equal(DurationMinutes(0)))
})
Expand Down Expand Up @@ -458,33 +458,33 @@ var _ = Describe("Threshold", func() {
It("accepts mg/dL", func() {
buf := buff(`{"units":"%s","value":42}`, glucose.MgdL)
threshold := &Threshold{}
err := request.DecodeObject(context.Background(), nil, buf, threshold)
err := request.DecodeStream(context.Background(), nil, buf, threshold)
Expect(err).To(BeNil())
Expect(threshold.Value).To(Equal(42.0))
Expect(threshold.Units).To(Equal(glucose.MgdL))
})
It("accepts mmol/L", func() {
buf := buff(`{"units":"%s","value":42}`, glucose.MmolL)
threshold := &Threshold{}
err := request.DecodeObject(context.Background(), nil, buf, threshold)
err := request.DecodeStream(context.Background(), nil, buf, threshold)
Expect(err).To(BeNil())
Expect(threshold.Value).To(Equal(42.0))
Expect(threshold.Units).To(Equal(glucose.MmolL))
})
It("rejects lb/gal", func() {
buf := buff(`{"units":"%s","value":42}`, "lb/gal")
err := request.DecodeObject(context.Background(), nil, buf, &Threshold{})
err := request.DecodeStream(context.Background(), nil, buf, &Threshold{})
Expect(err).Should(HaveOccurred())
})
It("rejects blank units", func() {
buf := buff(`{"units":"","value":42}`)
err := request.DecodeObject(context.Background(), nil, buf, &Threshold{})
err := request.DecodeStream(context.Background(), nil, buf, &Threshold{})
Expect(err).Should(HaveOccurred())
})
It("is case-sensitive with respect to Units", func() {
badUnits := strings.ToUpper(glucose.MmolL)
buf := buff(`{"units":"%s","value":42}`, badUnits)
err := request.DecodeObject(context.Background(), nil, buf, &Threshold{})
err := request.DecodeStream(context.Background(), nil, buf, &Threshold{})
Expect(err).Should(HaveOccurred())
})

Expand Down
2 changes: 1 addition & 1 deletion auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var _ = Describe("Client", func() {
serverSessionTokenProviderController.Finish()
})

It("returs nil if the context is nil", func() {
It("returns nil if the context is nil", func() {
Expect(auth.ServerSessionTokenProviderFromContext(nil)).To(BeNil())
})

Expand Down
4 changes: 4 additions & 0 deletions auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (o *OAuthToken) Refreshed(rawToken *oauth2.Token) (*OAuthToken, error) {
return &refreshed, nil
}

func (o *OAuthToken) IsExpired() bool {
return o.ExpirationTime.Before(time.Now())
Comment thread
darinkrauss marked this conversation as resolved.
}

func (o *OAuthToken) Expired() *OAuthToken {
return &OAuthToken{
AccessToken: o.AccessToken,
Expand Down
16 changes: 15 additions & 1 deletion auth/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,21 @@ var _ = Describe("OAuthToken", func() {
})
})

Context("Expire", func() {
Context("IsExpired", func() {
It("returns false if the expiration time is in the future", func() {
token := authTest.RandomToken()
token.ExpirationTime = time.Now().Add(time.Second)
Expect(token.IsExpired()).To(BeFalse())
})

It("returns true if the expiration time is in the past", func() {
token := authTest.RandomToken()
token.ExpirationTime = time.Now().Add(-time.Second)
Expect(token.IsExpired()).To(BeTrue())
})
})

Context("Expired", func() {
It("sets ExpirationTime to the past", func() {
token := authTest.RandomToken().Expired()
Expect(token.ExpirationTime).To(BeTemporally("<", time.Now()))
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *Client) RequestDataWithHTTPClient(ctx context.Context, method string, u
return nil
}

return request.DecodeObject(ctx, structure.NewPointerSource(), body, responseBody)
return request.DecodeStream(ctx, structure.NewPointerSource(), body, responseBody)
}

func (c *Client) createRequest(ctx context.Context, method string, url string, mutators []request.RequestMutator, requestBody interface{}) (*http.Request, error) {
Expand Down
Loading
Loading