Skip to content
Snippets Groups Projects
Select Git revision
  • b3370a435a6eb3cdcb66464acdce4a69b72dbef9
  • master default protected
  • feature/PRXS-3383-CollectionsRankSort
  • feature/PRXS-3421-3426-AddAPI
  • refactor/PRXS-3053-Files
  • docs/3247-PerxisWebCDN
  • feature/PRXS-3421-RecursiveReferences
  • feature/3146-UpdateItemStorageInterface
  • feature/3180-RemoveOldHugo
  • feature/3264-FixExtracTranslationsArrays
  • feature/3274-ObjectIndexesFixes
  • feature/2931-AllowPartialDecode
  • feature/3055-ItemsRestAPI
  • feature/3082-gitlab-triage
  • feature/3055-LogsRestAPI
  • feature/2985-add-preset-settings
  • feature/2929-MultiInvitationFix
  • feature/2929-MultiInvitation
  • docs/2889-HugoModules
  • docs/2954-CheckResource
  • docs/3012-SplitBuild
  • v0.27.0
  • v0.21.0
  • v0.19.0
  • v0.20.0
25 results

common.proto

Blame
  • 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()")
    		})
    	}
    }