Select Git revision
field_json.go
action_url_test.go 3.18 KiB
package extension
import (
"fmt"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestActionURL_New(t *testing.T) {
tests := []struct {
name string
action string
want *ActionURL
url string
wantErr assert.ErrorAssertionFunc
}{
{
name: "Without action",
want: &ActionURL{
URL: &url.URL{},
},
wantErr: assert.NoError,
},
{
name: "Without deprecated action call",
action: "build-site",
want: &ActionURL{
URL: &url.URL{
Path: "build-site",
},
},
url: "build-site",
wantErr: assert.NoError,
},
{
name: "With grpc action",
action: "grpc:///perxisweb/build-site",
want: &ActionURL{
URL: &url.URL{
Scheme: "grpc",
Path: "/perxisweb/build-site",
},
},
url: "grpc:///perxisweb/build-site",
wantErr: assert.NoError,
},
{
name: "With ui action",
action: "ui:///space/env/coll",
want: &ActionURL{
URL: &url.URL{
Scheme: "ui",
Path: "/space/env/coll",
},
},
url: "ui:///space/env/coll",
wantErr: assert.NoError,
},
{
name: "With http action",
action: "https://perx.ru",
want: &ActionURL{
URL: &url.URL{
Scheme: "https",
Host: "perx.ru",
},
},
url: "https://perx.ru",
wantErr: assert.NoError,
},
{
name: "With error in parse",
action: "grpc://user:abc{DEf1=ghi@example.com:5432/db?sslmode=require",
want: nil,
wantErr: assert.Error,
},
{
name: "With no action id",
action: "grpc:///perxisweb",
want: &ActionURL{
URL: &url.URL{
Scheme: "grpc",
Path: "/perxisweb",
},
},
wantErr: assert.NoError,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewActionURL(tt.action)
if !tt.wantErr(t, err, fmt.Sprintf("NewURL(%v)", tt.action)) {
return
}
assert.Equalf(t, tt.want, got, "NewURL(%v)", tt.action)
})
}
}
func TestActionURL_String(t *testing.T) {
tests := []struct {
name string
url string
want string
}{
{
name: "GRPC action",
url: "grpc:///perxisweb/build-site",
},
{
name: "UI action #1",
url: "ui:///space/env/coll",
},
{
name: "UI action deprecated call #2",
url: "space/env/coll",
},
{
name: "Https action",
url: "https://perx.ru",
},
{
name: "With action deprecated call",
url: "extension-id",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p, _ := NewActionURL(tt.url)
assert.Equalf(t, tt.url, p.String(), "String()")
})
}
}
func TestActionURL_Action(t *testing.T) {
tests := []struct {
name string
url string
want string
}{
{
name: "GRPC action",
url: "grpc:///perxisweb/build-site",
want: "build-site",
},
{
name: "UI action #1",
url: "ui:///space/env/coll",
},
{
name: "UI action deprecated call #2",
url: "space/env/coll",
},
{
name: "Https action",
url: "https://perx.ru",
},
{
name: "With action deprecated call",
url: "extension-id",
want: "extension-id",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p, _ := NewActionURL(tt.url)
assert.Equalf(t, tt.want, p.Action(), "Action()")
})
}
}