chore(linter): enable errorlint

This commit is contained in:
Matthieu MOREL 2021-10-03 11:06:20 +02:00 committed by GitHub
parent 0594522560
commit 0235f6179e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View file

@ -17,6 +17,7 @@ linters:
- dogsled
- dupl
- durationcheck
- errorlint
- exhaustive
- exportloopref
- gci

View file

@ -1,6 +1,7 @@
package encoding
import (
"errors"
"testing"
)
@ -34,7 +35,7 @@ func TestDecoderRegistry_RegisterDecoder(t *testing.T) {
}
err = registry.RegisterDecoder("myformat", decoder{})
if err != ErrDecoderFormatAlreadyRegistered {
if !errors.Is(err, ErrDecoderFormatAlreadyRegistered) {
t.Fatalf("expected ErrDecoderFormatAlreadyRegistered, got: %v", err)
}
})
@ -70,7 +71,7 @@ func TestDecoderRegistry_Decode(t *testing.T) {
var v string
err := registry.Decode("myformat", []byte("some value"), &v)
if err != ErrDecoderNotFound {
if !errors.Is(err, ErrDecoderNotFound) {
t.Fatalf("expected ErrDecoderNotFound, got: %v", err)
}
})

View file

@ -1,6 +1,7 @@
package encoding
import (
"errors"
"testing"
)
@ -31,7 +32,7 @@ func TestEncoderRegistry_RegisterEncoder(t *testing.T) {
}
err = registry.RegisterEncoder("myformat", encoder{})
if err != ErrEncoderFormatAlreadyRegistered {
if !errors.Is(err, ErrEncoderFormatAlreadyRegistered) {
t.Fatalf("expected ErrEncoderFormatAlreadyRegistered, got: %v", err)
}
})
@ -63,7 +64,7 @@ func TestEncoderRegistry_Decode(t *testing.T) {
registry := NewEncoderRegistry()
_, err := registry.Encode("myformat", "some value")
if err != ErrEncoderNotFound {
if !errors.Is(err, ErrEncoderNotFound) {
t.Fatalf("expected ErrEncoderNotFound, got: %v", err)
}
})

View file

@ -8,6 +8,7 @@ package viper
import (
"bytes"
"encoding/json"
"errors"
"io"
"io/ioutil"
"os"
@ -1840,7 +1841,8 @@ func TestSafeWriteConfigWithExistingFile(t *testing.T) {
v.SetConfigType("yaml")
err := v.SafeWriteConfig()
require.Error(t, err)
_, ok := err.(ConfigFileAlreadyExistsError)
var cfaeErr ConfigFileAlreadyExistsError
ok := errors.As(err, &cfaeErr)
assert.True(t, ok, "Expected ConfigFileAlreadyExistsError")
}
@ -1865,7 +1867,8 @@ func TestSafeWriteConfigAsWithExistingFile(t *testing.T) {
v.SetFs(fs)
err := v.SafeWriteConfigAs("/test/c.yaml")
require.Error(t, err)
_, ok := err.(ConfigFileAlreadyExistsError)
var cfaeErr ConfigFileAlreadyExistsError
ok := errors.As(err, &cfaeErr)
assert.True(t, ok, "Expected ConfigFileAlreadyExistsError")
}