Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release config test #334

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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