api/pkg/cert/addr_utils_test.go
Peter Kurfer 7c2a41ad25 Move TLS/cert handling to main app
- apply changes in proxy plugin and TLS interceptor
- add HTTPS proxy support
- move ca-generation command to main app
- minor refactoring to improve API stability
- move mocks to extra packages to avoid cycling imports
- fix bug in multi-port configuration
- change HTTP proxy to redirect to HTTP mock instead of maintaining custom rules
2020-04-26 00:32:46 +02:00

44 lines
847 B
Go

package cert
import "testing"
func Test_extractIPFromAddress(t *testing.T) {
type args struct {
addr string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "Get address for IPv4 address",
want: "127.0.0.1",
wantErr: false,
args: args{
addr: "127.0.0.1:23492",
},
},
{
name: "Get address for IPv6 address",
want: "::1",
wantErr: false,
args: args{
addr: "[::1]:23492",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := extractIPFromAddress(tt.args.addr)
if (err != nil) != tt.wantErr {
t.Errorf("extractIPFromAddress() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("extractIPFromAddress() got = %v, want %v", got, tt.want)
}
})
}
}