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

testutil: add Session #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

testutil: add Session #235

wants to merge 1 commit into from

Conversation

System-Glitch
Copy link
Member

References

Issue(s): closes #233

Description

testutil.Session is a new testing utility used to mock the session.Session interface. This implementation is designed to provide a realistic, observable transaction system and help identify incorrect usage. You can find more details in the godoc on the testutil.Session struct.

Usage example:

session := testutil.NewTestSession()
service := NewService(repo, session)

createDTO := &dto.CreateUserRequest{
	//...
}
created, err := service.Create(context.Background(), createDTO)
require.NoError(t, err)
expected := &dto.User{
	//...
}
assert.Equal(t, expected, created)

txs := session.Children()
if assert.Len(t, txs, 1) {
	assert.Equal(t, testutil.SessionCommitted, txs[0].Status())
}

Possible drawbacks

  • The incorrect session usage detection is quite strict and may force developers to write their services in a certain way. On the other hand, this sounds good to me because code that doesn't meet these criteria would be flawed anyway and wouldn't be reliable. Please feel free to add some feedback regarding this.

@System-Glitch System-Glitch added the feature request Request for new feature implementation label Nov 26, 2024
@System-Glitch System-Glitch self-assigned this Nov 26, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 12034777957

Details

  • 88 of 90 (97.78%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 97.475%

Changes Missing Coverage Covered Lines Changed/Added Lines %
util/testutil/session.go 88 90 97.78%
Totals Coverage Status
Change from base Build 12014896572: 0.005%
Covered Lines: 6407
Relevant Lines: 6573

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for new feature implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

testutil: mock session.Session
2 participants