mirror of
https://github.com/spf13/viper
synced 2025-05-15 08:37:19 +00:00
chore(linter): enable errorlint
This commit is contained in:
parent
0594522560
commit
0235f6179e
4 changed files with 12 additions and 6 deletions
|
@ -17,6 +17,7 @@ linters:
|
||||||
- dogsled
|
- dogsled
|
||||||
- dupl
|
- dupl
|
||||||
- durationcheck
|
- durationcheck
|
||||||
|
- errorlint
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- exportloopref
|
- exportloopref
|
||||||
- gci
|
- gci
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package encoding
|
package encoding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ func TestDecoderRegistry_RegisterDecoder(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = registry.RegisterDecoder("myformat", decoder{})
|
err = registry.RegisterDecoder("myformat", decoder{})
|
||||||
if err != ErrDecoderFormatAlreadyRegistered {
|
if !errors.Is(err, ErrDecoderFormatAlreadyRegistered) {
|
||||||
t.Fatalf("expected ErrDecoderFormatAlreadyRegistered, got: %v", err)
|
t.Fatalf("expected ErrDecoderFormatAlreadyRegistered, got: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -70,7 +71,7 @@ func TestDecoderRegistry_Decode(t *testing.T) {
|
||||||
var v string
|
var v string
|
||||||
|
|
||||||
err := registry.Decode("myformat", []byte("some value"), &v)
|
err := registry.Decode("myformat", []byte("some value"), &v)
|
||||||
if err != ErrDecoderNotFound {
|
if !errors.Is(err, ErrDecoderNotFound) {
|
||||||
t.Fatalf("expected ErrDecoderNotFound, got: %v", err)
|
t.Fatalf("expected ErrDecoderNotFound, got: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package encoding
|
package encoding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ func TestEncoderRegistry_RegisterEncoder(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = registry.RegisterEncoder("myformat", encoder{})
|
err = registry.RegisterEncoder("myformat", encoder{})
|
||||||
if err != ErrEncoderFormatAlreadyRegistered {
|
if !errors.Is(err, ErrEncoderFormatAlreadyRegistered) {
|
||||||
t.Fatalf("expected ErrEncoderFormatAlreadyRegistered, got: %v", err)
|
t.Fatalf("expected ErrEncoderFormatAlreadyRegistered, got: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -63,7 +64,7 @@ func TestEncoderRegistry_Decode(t *testing.T) {
|
||||||
registry := NewEncoderRegistry()
|
registry := NewEncoderRegistry()
|
||||||
|
|
||||||
_, err := registry.Encode("myformat", "some value")
|
_, err := registry.Encode("myformat", "some value")
|
||||||
if err != ErrEncoderNotFound {
|
if !errors.Is(err, ErrEncoderNotFound) {
|
||||||
t.Fatalf("expected ErrEncoderNotFound, got: %v", err)
|
t.Fatalf("expected ErrEncoderNotFound, got: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,6 +8,7 @@ package viper
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -1840,7 +1841,8 @@ func TestSafeWriteConfigWithExistingFile(t *testing.T) {
|
||||||
v.SetConfigType("yaml")
|
v.SetConfigType("yaml")
|
||||||
err := v.SafeWriteConfig()
|
err := v.SafeWriteConfig()
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
_, ok := err.(ConfigFileAlreadyExistsError)
|
var cfaeErr ConfigFileAlreadyExistsError
|
||||||
|
ok := errors.As(err, &cfaeErr)
|
||||||
assert.True(t, ok, "Expected ConfigFileAlreadyExistsError")
|
assert.True(t, ok, "Expected ConfigFileAlreadyExistsError")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1865,7 +1867,8 @@ func TestSafeWriteConfigAsWithExistingFile(t *testing.T) {
|
||||||
v.SetFs(fs)
|
v.SetFs(fs)
|
||||||
err := v.SafeWriteConfigAs("/test/c.yaml")
|
err := v.SafeWriteConfigAs("/test/c.yaml")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
_, ok := err.(ConfigFileAlreadyExistsError)
|
var cfaeErr ConfigFileAlreadyExistsError
|
||||||
|
ok := errors.As(err, &cfaeErr)
|
||||||
assert.True(t, ok, "Expected ConfigFileAlreadyExistsError")
|
assert.True(t, ok, "Expected ConfigFileAlreadyExistsError")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue