Created
May 1, 2021 12:19
-
-
Save utkarshmani1997/e72023e83a163edd5330e311cfdcba13 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
func TestInsertUser(t *testing.T) { | |
mockCtl := gomock.NewController(t) | |
defer mockCtl.Finish() | |
mockUser := mock_database.NewMockUsers(mockCtl) | |
gomock.InOrder( | |
mockUser.EXPECT().Insert().Return(0, fmt.Errorf("%v", "insert error")).Times(1), | |
mockUser.EXPECT().Insert().Return(5, nil).Times(1), | |
) | |
_, err := insertUser(mockUser) | |
if err == nil { | |
t.Fatal(err) | |
} | |
id, err := insertUser(mockUser) | |
if err != nil { | |
t.Fatal(err) | |
} | |
if id != 5 { | |
t.Fatalf("Expected id: %d, got: %d", 5, id) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment