Skip to content
Snippets Groups Projects
Select Git revision
  • 7e09f8e9864d9814cf3d72952add338a59224bac
  • master default protected
  • feature/PRXS-3106-NoCache
  • feature/PRXS-3043-NewURLFormat
  • feature/2781-SpacesLoggingMiddleware
  • feature/PRXS-2974-FillImageDimensions
  • feature/PRXS-3143-3235-ReferenceOptions
  • feature/PRXS-3056-LocalesFromToMap
  • feature/PRXS-3421-ImplementNewRefAPI
  • feature/PRXS-3143-LimitReferenceFields
  • feature/PRXS-3234-FeaturePruneIdents
  • PRXS-3421-RecursiveReferences
  • feature/3109-SerializeFeature
  • release/0.33
  • feature/3109-RecoverySchema
  • feature/3109-feature
  • fix/PRXS-3369-ValidateFields
  • refactor/PRXS-3306-MovePkgGroup1
  • refactor/6-pkg-refactor-expr
  • fix/PRXS-3360-TemplateBuilderPatch
  • feature/3293-MongoV2
  • v0.33.1
  • v0.32.0
  • v0.31.1
  • v0.31.0
  • v0.30.0
  • v0.29.0
  • v0.28.0
  • v0.27.0-alpha.1+16
  • v0.27.0-alpha.1+15
  • v0.27.0-alpha.1+14
  • v0.27.0-alpha.1+13
  • v0.27.0-alpha.1+12
  • v0.27.0-alpha.1+11
  • v0.27.0-alpha.1+10
  • v0.27.0-alpha.1+9
  • v0.27.0-alpha.1+8
  • v0.27.0-alpha.1+7
  • v0.27.0-alpha.1+6
  • v0.27.0-alpha.1+5
  • v0.27.0-alpha.1+4
41 results

action_test.go

Blame
  • action_test.go 2.70 KiB
    package action
    
    import (
    	"fmt"
    	"net/url"
    	"testing"
    
    	"github.com/stretchr/testify/assert"
    )
    
    func TestActionURL_New(t *testing.T) {
    	tests := []struct {
    		name    string
    		action  string
    		want    *URL
    		url     string
    		wantErr assert.ErrorAssertionFunc
    	}{
    		{
    			name:    "Without action",
    			want:    &URL{},
    			wantErr: assert.NoError,
    		},
    		{
    			name:    "Without deprecated action call",
    			action:  "build-site",
    			want:    &URL{},
    			url:     "build-site",
    			wantErr: assert.NoError,
    		},
    		{
    			name:   "With grpc action",
    			action: "grpc:///perxisweb/build-site",
    			want: &URL{
    				id:        "build-site",
    				extension: "perxisweb",
    			},
    			url:     "grpc:///perxisweb/build-site",
    			wantErr: assert.NoError,
    		},
    		{
    			name:   "With ui action",
    			action: "ui:///space/env/coll",
    			want: &URL{
    				id:        "",
    				extension: "",
    			},
    			url:     "ui:///space/env/coll",
    			wantErr: assert.NoError,
    		},
    		{
    			name:    "With http action",
    			action:  "https://perx.ru",
    			want:    &URL{},
    			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:    nil,
    			wantErr: assert.Error,
    		},
    	}
    	for _, tt := range tests {
    		t.Run(tt.name, func(t *testing.T) {
    			if tt.url != "" {
    				tt.want.URL, _ = url.Parse(tt.url)
    			}
    			got, err := NewURL(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_Make(t *testing.T) {
    	tests := []struct {
    		name      string
    		id        string
    		extension string
    		url       string
    		want      string
    	}{
    		{
    			name: "Without action and extensions id's #1",
    			url:  "grpc:///extension-id/action-id",
    			want: "grpc:///extension-id/action-id",
    		},
    		{
    			name: "Without action and extensions id's #2",
    			url:  "ui:///space/env/coll",
    			want: "ui:///space/env/coll",
    		},
    		{
    			name: "Without action and extensions id's #3",
    			url:  "space/env/coll",
    			want: "space/env/coll",
    		},
    		{
    			name: "Without action and extensions id's #4",
    			url:  "https://perx.ru",
    			want: "https://perx.ru",
    		},
    		{
    			name:      "With action and extensions",
    			id:        "action-id",
    			extension: "extension-id",
    			want:      "grpc:///extension-id/action-id",
    		},
    	}
    	for _, tt := range tests {
    		t.Run(tt.name, func(t *testing.T) {
    			p := &URL{
    				id:        tt.id,
    				extension: tt.extension,
    			}
    			if tt.url != "" {
    				p.URL, _ = url.Parse(tt.url)
    			}
    			assert.Equalf(t, tt.want, p.Make(), "MakeFromURL()")
    		})
    	}
    }