Switch to mirrorred images for Drone and Docker, make linters happy.
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Stanislav Nikitin 2022-06-29 15:32:54 +05:00
parent 389c15f1f7
commit d26b8f4262
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
6 changed files with 44 additions and 42 deletions

View File

@ -5,32 +5,32 @@ name: build
steps: steps:
- name: lint - name: lint
image: golangci/golangci-lint:v1.43.0 image: code.pztrn.name/containers/mirror/golangci/golangci-lint:v1.46.2
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
commands: commands:
- golangci-lint run - golangci-lint run
- name: test - name: test
image: golang:1.17.3-alpine image: code.pztrn.name/containers/mirror/golang:1.18.3-alpine
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
commands: commands:
- go test -test.v ./... - go test -test.v ./...
- name: test-race - name: test-race
image: golang:1.17.3-stretch image: code.pztrn.name/containers/mirror/golang:1.18.3-bullseye
commands: commands:
- go test -race -test.v ./... - go test -race -test.v ./...
- name: benchmark - name: benchmark
image: golang:1.17.3-alpine image: code.pztrn.name/containers/mirror/golang:1.18.3-alpine
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
commands: commands:
- go test -benchmem -run=^$ go.dev.pztrn.name/valiwork -bench . - go test -benchmem -run=^$ go.dev.pztrn.name/valiwork -bench .
- name: benchmark-race - name: benchmark-race
image: golang:1.17.3-stretch image: code.pztrn.name/containers/mirror/golang:1.18.3-bullseye
commands: commands:
- go test -benchmem -run=^$ go.dev.pztrn.name/valiwork -race -bench . - go test -benchmem -run=^$ go.dev.pztrn.name/valiwork -race -bench .

View File

@ -23,14 +23,11 @@
package valiwork package valiwork
import ( import (
// stdlib
"os" "os"
"strconv" "strconv"
) )
var ( var DEBUG bool
DEBUG bool
)
// Initializes debug output. // Initializes debug output.
// nolint // nolint

View File

@ -23,7 +23,6 @@
package valiwork package valiwork
import ( import (
// stdlib
"errors" "errors"
) )

View File

