Skip to content

Commit

Permalink
add test for parsing custom string type
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorik van der Werf committed Oct 18, 2019
1 parent 16377d4 commit 01e5227
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions internal/cmd/scraper/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/require"

"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -66,3 +69,20 @@ func TestLogrusDebugPrintMasksLicenseKey(t *testing.T) {
t.Error("Log output does not contain the masked licenseKey")
}
}

func TestConfigParseWithCustomType(t *testing.T) {

const licenseKey = "MY_LICENSE_KEY"
cfgStr := []byte(fmt.Sprintf(`LICENSE_KEY: %s`, licenseKey))

vip := viper.New()
vip.SetConfigType("yaml")
err := vip.ReadConfig(bytes.NewBuffer(cfgStr))
require.NoError(t, err)

var cfg Config
err = vip.Unmarshal(&cfg)
require.NoError(t, err)

assert.Equal(t, licenseKey, string(cfg.LicenseKey))
}

0 comments on commit 01e5227

Please sign in to comment.