mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-01 09:32:35 +02:00

Some checks are pending
Docker Image CI (socket-proxy) / build (push) Waiting to run
* refactor: simplify io code and make utils module independent * fix(docker): agent and socket-proxy docker event flushing with modified reverse proxy handler * refactor: remove unused code * refactor: remove the use of logging module in most code * refactor: streamline domain mismatch check in certState function * tweak: use ecdsa p-256 for autocert * fix(tests): update health check tests for invalid host and add case for port in host * feat(acme): custom acme directory * refactor: code refactor and improved context and error handling * tweak: optimize memory usage under load * fix(oidc): restore old user matching behavior * docs: add ChatGPT assistant to README --------- Co-authored-by: yusing <yusing@6uo.me>
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package expect
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var isTest = strings.HasSuffix(os.Args[0], ".test")
|
|
|
|
func init() {
|
|
if isTest {
|
|
// force verbose output
|
|
os.Args = append([]string{os.Args[0], "-test.v"}, os.Args[1:]...)
|
|
}
|
|
}
|
|
|
|
func Must[Result any](r Result, err error) Result {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return r
|
|
}
|
|
|
|
var (
|
|
NoError = require.NoError
|
|
HasError = require.Error
|
|
True = require.True
|
|
False = require.False
|
|
Nil = require.Nil
|
|
NotNil = require.NotNil
|
|
ErrorContains = require.ErrorContains
|
|
Panics = require.Panics
|
|
Greater = require.Greater
|
|
Less = require.Less
|
|
GreaterOrEqual = require.GreaterOrEqual
|
|
LessOrEqual = require.LessOrEqual
|
|
)
|
|
|
|
func ErrorIs(t *testing.T, expected error, err error, msgAndArgs ...any) {
|
|
t.Helper()
|
|
require.ErrorIs(t, err, expected, msgAndArgs...)
|
|
}
|
|
|
|
func ErrorT[T error](t *testing.T, err error, msgAndArgs ...any) {
|
|
t.Helper()
|
|
var errAs T
|
|
require.ErrorAs(t, err, &errAs, msgAndArgs...)
|
|
}
|
|
|
|
func Equal[T any](t *testing.T, got T, want T, msgAndArgs ...any) {
|
|
t.Helper()
|
|
require.EqualValues(t, want, got, msgAndArgs...)
|
|
}
|
|
|
|
func NotEqual[T any](t *testing.T, got T, want T, msgAndArgs ...any) {
|
|
t.Helper()
|
|
require.NotEqual(t, want, got, msgAndArgs...)
|
|
}
|
|
|
|
func Contains[T any](t *testing.T, got T, wants []T, msgAndArgs ...any) {
|
|
t.Helper()
|
|
require.Contains(t, wants, got, msgAndArgs...)
|
|
}
|
|
|
|
func Type[T any](t *testing.T, got any, msgAndArgs ...any) (_ T) {
|
|
t.Helper()
|
|
_, ok := got.(T)
|
|
require.True(t, ok, msgAndArgs...)
|
|
return got.(T)
|
|
}
|