From 81fe047ccd766a5815ae1f8a6815f8a5b5dacea3 Mon Sep 17 00:00:00 2001 From: Brooks Newberry Date: Thu, 11 Jan 2024 13:14:03 -0800 Subject: [PATCH] add config test (#334) Signed-off-by: Brooks Newberry --- cmd/release/config/config.go | 7 +++++-- cmd/release/config/config_test.go | 20 ++++++++++++++++++++ cmd/release/config/test_data/config.json | 4 +++- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 cmd/release/config/config_test.go diff --git a/cmd/release/config/config.go b/cmd/release/config/config.go index fa582121..405d426c 100644 --- a/cmd/release/config/config.go +++ b/cmd/release/config/config.go @@ -2,6 +2,7 @@ package config import ( "encoding/json" + "io" "os" ) @@ -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 } diff --git a/cmd/release/config/config_test.go b/cmd/release/config/config_test.go new file mode 100644 index 00000000..0fee5a37 --- /dev/null +++ b/cmd/release/config/config_test.go @@ -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) + } +} diff --git a/cmd/release/config/test_data/config.json b/cmd/release/config/test_data/config.json index bbc214a5..5a207385 100644 --- a/cmd/release/config/test_data/config.json +++ b/cmd/release/config/test_data/config.json @@ -15,7 +15,9 @@ }, "workspace": "/Users/pedrosuse/go/src/github.com/src/kubernetes" }, - "rke2": [], + "rke2": { + "versions": [] + }, "auth": { "drone": { "k3s_pr": "",