Skip to content

Commit

Permalink
Merge pull request #62 from vshn/renovate/gopkg.in-yaml.v2-3.x
Browse files Browse the repository at this point in the history
Update module gopkg.in/yaml.v2 to v3
  • Loading branch information
simu authored Feb 13, 2024
2 parents e1af739 + a2b254a commit b3219bf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
5 changes: 5 additions & 0 deletions floaty.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider: cloudscale
cloudscale:
token: fake-token
managed-addresses:
- 192.0.2.10
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand All @@ -24,5 +25,4 @@ require (
github.com/vishvananda/netlink v1.1.0 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
golang.org/x/sys v0.17.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
13 changes: 9 additions & 4 deletions notify_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import (
"errors"
"fmt"
"io/ioutil"
"net/url"
"os"
"time"

yaml "gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v3"
)

const (
Expand Down Expand Up @@ -51,12 +51,17 @@ func newNotifyConfig() notifyConfig {

// Update configuration from a YAML file
func (c *notifyConfig) ReadFromYAML(path string) error {
content, err := ioutil.ReadFile(path)
configreader, err := os.Open(path)
if err != nil {
return err
}

return yaml.UnmarshalStrict(content, c)
decoder := yaml.NewDecoder(configreader)
// NOTE(sg): With gopkg.in/yaml.v3, we use the decoder API instead of
// `Unmarshal` so we can ensure that we get errors for unknown fields.
decoder.KnownFields(true)

return decoder.Decode(c)
}

func (c notifyConfig) NewProvider() (elasticIPProvider, error) {
Expand Down
17 changes: 17 additions & 0 deletions notify_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadConfig(t *testing.T) {
cfg, err := loadConfig("floaty.example.yaml", false)
assert.NoError(t, err)
assert.Equalf(t, "cloudscale", cfg.Provider, "error parsing provider from config file")
assert.Equalf(t, "fake-token", cfg.Cloudscale.Token, "error parsing cloudscale token from config file")
managedAddr := netAddress{}
managedAddr.UnmarshalText([]byte("192.0.2.10"))
assert.Equalf(t, []netAddress{managedAddr}, cfg.ManagedAddresses, "error parsing managed addresses from config file")
}

0 comments on commit b3219bf

Please sign in to comment.