From 42995bd4315a819f98f22b899bd96628d7eece0a Mon Sep 17 00:00:00 2001 From: Hidetake Iwata Date: Sat, 29 Aug 2020 11:08:37 +0900 Subject: [PATCH] Remove deprecated fields (#46) --- oauth2cli.go | 25 ------------ oauth2cli_test.go | 99 ----------------------------------------------- 2 files changed, 124 deletions(-) diff --git a/oauth2cli.go b/oauth2cli.go index 3171030..385fd08 100644 --- a/oauth2cli.go +++ b/oauth2cli.go @@ -91,18 +91,6 @@ type Config struct { // Logger function for debug. Logf func(format string, args ...interface{}) - - // DEPRECATED: this will be removed in the future release. - // Use LocalServerBindAddress instead. - // Address which the local server binds to. - // Default to "127.0.0.1". - LocalServerAddress string - // DEPRECATED: this will be removed in the future release. - // Use LocalServerBindAddress instead. - // Candidates of a port which the local server binds to. - // If nil or an empty slice is given, LocalServerAddress is ignored and allocate a free port. - // If multiple ports are given, they are appended to LocalServerBindAddress. - LocalServerPort []int } func (c *Config) isLocalServerHTTPS() bool { @@ -136,18 +124,6 @@ func (c *Config) validateAndSetDefaults() error { return nil } -func (c *Config) populateDeprecatedFields() { - if len(c.LocalServerPort) > 0 { - address := c.LocalServerAddress - if address == "" { - address = "127.0.0.1" - } - for _, port := range c.LocalServerPort { - c.LocalServerBindAddress = append(c.LocalServerBindAddress, fmt.Sprintf("%s:%d", address, port)) - } - } -} - // GetToken performs the Authorization Code Grant Flow and returns a token received from the provider. // See https://tools.ietf.org/html/rfc6749#section-4.1 // @@ -164,7 +140,6 @@ func GetToken(ctx context.Context, c Config) (*oauth2.Token, error) { if err := c.validateAndSetDefaults(); err != nil { return nil, fmt.Errorf("invalid config: %w", err) } - c.populateDeprecatedFields() code, err := receiveCodeViaLocalServer(ctx, &c) if err != nil { return nil, fmt.Errorf("authorization error: %w", err) diff --git a/oauth2cli_test.go b/oauth2cli_test.go index d1fa081..f4755bf 100644 --- a/oauth2cli_test.go +++ b/oauth2cli_test.go @@ -1,100 +1 @@ package oauth2cli - -import ( - "testing" - - "github.com/google/go-cmp/cmp" -) - -func TestConfig_populateDeprecatedFields(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - var cfg Config - cfg.populateDeprecatedFields() - var want []string - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) - } - }) - - t.Run("AddressOnly", func(t *testing.T) { - cfg := Config{ - LocalServerAddress: "0.0.0.0", - } - cfg.populateDeprecatedFields() - var want []string - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) - } - }) - - t.Run("SinglePort", func(t *testing.T) { - cfg := Config{ - LocalServerPort: []int{8000}, - } - cfg.populateDeprecatedFields() - want := []string{"127.0.0.1:8000"} - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) - } - }) - - t.Run("SinglePortWithAddress", func(t *testing.T) { - cfg := Config{ - LocalServerAddress: "0.0.0.0", - LocalServerPort: []int{8000}, - } - cfg.populateDeprecatedFields() - want := []string{"0.0.0.0:8000"} - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) - } - }) - - t.Run("MultiplePort", func(t *testing.T) { - cfg := Config{ - LocalServerPort: []int{8000, 18000}, - } - cfg.populateDeprecatedFields() - want := []string{"127.0.0.1:8000", "127.0.0.1:18000"} - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) - } - }) - - t.Run("MultiplePortWithAddress", func(t *testing.T) { - cfg := Config{ - LocalServerAddress: "0.0.0.0", - LocalServerPort: []int{8000, 18000}, - } - cfg.populateDeprecatedFields() - want := []string{"0.0.0.0:8000", "0.0.0.0:18000"} - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) - } - }) - - t.Run("PreserveOriginalValue", func(t *testing.T) { - t.Run("DefaultValue", func(t *testing.T) { - cfg := Config{ - LocalServerBindAddress: []string{"127.0.0.1:10000"}, - } - cfg.populateDeprecatedFields() - want := []string{"127.0.0.1:10000"} - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) - } - }) - - t.Run("SinglePort", func(t *testing.T) { - cfg := Config{ - LocalServerBindAddress: []string{"127.0.0.1:10000"}, - LocalServerPort: []int{8000}, - } - cfg.populateDeprecatedFields() - want := []string{"127.0.0.1:10000", "127.0.0.1:8000"} - if diff := cmp.Diff(want, cfg.LocalServerBindAddress); diff != "" { - t.Errorf("LocalServerBindAddress mismatch (-want +got):\n%s", diff) - } - }) - }) -}