Skip to content
Snippets Groups Projects
Select Git revision
  • 3c849fc692e8b63478c36aa7c666eb2b28b2d1e8
  • master default protected
  • feature/PRXS-3383-CollectionsRankSortAPI
  • feature/PRXS-3383-CollectionsSort
  • 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
  • feature/3272-GoVersionUp
  • feature/PRXS-3218-HideTemplateActions
  • feature/PRXS-3234-PruneIdents
  • feature/3146-UpdateItemStorageInterface
  • feature/3274-ObjectIndexesFixes
  • feature/PRXS-3143-3235-ReferenceOptions
  • feature/PRXS-3143-3237-ExecuteOptions
  • feature/3149-LocaleCodeAsID-Implementation
  • 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

file_test.go

Blame
  • file_test.go 2.24 KiB
    package files
    
    import (
    	"context"
    	"testing"
    	"text/template"
    
    	"git.perx.ru/perxis/perxis-go/pkg/expr"
    	"github.com/stretchr/testify/require"
    )
    
    func TestFile_SetURLWithTemplate(t *testing.T) {
    	tests := []struct {
    		name     string
    		file     *File
    		template *template.Template
    		wantErr  bool
    		wantURL  string
    	}{
    		{
    			name: "template is nil",
    			file: &File{
    				URL: "https://cloud.com/",
    			},
    			template: nil,
    			wantErr:  false,
    			wantURL:  "https://cloud.com/",
    		},
    		{
    			name:     "template with non-existent field",
    			file:     &File{},
    			template: template.Must(template.New("url").Parse("{{.NonExistentField}}")),
    			wantErr:  true,
    		},
    		{
    			name: "success",
    			file: &File{
    				Size:     1024,
    				MimeType: "image/png",
    				Key:      "file-key",
    			},
    			template: template.Must(template.New("url").Parse("https://cloud-proxy.com/{{.Key}}?size={{.Size}}#{{.MimeType}}")),
    			wantErr:  false,
    			wantURL:  "https://cloud-proxy.com/file-key?size=1024#image/png",
    		},
    	}
    
    	for _, tt := range tests {
    		t.Run(tt.name, func(t *testing.T) {
    			err := tt.file.SetURLWithTemplate(tt.template)
    			if tt.wantErr {
    				require.Error(t, err)
    			} else {
    				require.NoError(t, err)
    				require.Equal(t, tt.wantURL, tt.file.URL)
    			}
    		})
    	}
    }
    
    func TestFile_InExpr(t *testing.T) {
    	ctx := context.Background()
    
    	tests := []struct {
    		exp        string
    		env        map[string]interface{}
    		wantResult interface{}
    		wantErr    bool
    	}{
    		{"f.id", map[string]interface{}{"f": &File{ID: "some_id"}}, "some_id", false},