-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from ngrok/mo/bindings
Add WithBindings Mixin
- Loading branch information
Showing
9 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package config | ||
|
||
type bindings []string | ||
|
||
// WithBinding configures ingress for an endpoint | ||
// | ||
// The requestedBindings argument specifies the type of ingress for the endpoint. | ||
func WithBindings(requestedBindings ...string) interface { | ||
HTTPEndpointOption | ||
TLSEndpointOption | ||
TCPEndpointOption | ||
} { | ||
ret := bindings{} | ||
for _, binding := range requestedBindings { | ||
ret = append(ret, binding) | ||
} | ||
return ret | ||
} | ||
|
||
func (b bindings) ApplyTLS(cfg *tlsOptions) { | ||
cfg.Bindings = []string(b) | ||
} | ||
|
||
func (b bindings) ApplyTCP(cfg *tcpOptions) { | ||
cfg.Bindings = []string(b) | ||
} | ||
|
||
func (b bindings) ApplyHTTP(cfg *httpOptions) { | ||
cfg.Bindings = []string(b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func testBindings[T tunnelConfigPrivate, OT any](t *testing.T, | ||
makeOpts func(...OT) Tunnel, | ||
) { | ||
optsFunc := func(opts ...any) Tunnel { | ||
return makeOpts(assertSlice[OT](opts)...) | ||
} | ||
|
||
cases := testCases[T, any]{ | ||
{ | ||
name: "absent", | ||
opts: optsFunc(), | ||
expectExtra: &matchBindExtra{ | ||
Bindings: ptr([]string{}), | ||
}, | ||
}, | ||
{ | ||
name: "with bindings", | ||
opts: optsFunc(WithBindings("public")), | ||
expectExtra: &matchBindExtra{ | ||
Bindings: ptr([]string{"public"}), | ||
}, | ||
}, | ||
{ | ||
name: "with bindings with spread op", | ||
opts: optsFunc(WithBindings([]string{"public"}...)), | ||
expectExtra: &matchBindExtra{ | ||
Bindings: ptr([]string{"public"}), | ||
}, | ||
}, | ||
} | ||
|
||
cases.runAll(t) | ||
} | ||
|
||
func TestBindings(t *testing.T) { | ||
testBindings[*httpOptions](t, HTTPEndpoint) | ||
testBindings[*tlsOptions](t, TLSEndpoint) | ||
testBindings[*tcpOptions](t, TCPEndpoint) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters