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 TestUserGetByIDSuccess(t *testing.T) { | |
const ( | |
expectedEmail = "john.doe@gmail.com" | |
expectedID = uint(1) | |
) | |
testMock, assertion := setUp(t) | |
returnRows := mockRows() | |
// Query: SELECT * FROM users WHERE deleted_at IS NULL AND id = '$1' ORDER BY id ASC LIMIT 1 | |
testMock.ExpectQuery("^SELECT (.+) FROM \"users\".+$").WillReturnRows(returnRows) | |
userRepo := new(UserRepositoryImpl) |
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 setUp(t *testing.T) (sqlmock.Sqlmock, *assert.Assertions) { | |
mock := setUpMockDB() | |
assertions := assert.New(t) | |
return mock, assertions | |
} | |
//Mock the DB for the test | |
func setUpMockDB() sqlmock.Sqlmock { | |
mockDB, mock, _ := sqlmock.New() | |
gormMockDB, _ := gorm.Open("postgres", mockDB) |
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
//GetByID ... | |
func (u UserRepositoryImpl) GetByID(id uint) (models.User, error) { | |
var selectedUser models.User | |
err := models.GetDB().Where("id = ?", id).First(&selectedUser).Error | |
return selectedUser, err | |
} |
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
class LoRA(torch.nn.Module): | |
def __freeze_params(self, weight): | |
for param in weight.parameters(): | |
param.requires_grad = False | |
def __init__(self, weight, in_dim: int, downproj_coeff: int, out_dim: int, scaler_coeff: float = 0.1, use_bias: bool = True): | |
super(LoRA, self).__init__() | |
self.weight = weight | |
self.__freeze_params(self.weight) | |
self.in_dim = in_dim |