Last active
June 6, 2021 21:26
-
-
Save agusrichard/c279a0a899d60c1075c258cd0956ba94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type tweetRepositorySuite struct { | |
| // we need this to use the suite functionalities from testify | |
| suite.Suite | |
| // the funcionalities we need to test | |
| repository TweetRepository | |
| // some helper function to clean-up any used tables | |
| cleanupExecutor utils.TruncateTableExecutor | |
| } | |
| func (suite *tweetRepositorySuite) SetupSuite() { | |
| // this function runs once before all tests in the suite | |
| // some initialization setup | |
| configs := config.GetConfig() | |
| db := config.ConnectDB(configs) | |
| repository := InitializeTweetRepository(db) | |
| // assign the dependencies we need as the suite properties | |
| // we need this to run the tests | |
| suite.repository = repository | |
| suite.cleanupExecutor = utils.InitTruncateTableExecutor(db) | |
| } | |
| func (suite *tweetRepositorySuite) TearDownTest() { | |
| // clean-up the used table to be used for another session | |
| defer suite.cleanupExecutor.TruncateTable([]string{"tweets"}) | |
| } | |
| func (suite *tweetRepositorySuite) TestCreateTweet_Positive() { | |
| // instantiate an entity to be used by the function we want to test | |
| tweet := entities.Tweet{ | |
| Username: "username", | |
| Text: "text", | |
| } | |
| // real function we need to test | |
| err := suite.repository.CreateTweet(&tweet) | |
| // assertion for the result of our test | |
| suite.NoError(err, "no error when create tweet with valid input") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment