-
Notifications
You must be signed in to change notification settings - Fork 10
Integrate consul-server-connection-manager library #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
7bfbdf9
dc38a42
9043812
f22826a
f56a882
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package main | ||
boxofrad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import ( | ||
| "flag" | ||
| "fmt" | ||
| "strings" | ||
| ) | ||
|
|
||
| var _ flag.Value = (*FlagMapValue)(nil) | ||
|
|
||
| // FlagMapValue is a flag implementation used to provide key=value semantics | ||
| // multiple times. | ||
| type FlagMapValue map[string]string | ||
|
|
||
| func (h *FlagMapValue) String() string { | ||
| return fmt.Sprintf("%v", *h) | ||
| } | ||
|
|
||
| func (h *FlagMapValue) Set(value string) error { | ||
| idx := strings.Index(value, "=") | ||
| if idx == -1 { | ||
| return fmt.Errorf("Missing \"=\" value in argument: %s", value) | ||
| } | ||
|
|
||
| key, value := value[0:idx], value[idx+1:] | ||
|
|
||
| if *h == nil { | ||
| *h = make(map[string]string) | ||
| } | ||
|
|
||
| headers := *h | ||
| headers[key] = value | ||
| *h = headers | ||
|
|
||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestFlagMapValueSet(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| t.Run("missing =", func(t *testing.T) { | ||
|
|
||
| f := new(FlagMapValue) | ||
| if err := f.Set("foo"); err == nil { | ||
| t.Fatal("expected error, got nil") | ||
| } | ||
| }) | ||
|
|
||
| t.Run("sets", func(t *testing.T) { | ||
|
|
||
| f := new(FlagMapValue) | ||
| if err := f.Set("foo=bar"); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| r, ok := (*f)["foo"] | ||
| if !ok { | ||
| t.Errorf("missing value: %#v", f) | ||
| } | ||
| if exp := "bar"; r != exp { | ||
| t.Errorf("expected %q to be %q", r, exp) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("sets multiple", func(t *testing.T) { | ||
|
|
||
| f := new(FlagMapValue) | ||
|
|
||
| r := map[string]string{ | ||
| "foo": "bar", | ||
| "zip": "zap", | ||
| "cat": "dog", | ||
| } | ||
|
|
||
| for k, v := range r { | ||
| if err := f.Set(fmt.Sprintf("%s=%s", k, v)); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
|
|
||
| for k, v := range r { | ||
| r, ok := (*f)[k] | ||
| if !ok { | ||
| t.Errorf("missing value %q: %#v", k, f) | ||
| } | ||
| if exp := v; r != exp { | ||
| t.Errorf("expected %q to be %q", r, exp) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| t.Run("overwrites", func(t *testing.T) { | ||
|
|
||
| f := new(FlagMapValue) | ||
| if err := f.Set("foo=bar"); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := f.Set("foo=zip"); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| r, ok := (*f)["foo"] | ||
| if !ok { | ||
| t.Errorf("missing value: %#v", f) | ||
| } | ||
| if exp := "zip"; r != exp { | ||
| t.Errorf("expected %q to be %q", r, exp) | ||
| } | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,21 +4,27 @@ go 1.19 | |
|
|
||
| require ( | ||
| github.com/adamthesax/grpc-proxy v0.0.0-20220525203857-13e92d14f87a | ||
| github.com/hashicorp/consul/proto-public v0.1.0 | ||
| github.com/hashicorp/go-hclog v1.2.2 | ||
| github.com/hashicorp/go-netaddrs v0.0.0-20220509001840-90ed9d26ec46 | ||
| github.com/hashicorp/go-rootcerts v1.0.2 | ||
| github.com/mitchellh/mapstructure v1.5.0 | ||
| github.com/stretchr/testify v1.8.0 | ||
| google.golang.org/grpc v1.48.0 | ||
| google.golang.org/protobuf v1.28.1 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/cenkalti/backoff/v4 v4.1.3 // indirect | ||
| github.com/davecgh/go-spew v1.1.1 // indirect | ||
| github.com/fatih/color v1.13.0 // indirect | ||
| github.com/golang/protobuf v1.5.2 // indirect | ||
| github.com/google/go-cmp v0.5.8 // indirect | ||
| github.com/google/uuid v1.1.2 // indirect | ||
| github.com/hashicorp/consul-server-connection-manager v0.0.0-20220908112242-b9f43f15d156 // indirect | ||
|
||
| github.com/hashicorp/go-netaddrs v0.0.0-20220509001840-90ed9d26ec46 // indirect | ||
| github.com/mattn/go-colorable v0.1.12 // indirect | ||
| github.com/mattn/go-isatty v0.0.14 // indirect | ||
| github.com/mitchellh/go-homedir v1.1.0 // indirect | ||
| github.com/pmezard/go-difflib v1.0.0 // indirect | ||
| github.com/stretchr/objx v0.4.0 // indirect | ||
| golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.