~evanj/cms

988b7528f2cbbe7da4b1cec55427b9673b927a40 — Evan J 10 months ago ec3e200
WIP(testing): Step one of fixing broken tests.
M internal/c/c_test.go => internal/c/c_test.go +9 -9
@@ 37,7 37,7 @@ func TestJSON(t *testing.T) {
		ctrl = gomock.NewController(t)
		db   = mock_c.NewMockdber(ctrl)
		l    *log.Logger
		s    = server{c.New(l, db, true)}
		s    = server{c.New(l, db, true, "test")}
		ts   = httptest.NewServer(s)
	)



@@ 53,7 53,7 @@ func TestHTML(t *testing.T) {
		ctrl = gomock.NewController(t)
		db   = mock_c.NewMockdber(ctrl)
		l    *log.Logger
		s    = server{c.New(l, db, true)}
		s    = server{c.New(l, db, true, "test")}
		ts   = httptest.NewServer(s)
	)



@@ 106,7 106,7 @@ func TestMethodHack(t *testing.T) {
	for _, test := range tests {
		var (
			s = server2{
				c.New(l, db, true),
				c.New(l, db, true, "test"),
				func(method string) {
					assert.Equal(t, method, test.expect)
				},


@@ 158,7 158,7 @@ func TestRedirect(t *testing.T) {

	for _, test := range tests {
		var (
			s   = server3{c.New(l, db, true), test}
			s   = server3{c.New(l, db, true, "test"), test}
			ts  = httptest.NewServer(s)
			val = url.Values{"url": {test}}
		)


@@ 172,7 172,7 @@ func TestRedirect(t *testing.T) {

	for _, test := range tests {
		var (
			s  = server3{c.New(l, db, true), test}
			s  = server3{c.New(l, db, true, "test"), test}
			ts = httptest.NewServer(s)
		)
		buf, _ := json.Marshal(map[string]string{"redirectURL": test})


@@ 211,7 211,7 @@ func TestUserFromBasicAuth(t *testing.T) {
		ctrl = gomock.NewController(t)
		db   = mock_c.NewMockdber(ctrl)
		l    *log.Logger
		s    = server4{c.New(l, db, true)}
		s    = server4{c.New(l, db, true, "test")}
		ts   = httptest.NewServer(s)

		uname = uuid.New().String()


@@ 235,7 235,7 @@ func TestUserFromFromCookie(t *testing.T) {
		ctrl = gomock.NewController(t)
		db   = mock_c.NewMockdber(ctrl)
		l    *log.Logger
		s    = server4{c.New(l, db, true)}
		s    = server4{c.New(l, db, true, "test")}
		ts   = httptest.NewServer(s)

		uname  = uuid.New().String()


@@ 265,7 265,7 @@ func TestUserFromFromCookieFail(t *testing.T) {
		ctrl = gomock.NewController(t)
		db   = mock_c.NewMockdber(ctrl)
		l    *log.Logger
		s    = server4{c.New(l, db, true)}
		s    = server4{c.New(l, db, true, "test")}
		ts   = httptest.NewServer(s)

		cookie = uuid.New().String()


@@ 324,7 324,7 @@ func TestStrAndErr(t *testing.T) {

	for _, test := range tests {
		var (
			s  = server5{c.New(l, db, true), test.typ, test.str}
			s  = server5{c.New(l, db, true, "test"), test.typ, test.str}
			ts = httptest.NewServer(s)
		)
		res, _ := http.Get(ts.URL)

M internal/c/content/content_test.go => internal/c/content/content_test.go +9 -9
@@ 175,7 175,7 @@ func TestCreateGood(t *testing.T) {
		e3   = content.NewMockE3er(ctrl)
		h    = content.NewMockHooker(ctrl)
		l    = log.New(os.Stdout, "", 0)
		ts   = httptest.NewServer(content.New(c.New(l, db, true), l, db, e3, h, ""))
		ts   = httptest.NewServer(content.New(c.New(l, db, true, "test"), l, db, e3, h, ""))

		u  = fakeuser{uuid.New().String(), uuid.New().String()}
		s  = fakespace{uuid.New().String(), uuid.New().String()}


@@ 229,7 229,7 @@ func TestUpdateGood(t *testing.T) {
		e3   = content.NewMockE3er(ctrl)
		h    = content.NewMockHooker(ctrl)
		l    = log.New(os.Stdout, "", 0)
		ts   = httptest.NewServer(content.New(c.New(l, db, true), l, db, e3, h, ""))
		ts   = httptest.NewServer(content.New(c.New(l, db, true, "test"), l, db, e3, h, ""))

		u  = fakeuser{uuid.New().String(), uuid.New().String()}
		s  = fakespace{uuid.New().String(), uuid.New().String()}


@@ 287,7 287,7 @@ func TestUpdateGood2(t *testing.T) {
		e3   = content.NewMockE3er(ctrl)
		h    = content.NewMockHooker(ctrl)
		l    = log.New(os.Stdout, "", 0)
		ts   = httptest.NewServer(content.New(c.New(l, db, true), l, db, e3, h, ""))
		ts   = httptest.NewServer(content.New(c.New(l, db, true, "test"), l, db, e3, h, ""))

		u  = fakeuser{uuid.New().String(), uuid.New().String()}
		s  = fakespace{uuid.New().String(), uuid.New().String()}


@@ 332,7 332,7 @@ func TestServeGood(t *testing.T) {
		e3   = content.NewMockE3er(ctrl)
		h    = content.NewMockHooker(ctrl)
		l    = log.New(os.Stdout, "", 0)
		ts   = httptest.NewServer(content.New(c.New(l, db, true), l, db, e3, h, ""))
		ts   = httptest.NewServer(content.New(c.New(l, db, true, "test"), l, db, e3, h, ""))

		u  = fakeuser{uuid.New().String(), uuid.New().String()}
		s  = fakespace{uuid.New().String(), uuid.New().String()}


@@ 371,7 371,7 @@ func TestServeGood2(t *testing.T) {
		e3   = content.NewMockE3er(ctrl)
		h    = content.NewMockHooker(ctrl)
		l    = log.New(os.Stdout, "", 0)
		ts   = httptest.NewServer(content.New(c.New(l, db, true), l, db, e3, h, ""))
		ts   = httptest.NewServer(content.New(c.New(l, db, true, "test"), l, db, e3, h, ""))

		u  = fakeuser{uuid.New().String(), uuid.New().String()}
		s  = fakespace{uuid.New().String(), uuid.New().String()}


@@ 406,7 406,7 @@ func TestServeGood3(t *testing.T) {
		e3   = content.NewMockE3er(ctrl)
		h    = content.NewMockHooker(ctrl)
		l    = log.New(os.Stdout, "", 0)
		ts   = httptest.NewServer(content.New(c.New(l, db, true), l, db, e3, h, ""))
		ts   = httptest.NewServer(content.New(c.New(l, db, true, "test"), l, db, e3, h, ""))

		u  = fakeuser{uuid.New().String(), uuid.New().String()}
		s  = fakespace{uuid.New().String(), uuid.New().String()}


@@ 435,7 435,7 @@ func TestDeleteGood(t *testing.T) {
		e3   = content.NewMockE3er(ctrl)
		h    = content.NewMockHooker(ctrl)
		l    = log.New(os.Stdout, "", 0)
		ts   = httptest.NewServer(content.New(c.New(l, db, true), l, db, e3, h, ""))
		ts   = httptest.NewServer(content.New(c.New(l, db, true, "test"), l, db, e3, h, ""))

		u  = fakeuser{uuid.New().String(), uuid.New().String()}
		s  = fakespace{uuid.New().String(), uuid.New().String()}


@@ 473,7 473,7 @@ func TestSearchGood(t *testing.T) {
		e3   = content.NewMockE3er(ctrl)
		h    = content.NewMockHooker(ctrl)
		l    = log.New(os.Stdout, "", 0)
		ts   = httptest.NewServer(content.New(c.New(l, db, true), l, db, e3, h, ""))
		ts   = httptest.NewServer(content.New(c.New(l, db, true, "test"), l, db, e3, h, ""))

		u  = fakeuser{uuid.New().String(), uuid.New().String()}
		s  = fakespace{uuid.New().String(), uuid.New().String()}


@@ 714,7 714,7 @@ func TestBad(t *testing.T) {
			e3   = content.NewMockE3er(ctrl)
			h    = content.NewMockHooker(ctrl)
			l    = log.New(os.Stdout, "", 0)
			ts   = httptest.NewServer(content.New(c.New(l, db, true), l, db, e3, h, ""))
			ts   = httptest.NewServer(content.New(c.New(l, db, true, "test"), l, db, e3, h, ""))
		)

		test.mock(db, e3, h)

M internal/c/contenttype/contenttype_test.go => internal/c/contenttype/contenttype_test.go +3 -3
@@ 29,7 29,7 @@ func TestNoUser(t *testing.T) {
		ctrl    = gomock.NewController(t)
		db      = mock_contenttype.NewMockdber(ctrl)
		l       *log.Logger
		s       = contenttype.New(c.New(l, db, true), l, db)
		s       = contenttype.New(c.New(l, db, true, "test"), l, db)
		ts      = httptest.NewServer(s)
		methods = []string{"GET", "POST", "PATCH", "DELETE"}
	)


@@ 199,7 199,7 @@ func TestContentTypeHappyPath(t *testing.T) {
			ctrl = gomock.NewController(t)
			db   = mock_contenttype.NewMockdber(ctrl)
			l    *log.Logger
			s    = contenttype.New(c.New(l, db, true), l, db)
			s    = contenttype.New(c.New(l, db, true, "test"), l, db)
			ts   = httptest.NewServer(s)
		)



@@ 374,7 374,7 @@ func TestContentTypeBadPath(t *testing.T) {
			ctrl = gomock.NewController(t)
			db   = mock_contenttype.NewMockdber(ctrl)
			l    *log.Logger
			s    = contenttype.New(c.New(l, db, true), l, db)
			s    = contenttype.New(c.New(l, db, true, "test"), l, db)
			ts   = httptest.NewServer(s)
		)


M internal/c/doc/doc_test.go => internal/c/doc/doc_test.go +4 -4
@@ 19,7 19,7 @@ func TestWithoutUser(t *testing.T) {
	var (
		ctrl = gomock.NewController(t)
		db   = doc.NewMockdber(ctrl)
		s    = doc.New(c.New(nil, db, true), nil, db)
		s    = doc.New(c.New(nil, db, true, "test"), nil, db)
		ts   = httptest.NewServer(s)
	)



@@ 41,7 41,7 @@ func TestWithUser(t *testing.T) {
	var (
		ctrl = gomock.NewController(t)
		db   = doc.NewMockdber(ctrl)
		s    = doc.New(c.New(nil, db, true), nil, db)
		s    = doc.New(c.New(nil, db, true, "test"), nil, db)
		ts   = httptest.NewServer(s)
	)



@@ 59,7 59,7 @@ func TestWithInvalidUserToken(t *testing.T) {
	var (
		ctrl = gomock.NewController(t)
		db   = doc.NewMockdber(ctrl)
		s    = doc.New(c.New(nil, db, true), nil, db)
		s    = doc.New(c.New(nil, db, true, "test"), nil, db)
		ts   = httptest.NewServer(s)
		u    = FakeUser{}
		tok  = u.Token()


@@ 84,7 84,7 @@ func TestNotFound(t *testing.T) {
	var (
		ctrl = gomock.NewController(t)
		db   = doc.NewMockdber(ctrl)
		s    = doc.New(c.New(nil, db, true), nil, db)
		s    = doc.New(c.New(nil, db, true, "test"), nil, db)
		ts   = httptest.NewServer(s)
	)


M internal/c/file/file_test.go => internal/c/file/file_test.go +3 -3
@@ 21,7 21,7 @@ func TestProxyGood(t *testing.T) {
		ctrl  = gomock.NewController(t)
		db    = file.NewMockDBer(ctrl)
		e3    = file.NewMockE3er(ctrl)
		s     = file.New(c.New(nil, db, true), nil, db, e3, E3.DefaultURL)
		s     = file.New(c.New(nil, db, true, "test"), nil, db, e3, E3.DefaultURL)
		ts    = httptest.NewServer(s)
		fp    = "/file/some-file.jpg"
		url   = strings.TrimRight(E3.DefaultURL, "api") + "some-file.jpg"


@@ 44,7 44,7 @@ func TestProxyBad(t *testing.T) {
		ctrl = gomock.NewController(t)
		db   = file.NewMockDBer(ctrl)
		e3   = file.NewMockE3er(ctrl)
		s    = file.New(c.New(nil, db, true), nil, db, e3, E3.DefaultURL)
		s    = file.New(c.New(nil, db, true, "test"), nil, db, e3, E3.DefaultURL)
		ts   = httptest.NewServer(s)
		fp   = "/file/some-file.jpg"
		url  = strings.TrimRight(E3.DefaultURL, "api") + "some-file.jpg"


@@ 67,7 67,7 @@ func TestFileDoesNotExit(t *testing.T) {
		ctrl = gomock.NewController(t)
		db   = file.NewMockDBer(ctrl)
		e3   = file.NewMockE3er(ctrl)
		s    = file.New(c.New(nil, db, true), nil, db, e3, E3.DefaultURL)
		s    = file.New(c.New(nil, db, true, "test"), nil, db, e3, E3.DefaultURL)
		ts   = httptest.NewServer(s)
		fp   = "/file/some-file.jpg"
		err  = errors.New("placeholder")

M internal/c/hook/hook_test.go => internal/c/hook/hook_test.go +4 -4
@@ 26,7 26,7 @@ func TestNoUser(t *testing.T) {
		ctrl    = gomock.NewController(t)
		db      = mock_hook.NewMockdber(ctrl)
		l       *log.Logger
		s       = hook.New(c.New(l, db, true), l, db)
		s       = hook.New(c.New(l, db, true, "test"), l, db)
		ts      = httptest.NewServer(s)
		methods = []string{"GET", "POST", "PUT", "PATCH", "DELETE"}
	)


@@ 120,7 120,7 @@ func TestHookHappyPath(t *testing.T) {
			ctrl = gomock.NewController(t)
			db   = mock_hook.NewMockdber(ctrl)
			l    *log.Logger
			s    = hook.New(c.New(l, db, true), l, db)
			s    = hook.New(c.New(l, db, true, "test"), l, db)
			ts   = httptest.NewServer(s)
		)



@@ 283,7 283,7 @@ func TestHookBadPaths(t *testing.T) {
			ctrl = gomock.NewController(t)
			db   = mock_hook.NewMockdber(ctrl)
			l    *log.Logger
			s    = hook.New(c.New(l, db, true), l, db)
			s    = hook.New(c.New(l, db, true, "test"), l, db)
			ts   = httptest.NewServer(s)
		)



@@ 331,7 331,7 @@ func TestHookWeirdPath(t *testing.T) {
			ctrl = gomock.NewController(t)
			db   = mock_hook.NewMockdber(ctrl)
			l    *log.Logger
			s    = hook.New(c.New(l, db, true), l, db)
			s    = hook.New(c.New(l, db, true, "test"), l, db)
			ts   = httptest.NewServer(s)
		)


M internal/c/redirect/redirect_test.go => internal/c/redirect/redirect_test.go +1 -1
@@ 19,7 19,7 @@ func TestRedirect(t *testing.T) {
		ctrl = gomock.NewController(t)
		db   = redirect.NewMockdber(ctrl)
		l    *log.Logger
		s    = redirect.New(c.New(l, db, true), l, db)
		s    = redirect.New(c.New(l, db, true, "test"), l, db)
		ts   = httptest.NewServer(s)
	)


M internal/c/space/space_test.go => internal/c/space/space_test.go +2 -2
@@ 78,7 78,7 @@ func TestNoUser(t *testing.T) {
		ctrl    = gomock.NewController(t)
		db      = mock_space.NewMockdber(ctrl)
		l       *log.Logger
		s       = space.New(c.New(l, db, true), l, db)
		s       = space.New(c.New(l, db, true, "test"), l, db)
		ts      = httptest.NewServer(s)
		methods = []string{"GET", "POST", "PUT", "PATCH", "DELETE"}
	)


@@ 225,7 225,7 @@ func TestAll(t *testing.T) {
			ctrl = gomock.NewController(t)
			db   = mock_space.NewMockdber(ctrl)
			l    = log.New(bytes.NewBufferString(os.DevNull), "", 0)
			s    = space.New(c.New(l, db, true), l, db)
			s    = space.New(c.New(l, db, true, "test"), l, db)
			ts   = httptest.NewServer(s)
		)


M internal/c/user/mock.go => internal/c/user/mock.go +29 -0
@@ 80,6 80,21 @@ func (mr *MockdberMockRecorder) UserGetFromToken(token interface{}) *gomock.Call
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UserGetFromToken", reflect.TypeOf((*Mockdber)(nil).UserGetFromToken), token)
}

// UserSetEmail mocks base method
func (m *Mockdber) UserSetEmail(u user.User, email string) (user.User, error) {
	m.ctrl.T.Helper()
	ret := m.ctrl.Call(m, "UserSetEmail", u, email)
	ret0, _ := ret[0].(user.User)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}

// UserSetEmail indicates an expected call of UserSetEmail
func (mr *MockdberMockRecorder) UserSetEmail(u, email interface{}) *gomock.Call {
	mr.mock.ctrl.T.Helper()
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UserSetEmail", reflect.TypeOf((*Mockdber)(nil).UserSetEmail), u, email)
}

// SpacesPerUser mocks base method
func (m *Mockdber) SpacesPerUser(user user.User, before int) (space.SpaceList, error) {
	m.ctrl.T.Helper()


@@ 133,3 148,17 @@ func (mr *MockStriperMockRecorder) StartCheckout(user, t interface{}) *gomock.Ca
	mr.mock.ctrl.T.Helper()
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartCheckout", reflect.TypeOf((*MockStriper)(nil).StartCheckout), user, t)
}

// CancelSubscription mocks base method
func (m *MockStriper) CancelSubscription(user user.User) error {
	m.ctrl.T.Helper()
	ret := m.ctrl.Call(m, "CancelSubscription", user)
	ret0, _ := ret[0].(error)
	return ret0
}

// CancelSubscription indicates an expected call of CancelSubscription
func (mr *MockStriperMockRecorder) CancelSubscription(user interface{}) *gomock.Call {
	mr.mock.ctrl.T.Helper()
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CancelSubscription", reflect.TypeOf((*MockStriper)(nil).CancelSubscription), user)
}

M internal/c/user/user_test.go => internal/c/user/user_test.go +9 -9
@@ 38,7 38,7 @@ func TestCreate(t *testing.T) {
		db     = user.NewMockdber(ctrl)
		l      *log.Logger
		stripe = user.NewMockStriper(ctrl)
		s      = user.New(c.New(l, db, true), l, db, true, stripe)
		s      = user.New(c.New(l, db, true, "test"), l, db, true, stripe)
		ts     = httptest.NewServer(s)

		uname = uuid.New().String()


@@ 67,7 67,7 @@ func TestLogin(t *testing.T) {
		db     = user.NewMockdber(ctrl)
		l      *log.Logger
		stripe = user.NewMockStriper(ctrl)
		s      = user.New(c.New(l, db, true), l, db, true, stripe)
		s      = user.New(c.New(l, db, true, "test"), l, db, true, stripe)
		ts     = httptest.NewServer(s)

		uname = uuid.New().String()


@@ 94,7 94,7 @@ func TestLogout(t *testing.T) {
		db     = user.NewMockdber(ctrl)
		l      *log.Logger
		stripe = user.NewMockStriper(ctrl)
		s      = user.New(c.New(l, db, true), l, db, true, stripe)
		s      = user.New(c.New(l, db, true, "test"), l, db, true, stripe)
		ts     = httptest.NewServer(s)
	)



@@ 110,7 110,7 @@ func TestHome(t *testing.T) {
		db     = user.NewMockdber(ctrl)
		l      *log.Logger
		stripe = user.NewMockStriper(ctrl)
		s      = user.New(c.New(l, db, true), l, db, true, stripe)
		s      = user.New(c.New(l, db, true, "test"), l, db, true, stripe)
		ts     = httptest.NewServer(s)

		uname = uuid.New().String()


@@ 149,7 149,7 @@ func TestBadLogin(t *testing.T) {
		db     = user.NewMockdber(ctrl)
		l      *log.Logger
		stripe = user.NewMockStriper(ctrl)
		s      = user.New(c.New(l, db, true), l, db, true, stripe)
		s      = user.New(c.New(l, db, true, "test"), l, db, true, stripe)
		ts     = httptest.NewServer(s)

		uname = uuid.New().String()


@@ 161,7 161,7 @@ func TestBadLogin(t *testing.T) {
		}
	)

	db.EXPECT().UserGet(uname, upass).Return(nil, user.ErrNoUser).AnyTimes()
	db.EXPECT().UserGet(uname, upass).Return(nil, c.ErrNoLogin).AnyTimes()

	res, _ := http.PostForm(ts.URL+"/user/login", form)
	assert.Equal(t, res.StatusCode, http.StatusBadRequest)


@@ 175,7 175,7 @@ func TestNoSignups(t *testing.T) {
		db     = user.NewMockdber(ctrl)
		l      *log.Logger
		stripe = user.NewMockStriper(ctrl)
		s      = user.New(c.New(l, db, true), l, db, false, stripe)
		s      = user.New(c.New(l, db, true, "test"), l, db, false, stripe)
		ts     = httptest.NewServer(s)

		uname = uuid.New().String()


@@ 203,7 203,7 @@ func TestCreatePaid(t *testing.T) {
		db     = user.NewMockdber(ctrl)
		l      *log.Logger
		stripe = user.NewMockStriper(ctrl)
		s      = user.New(c.New(l, db, true), l, db, true, stripe)
		s      = user.New(c.New(l, db, true, "test"), l, db, true, stripe)
		ts     = httptest.NewServer(s)

		uname = uuid.New().String()


@@ 233,7 233,7 @@ func TestHomeNoUser(t *testing.T) {
		db     = user.NewMockdber(ctrl)
		l      *log.Logger
		stripe = user.NewMockStriper(ctrl)
		s      = user.New(c.New(l, db, true), l, db, true, stripe)
		s      = user.New(c.New(l, db, true, "test"), l, db, true, stripe)
		ts     = httptest.NewServer(s)

		uname = uuid.New().String()

M makefile => makefile +1 -7
@@ 25,13 25,7 @@ coverage:
	@env $(ENV) go test ./... -cover -coverprofile=coverage.out ; go tool cover -html=coverage.out

lint: 
	@env $(ENV) go vet ./...
	# TODO: This encounters a runtime error. Submit issue to golangci-lint?
	# Investigate?
	# @env $(ENV) golangci-lint run --no-config --issues-exit-code=0 \
	# --disable-all --enable=deadcode  --enable=gocyclo --enable=golint --enable=varcheck \
	# --enable=structcheck --enable=maligned --enable=errcheck --enable=dupl --enable=ineffassign \
	# --enable=interfacer --enable=unconvert --enable=goconst --enable=gosec --enable=megacheck
	@find * -not -name '*_embed.go' | grep -E '*.(sql|go|js|css|html)' | entr -cr go vet ./...

run: gen build
	@clear