Switch to mirrorred images for Drone and Docker, make linters happy.
All checks were successful
continuous-integration/drone Build is passing
All checks were successful
continuous-integration/drone Build is passing
This commit is contained in:
parent
389c15f1f7
commit
d26b8f4262
10
.drone.yml
10
.drone.yml
@ -5,32 +5,32 @@ name: build
|
||||
|
||||
steps:
|
||||
- name: lint
|
||||
image: golangci/golangci-lint:v1.43.0
|
||||
image: code.pztrn.name/containers/mirror/golangci/golangci-lint:v1.46.2
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
commands:
|
||||
- golangci-lint run
|
||||
|
||||
- name: test
|
||||
image: golang:1.17.3-alpine
|
||||
image: code.pztrn.name/containers/mirror/golang:1.18.3-alpine
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
commands:
|
||||
- go test -test.v ./...
|
||||
|
||||
- name: test-race
|
||||
image: golang:1.17.3-stretch
|
||||
image: code.pztrn.name/containers/mirror/golang:1.18.3-bullseye
|
||||
commands:
|
||||
- go test -race -test.v ./...
|
||||
|
||||
- name: benchmark
|
||||
image: golang:1.17.3-alpine
|
||||
image: code.pztrn.name/containers/mirror/golang:1.18.3-alpine
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
commands:
|
||||
- go test -benchmem -run=^$ go.dev.pztrn.name/valiwork -bench .
|
||||
|
||||
- name: benchmark-race
|
||||
image: golang:1.17.3-stretch
|
||||
image: code.pztrn.name/containers/mirror/golang:1.18.3-bullseye
|
||||
commands:
|
||||
- go test -benchmem -run=^$ go.dev.pztrn.name/valiwork -race -bench .
|
||||
|
5
debug.go
5
debug.go
@ -23,14 +23,11 @@
|
||||
package valiwork
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var (
|
||||
DEBUG bool
|
||||
)
|
||||
var DEBUG bool
|
||||
|
||||
// Initializes debug output.
|
||||
// nolint
|
||||
|
@ -23,12 +23,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
// stdlib
|
||||
"errors"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
// other
|
||||
"go.dev.pztrn.name/valiwork"
|
||||
)
|
||||
|
||||
@ -51,6 +49,7 @@ func stringValidator(thing interface{}, optional ...interface{}) []interface{} {
|
||||
stringToValidate, ok := thing.(string)
|
||||
if !ok {
|
||||
errs = append(errs, errors.New("passed value is not a string"))
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
|
@ -23,16 +23,12 @@
|
||||
package valiwork
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
|
||||
// local
|
||||
"go.dev.pztrn.name/valiwork/validators"
|
||||
)
|
||||
|
||||
var (
|
||||
registeredValidators map[string]validators.ValidatorFunc
|
||||
)
|
||||
var registeredValidators map[string]validators.ValidatorFunc
|
||||
|
||||
// nolint
|
||||
func init() {
|
||||
@ -74,6 +70,7 @@ func Validate(thing interface{}, validatorName string, optional ...interface{})
|
||||
|
||||
if !found {
|
||||
errs = append(errs, ErrValidatorNotRegistered)
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
|
@ -23,30 +23,27 @@
|
||||
package valiwork
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
// local
|
||||
"go.dev.pztrn.name/valiwork/validators"
|
||||
|
||||
// other
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.dev.pztrn.name/valiwork/validators"
|
||||
)
|
||||
|
||||
const (
|
||||
testString = " I am test $tring"
|
||||
)
|
||||
|
||||
// nolint:paralleltest
|
||||
func TestRegisterValidator(t *testing.T) {
|
||||
initializeValidatorsStorage()
|
||||
|
||||
testCases := []struct {
|
||||
ValidatorName string
|
||||
ValidatorFunc validators.ValidatorFunc
|
||||
ValidatorName string
|
||||
ShouldFail bool
|
||||
}{
|
||||
{
|
||||
@ -92,10 +89,10 @@ func BenchmarkRegisterValidator(b *testing.B) {
|
||||
func BenchmarkRegisterValidatorAsync(b *testing.B) {
|
||||
initializeValidatorsStorage()
|
||||
|
||||
var w sync.WaitGroup
|
||||
var waiter sync.WaitGroup
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
w.Add(1)
|
||||
waiter.Add(1)
|
||||
|
||||
go func() {
|
||||
_ = RegisterValidator("string_test_validator_"+strconv.Itoa(i),
|
||||
@ -104,13 +101,14 @@ func BenchmarkRegisterValidatorAsync(b *testing.B) {
|
||||
},
|
||||
)
|
||||
|
||||
w.Done()
|
||||
waiter.Done()
|
||||
}()
|
||||
|
||||
w.Wait()
|
||||
waiter.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
// nolint:paralleltest
|
||||
func TestValidate(t *testing.T) {
|
||||
initializeValidatorsStorage()
|
||||
|
||||
@ -120,6 +118,7 @@ func TestValidate(t *testing.T) {
|
||||
stringToValidate, ok := thing.(string)
|
||||
if !ok {
|
||||
errs = append(errs, errors.New("not a string"))
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
@ -146,6 +145,7 @@ func BenchmarkValidate(b *testing.B) {
|
||||
stringToValidate, ok := thing.(string)
|
||||
if !ok {
|
||||
errs = append(errs, errors.New("not a string"))
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
@ -178,6 +178,7 @@ func BenchmarkValidateAsync(b *testing.B) {
|
||||
stringToValidate, ok := thing.(string)
|
||||
if !ok {
|
||||
errs = append(errs, errors.New("not a string"))
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
@ -194,21 +195,22 @@ func BenchmarkValidateAsync(b *testing.B) {
|
||||
|
||||
b.StartTimer()
|
||||
|
||||
var w sync.WaitGroup
|
||||
var waiter sync.WaitGroup
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
w.Add(1)
|
||||
waiter.Add(1)
|
||||
|
||||
go func() {
|
||||
_ = Validate(testString, "string_test1")
|
||||
|
||||
w.Done()
|
||||
waiter.Done()
|
||||
}()
|
||||
|
||||
w.Wait()
|
||||
waiter.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
// nolint:paralleltest
|
||||
func TestValidateMany(t *testing.T) {
|
||||
initializeValidatorsStorage()
|
||||
|
||||
@ -218,6 +220,7 @@ func TestValidateMany(t *testing.T) {
|
||||
stringToValidate, ok := thing.(string)
|
||||
if !ok {
|
||||
errs = append(errs, errors.New("not a string"))
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
@ -234,6 +237,7 @@ func TestValidateMany(t *testing.T) {
|
||||
stringToValidate, ok := thing.(string)
|
||||
if !ok {
|
||||
errs = append(errs, errors.New("not a string"))
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
@ -260,6 +264,7 @@ func BenchmarkValidateMany(b *testing.B) {
|
||||
stringToValidate, ok := thing.(string)
|
||||
if !ok {
|
||||
errs = append(errs, errors.New("not a string"))
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
@ -276,6 +281,7 @@ func BenchmarkValidateMany(b *testing.B) {
|
||||
stringToValidate, ok := thing.(string)
|
||||
if !ok {
|
||||
errs = append(errs, errors.New("not a string"))
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
@ -304,6 +310,7 @@ func BenchmarkValidateManyAsync(b *testing.B) {
|
||||
stringToValidate, ok := thing.(string)
|
||||
if !ok {
|
||||
errs = append(errs, errors.New("not a string"))
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
@ -320,6 +327,7 @@ func BenchmarkValidateManyAsync(b *testing.B) {
|
||||
stringToValidate, ok := thing.(string)
|
||||
if !ok {
|
||||
errs = append(errs, errors.New("not a string"))
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
@ -332,27 +340,28 @@ func BenchmarkValidateManyAsync(b *testing.B) {
|
||||
|
||||
b.StartTimer()
|
||||
|
||||
var w sync.WaitGroup
|
||||
var waiter sync.WaitGroup
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
w.Add(1)
|
||||
waiter.Add(1)
|
||||
|
||||
go func() {
|
||||
_ = ValidateMany(testString, []string{"string_test1", "string_test2"}, nil)
|
||||
|
||||
w.Done()
|
||||
waiter.Done()
|
||||
}()
|
||||
|
||||
w.Wait()
|
||||
waiter.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
// nolint:paralleltest
|
||||
func TestUnregisterValidator(t *testing.T) {
|
||||
initializeValidatorsStorage()
|
||||
|
||||
testCases := []struct {
|
||||
ValidatorName string
|
||||
ValidatorFunc validators.ValidatorFunc
|
||||
ValidatorName string
|
||||
}{
|
||||
{
|
||||
ValidatorName: "string_test_validator",
|
||||
@ -371,6 +380,7 @@ func TestUnregisterValidator(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// nolint:paralleltest
|
||||
func TestUnregisterValidatorNotRegisteredValidator(t *testing.T) {
|
||||
initializeValidatorsStorage()
|
||||
|
||||
@ -411,19 +421,19 @@ func BenchmarkUnregisterValidatorAsync(b *testing.B) {
|
||||
)
|
||||
}
|
||||
|
||||
var w sync.WaitGroup
|
||||
var waiter sync.WaitGroup
|
||||
|
||||
b.StartTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
w.Add(1)
|
||||
waiter.Add(1)
|
||||
|
||||
go func() {
|
||||
_ = UnregisterValidator("string_test_validator_" + strconv.Itoa(i))
|
||||
|
||||
w.Done()
|
||||
waiter.Done()
|
||||
}()
|
||||
|
||||
w.Wait()
|
||||
waiter.Wait()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user