Skip to content

Commit

Permalink
Used config.Viperize() in test file
Browse files Browse the repository at this point in the history
Signed-off-by: bugslayer-332 <[email protected]>
  • Loading branch information
severussnape321 committed Jul 18, 2023
1 parent 5c13ec1 commit 0984e72
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/config/corscfg/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type Flags struct {
}

func (c Flags) AddFlags(flags *flag.FlagSet) {
flags.String(c.Prefix+corsAllowedHeaders, "content-type", "Allowed headers for the HTTP port , default content-type")
flags.String(c.Prefix+corsAllowedOrigins, "*", "Allowed origins for the HTTP port , default accepts all")
flags.String(c.Prefix+corsAllowedHeaders, "content-type", "Comma-separated CORS allowed headers, default accepts content-type. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers")
flags.String(c.Prefix+corsAllowedOrigins, "*", "Comma-separated CORS allowed headers, default accepts all. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin")
}

func (c Flags) InitFromViper(v *viper.Viper) Options {
Expand Down
12 changes: 3 additions & 9 deletions pkg/config/corscfg/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
package corscfg

import (
"flag"
"fmt"
"testing"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/jaegertracing/jaeger/pkg/config"
)

func TestCORSFlags(t *testing.T) {
Expand All @@ -31,15 +30,10 @@ func TestCORSFlags(t *testing.T) {
"--prefix.cors.allowed-origins=http://example.domain.com, http://*.domain.com",
}
t.Run("CORS Flags", func(t *testing.T) {
v := viper.New()
command := cobra.Command{}
flagSet := &flag.FlagSet{}
flagCfg := Flags{
Prefix: "prefix",
}
flagCfg.AddFlags(flagSet)
command.PersistentFlags().AddGoFlagSet(flagSet)
v.BindPFlags(command.PersistentFlags())
v, command := config.Viperize(flagCfg.AddFlags)

err := command.ParseFlags(cmdFlags)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/corscfg/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
package corscfg

type Options struct {
AllowedOrigins []string `mapstructure:"allowed_origins"`
AllowedHeaders []string `mapstructure:"allowed_headers"`
AllowedOrigins []string
AllowedHeaders []string
}

0 comments on commit 0984e72

Please sign in to comment.