Skip to content

Instantly share code, notes, and snippets.

@maratori
maratori / testmain_test.go
Created July 29, 2022 21:33
TestMain to print logs if failed
package componenttests
import (
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"
)
@maratori
maratori / test_clock.go
Last active October 27, 2022 21:50
Mockable time for golang
package clock
import (
"fmt"
"sync"
"sync/atomic"
"time"
)
// Clock should be used instead of [time.Now], [time.After],
@maratori
maratori / db_in_transaction.go
Created July 29, 2022 20:43
db.InTransaction
package db
import (
"context"
"database/sql"
"sync"
"github.com/pkg/errors"
"go.uber.org/multierr"
)
@maratori
maratori / golang-mocks.md
Last active November 15, 2024 15:39
Comparison of golang mocking libraries

Comparison of golang mocking libraries

Updated 2024-09-01

[gomock][1] [testify][2] + [mockery][3] [mockio][4] [minimock][5] [moq][6]

Library

GitHub stars [![s1]][1] [![s2]][2] + [![s3]][3] [![s4]][4] [![s5]][5] [![s6]][6]
Latest release date [![d1]][r1] [![d2]][r2] + [![d3]][r3] [![d4]][r4] [![d5]][r5] [![d6]][r6]
Maintained
@maratori
maratori / wait_for.py
Created September 30, 2021 23:06
Helper function for python tests to get rid of time.sleep
import time
from typing import Callable, Iterable, TypeVar, Optional
T = TypeVar('T')
def wait_for(
fn: Callable[..., T],
message: str = "",
messageSupplier: Optional[Callable[[], str]] = None,
@maratori
maratori / clone_postgres_schema_test.go
Last active May 11, 2024 06:50
Clone postgres schema for each test
package my_package_test
import (
"fmt"
"testing"
"github.com/gtforge/global_payment_manager_service/testdb"
"github.com/stretchr/testify/require"
)
@maratori
maratori / .golangci.yml
Last active November 15, 2024 14:06
Golden config for golangci-lint
# This code is licensed under the terms of the MIT license https://opensource.org/license/mit
# Copyright (c) 2021 Marat Reymers
## Golden config for golangci-lint v1.62.0
#
# This is the best config for golangci-lint based on my experience and opinion.
# It is very strict, but not extremely strict.
# Feel free to adapt and change it for your needs.
run:
@maratori
maratori / wait_for.go
Last active October 27, 2022 22:23
func WaitFor() the best alternative for assert.Eventually()
package testhelpers
import (
"sync"
"time"
)
// WaitFor calls fn (once in tick) until it passes or timeout expired.
//
// Attempt is failed if any of following methods called in fn:
@maratori
maratori / hackSafariDriver.py
Created September 17, 2018 09:21
Workaround for bug in SafariDriver with overflow hidden
import allure
from selene.abctypes.webelement import IWebElement
from selene.browser import execute_script
from selene.conditions import Visible
from selene.exceptions import ConditionMismatchException
@allure.step("Hack selene library to introduce workaroud bug in SafariDriver")
def hackSafariDriver():
""" Workaround for bug https://github.com/SeleniumHQ/selenium/issues/4456 """