diff --git a/.forgejo/workflows/test.yml b/.forgejo/workflows/test.yml deleted file mode 100644 index 3829101..0000000 --- a/.forgejo/workflows/test.yml +++ /dev/null @@ -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 - diff --git a/.golangci.yml b/.golangci.yml index 14395f4..f31d6d9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 diff --git a/adapters.go b/adapters.go index bab1a4a..368b5ef 100644 --- a/adapters.go +++ b/adapters.go @@ -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) } diff --git a/config_test.go b/config_test.go index 1cb122f..9e55316 100644 --- a/config_test.go +++ b/config_test.go @@ -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) {