Skip to content

Commit

Permalink
Remove deprecated fields (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Aug 29, 2020
1 parent e1e5dd9 commit 42995bd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 124 deletions.
25 changes: 0 additions & 25 deletions oauth2cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
//
Expand All @@ -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)
Expand Down
99 changes: 0 additions & 99 deletions oauth2cli_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
})
}

0 comments on commit 42995bd

Please sign in to comment.