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 April 24, 2024 07:56
Comparison of golang mocking libraries

Comparison of golang mocking libraries

Updated 2024-04-21

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

Library

GitHub stars [![s6]][6] [![s2]][2] + [![s3]][3] [![s4]][4] [![s5]][5] [![s1]][1]
Latest release date [![d6]][r6] [![d2]][r2] + [![d3]][r3] [![d4]][r4] [![d5]][r5] [![d1]][r1]
Maintained :white_check
@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 April 3, 2024 12:22
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 April 24, 2024 16:59
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.57.2
#
# 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 """