Skip to content

Commit

Permalink
adds config format arg to read
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhang93 committed Aug 14, 2024
1 parent 683311d commit 4408c2a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ func ReadFromFile(path string) (TPLAgent, error) {
if err != nil {
return TPLAgent{}, fatal.NewError(fmt.Errorf("read config:%w", err))
}
return Read(confFile)
return Read(confFile, "json")
}

func Read(rr io.Reader) (TPLAgent, error) {
func Read(rr io.Reader, configFormat string) (TPLAgent, error) {
var c TPLAgent
if err := json.NewDecoder(rr).Decode(&c); err != nil {
return TPLAgent{}, fatal.NewError(fmt.Errorf("config decode error:%w", err))
Expand Down
8 changes: 4 additions & 4 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func Test_readConfig(t *testing.T) {
},
},
}
c, err := Read(strings.NewReader(configJSON))
c, err := Read(strings.NewReader(configJSON), "json")
if err != nil {
t.Errorf("error reading config:%v", err)
return
Expand Down Expand Up @@ -195,7 +195,7 @@ func Test_readConfig(t *testing.T) {
}
}
`
conf, err := Read(strings.NewReader(configJSON))
conf, err := Read(strings.NewReader(configJSON), "json")
if err != nil {
t.Errorf("error reading config:%v\n", err)
return
Expand Down Expand Up @@ -240,7 +240,7 @@ func Test_config_fatalErrors(t *testing.T) {
buff.Reset()
buff.Write(jsonCfg)

_, err = Read(&buff)
_, err = Read(&buff, "json")
if !fatal.Is(err) {
t.Error("expected fatal error")
return
Expand Down Expand Up @@ -273,7 +273,7 @@ func Test_config_fatalErrors(t *testing.T) {
return
}

_, err = Read(&buff)
_, err = Read(&buff, "json")
if !fatal.Is(err) {
t.Error("expected fatal error")
}
Expand Down

0 comments on commit 4408c2a

Please sign in to comment.