Skip to content

Commit

Permalink
add config test (#334)
Browse files Browse the repository at this point in the history
Signed-off-by: Brooks Newberry <[email protected]>
  • Loading branch information
brooksn authored Jan 11, 2024
1 parent 943a7a2 commit 81fe047
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cmd/release/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"encoding/json"
"io"
"os"
)

Expand Down Expand Up @@ -63,11 +64,13 @@ func Load(configFile string) (*Config, error) {
if err != nil {
return nil, err
}
return read(f)
}

func read(r io.Reader) (*Config, error) {
var c Config
if err := json.NewDecoder(f).Decode(&c); err != nil {
if err := json.NewDecoder(r).Decode(&c); err != nil {
return nil, err
}

return &c, nil
}
20 changes: 20 additions & 0 deletions cmd/release/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package config

import (
"embed"
"testing"
)

//go:embed test_data/config.json
var configFS embed.FS

func TestRead(t *testing.T) {
f, err := configFS.Open("test_data/config.json")
if err != nil {
t.Fatal(err)
}

if _, err := read(f); err != nil {
t.Fatal(err)
}
}
4 changes: 3 additions & 1 deletion cmd/release/config/test_data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
},
"workspace": "/Users/pedrosuse/go/src/github.com/src/kubernetes"
},
"rke2": [],
"rke2": {
"versions": []
},
"auth": {
"drone": {
"k3s_pr": "",
Expand Down

0 comments on commit 81fe047

Please sign in to comment.