@ -23,12 +23,10 @@
package main package main
import ( import (
"strings"
// stdlib
"errors" "errors"
"log" "log"
"strings"
// other
"go.dev.pztrn.name/valiwork" "go.dev.pztrn.name/valiwork"
) )
@ -40,7 +38,7 @@ func main() {
log.Println("Starting validation example...") log.Println("Starting validation example...")
log.Println("WARN: to see additional valiwork output define 'VALIWORK_DEBUG' environment variable and set it to 'true'!") log.Println("WARN: to see additional valiwork output define 'VALIWORK_DEBUG' environment variable and set it to 'true'!")
//stringToValidate := " I am pretty b@d $tring" // stringToValidate := " I am pretty b@d $tring"
_ = valiwork.RegisterValidator(stringValidatorName, stringValidator) _ = valiwork.RegisterValidator(stringValidatorName, stringValidator)
} }
@ -51,6 +49,7 @@ func stringValidator(thing interface{}, optional ...interface{}) []interface{} {
stringToValidate, ok := thing.(string) stringToValidate, ok := thing.(string)
if !ok { if !ok {
errs = append(errs, errors.New("passed value is not a string")) errs = append(errs, errors.New("passed value is not a string"))
return errs return errs
} }

View File

@ -23,16 +23,12 @@
package valiwork package valiwork
import ( import (
// stdlib
"log" "log"
// local
"go.dev.pztrn.name/valiwork/validators" "go.dev.pztrn.name/valiwork/validators"
) )
var ( var registeredValidators map[string]validators.ValidatorFunc
registeredValidators map[string]validators.ValidatorFunc
)
// nolint // nolint
func init() { func init() {
@ -74,6 +70,7 @@ func Validate(thing interface{}, validatorName string, optional ...interface{})
if !found { if !found {
errs = append(errs, ErrValidatorNotRegistered) errs = append(errs, ErrValidatorNotRegistered)
return errs return errs
} }

View File

@ -23,30 +23,27 @@
package valiwork package valiwork
import ( import (
// stdlib
"errors" "errors"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"testing" "testing"
// local
"go.dev.pztrn.name/valiwork/validators"
// other
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.dev.pztrn.name/valiwork/validators"
) )
const ( const (
testString = " I am test $tring" testString = " I am test $tring"
) )
// nolint:paralleltest
func TestRegisterValidator(t *testing.T) { func TestRegisterValidator(t *testing.T) {
initializeValidatorsStorage() initializeValidatorsStorage()
testCases := []struct { testCases := []struct {
ValidatorName string
ValidatorFunc validators.ValidatorFunc ValidatorFunc validators.ValidatorFunc
ValidatorName string
ShouldFail bool ShouldFail bool
}{ }{
{ {
@ -92,10 +89,10 @@ func BenchmarkRegisterValidator(b *testing.B) {
func BenchmarkRegisterValidatorAsync(b *testing.B) { func BenchmarkRegisterValidatorAsync(b *testing.B) {
initializeValidatorsStorage() initializeValidatorsStorage()
var w sync.WaitGroup var waiter sync.WaitGroup
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
w.Add(1) waiter.Add(1)
go func() { go func() {
_ = RegisterValidator("string_test_validator_"+strconv.Itoa(i), _ = 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) { func TestValidate(t *testing.T) {
initializeValidatorsStorage() initializeValidatorsStorage()
@ -120,6 +118,7 @@ func TestValidate(t *testing.T) {
stringToValidate, ok := thing.(string) stringToValidate, ok := thing.(string)
if !ok { if !ok {
errs = append(errs, errors.New("not a string")) errs = append(errs, errors.New("not a string"))
return errs return errs
} }
@ -146,6 +145,7 @@ func BenchmarkValidate(b *testing.B) {
stringToValidate, ok := thing.(string) stringToValidate, ok := thing.(string)
if !ok { if !ok {
errs = append(errs, errors.New("not a string")) errs = append(errs, errors.New("not a string"))
return errs return errs
} }
@ -178,6 +178,7 @@ func BenchmarkValidateAsync(b *testing.B) {
stringToValidate, ok := thing.(string) stringToValidate, ok := thing.(string)
if !ok { if !ok {
errs = append(errs, errors.New("not a string")) errs = append(errs, errors.New("not a string"))
return errs return errs
} }
@ -194,21 +195,22 @@ func BenchmarkValidateAsync(b *testing.B) {
b.StartTimer() b.StartTimer()
var w sync.WaitGroup var waiter sync.WaitGroup
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
w.Add(1) waiter.Add(1)
go func() { go func() {
_ = Validate(testString, "string_test1") _ = Validate(testString, "string_test1")
w.Done() waiter.Done()
}() }()
w.Wait() waiter.Wait()
} }
} }
// nolint:paralleltest
func TestValidateMany(t *testing.T) { func TestValidateMany(t *testing.T) {
initializeValidatorsStorage() initializeValidatorsStorage()
@ -218,6 +220,7 @@ func TestValidateMany(t *testing.T) {
stringToValidate, ok := thing.(string) stringToValidate, ok := thing.(string)
if !ok { if !ok {
errs = append(errs, errors.New("not a string")) errs = append(errs, errors.New("not a string"))
return errs return errs
} }
@ -234,6 +237,7 @@ func TestValidateMany(t *testing.T) {
stringToValidate, ok := thing.(string) stringToValidate, ok := thing.(string)
if !ok { if !ok {
errs = append(errs, errors.New("not a string")) errs = append(errs, errors.New("not a string"))
return errs return errs
} }
@ -260,6 +264,7 @@ func BenchmarkValidateMany(b *testing.B) {
stringToValidate, ok := thing.(string) stringToValidate, ok := thing.(string)
if !ok { if !ok {
errs = append(errs, errors.New("not a string")) errs = append(errs, errors.New("not a string"))
return errs return errs
} }
@ -276,6 +281,7 @@ func BenchmarkValidateMany(b *testing.B) {
stringToValidate, ok := thing.(string) stringToValidate, ok := thing.(string)
if !ok { if !ok {
errs = append(errs, errors.New("not a string")) errs = append(errs, errors.New("not a string"))
return errs return errs
} }
@ -304,6 +310,7 @@ func BenchmarkValidateManyAsync(b *testing.B) {
stringToValidate, ok := thing.(string) stringToValidate, ok := thing.(string)
if !ok { if !ok {
errs = append(errs, errors.New("not a string")) errs = append(errs, errors.New("not a string"))
return errs return errs
} }
@ -320,6 +327,7 @@ func BenchmarkValidateManyAsync(b *testing.B) {
stringToValidate, ok := thing.(string) stringToValidate, ok := thing.(string)
if !ok { if !ok {
errs = append(errs, errors.New("not a string")) errs = append(errs, errors.New("not a string"))
return errs return errs
} }
@ -332,27 +340,28 @@ func BenchmarkValidateManyAsync(b *testing.B) {
b.StartTimer() b.StartTimer()
var w sync.WaitGroup var waiter sync.WaitGroup
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
w.Add(1) waiter.Add(1)
go func() { go func() {
_ = ValidateMany(testString, []string{"string_test1", "string_test2"}, nil) _ = ValidateMany(testString, []string{"string_test1", "string_test2"}, nil)
w.Done() waiter.Done()
}() }()
w.Wait() waiter.Wait()
} }
} }
// nolint:paralleltest
func TestUnregisterValidator(t *testing.T) { func TestUnregisterValidator(t *testing.T) {
initializeValidatorsStorage() initializeValidatorsStorage()
testCases := []struct { testCases := []struct {
ValidatorName string
ValidatorFunc validators.ValidatorFunc ValidatorFunc validators.ValidatorFunc
ValidatorName string
}{ }{
{ {
ValidatorName: "string_test_validator", ValidatorName: "string_test_validator",
@ -371,6 +380,7 @@ func TestUnregisterValidator(t *testing.T) {
} }
} }
// nolint:paralleltest
func TestUnregisterValidatorNotRegisteredValidator(t *testing.T) { func TestUnregisterValidatorNotRegisteredValidator(t *testing.T) {
initializeValidatorsStorage() initializeValidatorsStorage()
@ -411,19 +421,19 @@ func BenchmarkUnregisterValidatorAsync(b *testing.B) {
) )
} }
var w sync.WaitGroup var waiter sync.WaitGroup
b.StartTimer() b.StartTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
w.Add(1) waiter.Add(1)
go func() { go func() {
_ = UnregisterValidator("string_test_validator_" + strconv.Itoa(i)) _ = UnregisterValidator("string_test_validator_" + strconv.Itoa(i))
w.Done() waiter.Done()
}() }()
w.Wait() waiter.Wait()
} }
} }