Compare commits

..

No commits in common. "081139cf6595cb647b017ad88ccd862b48a4d69b" and "fdf99daa9cbd9ac1c7a12476f55ebb71f8ed2831" have entirely different histories.

4 changed files with 9 additions and 43 deletions

View file

@ -1,22 +0,0 @@
on: [push]
jobs:
linting:
runs-on: docker
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- uses: https://github.com/golangci/golangci-lint-action@v6
tests:
runs-on: docker
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: Install dependencies
run: go get .
- name: Run tests
run: go test

View file

@ -435,13 +435,10 @@ linters:
- github.com/alexedwards/argon2id
- github.com/google/uuid
- github.com/hack-pad/hackpadfs
- github.com/hashicorp/hcl/v2
- github.com/jessevdk/go-flags
- github.com/pelletier/go-toml/v2
- github.com/pressly/goose/v3
- github.com/PuerkitoBio/goquery
- github.com/stretchr/testify
- gopkg.in/ini.v1
- gopkg.in/yaml.v3
- modernc.org/sqlite
# List of allowed module domains.
@ -2709,7 +2706,7 @@ linters:
- path: _test\.go
linters:
- revive
text: "(comments-density|line-length-limit|unchecked-type-assertion|cognitive-complexity)"
text: "(comments-density|line-length-limit|unchecked-type-assertion)"
# Run some linter only for test files by excluding its issues for everything else.
#- path-except: _test\.go

View file

@ -18,8 +18,6 @@ import (
"gopkg.in/yaml.v3"
)
const errMsgConfigGen = "cannot generate config content: %w"
func parseError(err error) error {
return fmt.Errorf("cannot parse config file: %w", err)
}
@ -107,7 +105,7 @@ func unmarshalJSON(data []byte, v any) error {
func marshalJSON(v any) ([]byte, error) {
data, err := json.MarshalIndent(v, "", " ")
if err != nil {
return nil, fmt.Errorf(errMsgConfigGen, err)
return nil, fmt.Errorf("cannot generate config content: %w", err)
}
return data, nil
@ -127,7 +125,7 @@ func unmarshalTOML(data []byte, v any) error {
func marshalTOML(v any) ([]byte, error) {
data, err := toml.Marshal(v)
if err != nil {
return nil, fmt.Errorf(errMsgConfigGen, err)
return nil, fmt.Errorf("cannot generate config content: %w", err)
}
return data, nil
@ -187,7 +185,7 @@ func unmarshalYAML(data []byte, v any) error {
func marshalYAML(v any) ([]byte, error) {
data, err := yaml.Marshal(v)
if err != nil {
return nil, fmt.Errorf(errMsgConfigGen, err)
return nil, fmt.Errorf("cannot generate config content: %w", err)
}
return data, nil
@ -196,7 +194,6 @@ func marshalYAML(v any) ([]byte, error) {
// unmarshalINI unmarshals the given data to the given struct.
func unmarshalINI(data []byte, v any) error {
opts := ini.LoadOptions{}
cfg, err := ini.LoadSources(opts, data)
if err != nil {
return parseError(err)
@ -223,31 +220,25 @@ func marshalINI(v any) ([]byte, error) {
err := ini.ReflectFromWithMapper(cfg, v, iniNameMapper)
if err != nil {
return nil, fmt.Errorf("cannot generate config from struct: %w", err)
return nil, fmt.Errorf("cannot generate config content: %w", err)
}
var buf bytes.Buffer
cfg.WriteTo(&buf)
data := buf.Bytes()
_, err = cfg.WriteTo(&buf)
if err != nil {
return nil, fmt.Errorf(errMsgConfigGen, err)
}
return buf.Bytes(), nil
return data, nil
}
func iniNameMapper(raw string) string {
newstr := make([]rune, 0, len(raw))
for i, chr := range raw {
if isUpper := 'A' <= chr && chr <= 'Z'; isUpper {
if i > 0 {
newstr = append(newstr, '_')
}
}
newstr = append(newstr, unicode.ToLower(chr))
}
return string(newstr)
}

View file

@ -241,7 +241,7 @@ func testLoadFiles(t *testing.T, ext string) {
err := conf.LoadFiles(&c, "test_data/invalid."+ext, "test_data/valid."+ext)
require.Error(t, err)
assert.Empty(t, c.String)
assert.Equal(t, "", c.String)
})
t.Run("with a valid file and invalid data", func(t *testing.T) {