heetch / heetch/confita

Can't load config into struct with json tags

Open
#85 1 comment 5 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
507
Forks
49
PR merge metrics
No merged PRs in 30d

Description

I noticed a regression in behaviour. Here is code for reproducing the issue.

```go
package confitajson

import (
"context"
"log"
"testing"

"github.com/heetch/confita"
"github.com/heetch/confita/backend/file"
)

func TestLoad(t *testing.T) {
b := file.NewBackend("config.json")

var c struct {
Field string `json:"field"`
}

if err := confita.NewLoader(b).Load(context.Background(), &c); err != nil {
log.Fatalf("failed to load config: %v", err)
}

if c.Field != "value" {
log.Fatal("field value is not updated")
}
}
```

Content of `config.json` file is following:

```
{
"field": "value"
}
```

When running this test on the latest confita release, struct field is not updated. But on version v0.7.0 code works fine.

```
prime@bee ~/C/confitajson> go get github.com/heetch/confita@v0.7.0
go: downloading github.com/heetch/confita v0.7.0
prime@bee ~/C/confitajson> go test .
ok github.com/slon/confitajson 0.002s
prime@bee ~/C/confitajson> go get github.com/heetch/confita
go: github.com/heetch/confita upgrade => v0.9.1
prime@bee ~/C/confitajson> go test .
2020/05/27 20:02:34 field value is not updated
FAIL github.com/slon/confitajson 0.002s
FAIL
```

I also noticed, that removing these 3 lines, seems to fix this issue for me. https://github.com/heetch/confita/blob/master/config.go#L183-L185

Is that change in behaviour intentional, or is it indeed a regression?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with config.go lines 183-185 and reproduce the reported behavior using the provided Go test, JSON file, and struct tag. Compare the result with confita v0.7.0 and the latest release. Done means determining whether the change is intentional and, if it is a regression, restoring the expected field loading behavior with a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.