Skip to content

Instantly share code, notes, and snippets.

View codefire53's full-sized avatar

Mahardika Krisna Ihsani codefire53

View GitHub Profile
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)
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)
//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
}
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