github.com/tuhaihe/gpbackup@v1.0.3/integration/predata_textsearch_queries_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"github.com/tuhaihe/gp-common-go-libs/structmatcher"
     5  	"github.com/tuhaihe/gp-common-go-libs/testhelper"
     6  	"github.com/tuhaihe/gpbackup/backup"
     7  	"github.com/tuhaihe/gpbackup/options"
     8  	"github.com/tuhaihe/gpbackup/testutils"
     9  
    10  	. "github.com/onsi/ginkgo/v2"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("backup integration tests", func() {
    15  	Describe("GetTextSearchParsers", func() {
    16  		BeforeEach(func() {
    17  			testutils.SkipIfBefore5(connectionPool)
    18  		})
    19  		It("returns a text search parser without a headline", func() {
    20  			testhelper.AssertQueryRuns(connectionPool, "CREATE TEXT SEARCH PARSER public.testparser(START = prsd_start, GETTOKEN = prsd_nexttoken, END = prsd_end, LEXTYPES = prsd_lextype);")
    21  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH PARSER public.testparser")
    22  			parsers := backup.GetTextSearchParsers(connectionPool)
    23  
    24  			expectedParser := backup.TextSearchParser{Oid: 1, Schema: "public", Name: "testparser", StartFunc: "prsd_start", TokenFunc: "prsd_nexttoken", EndFunc: "prsd_end", LexTypesFunc: "prsd_lextype", HeadlineFunc: ""}
    25  
    26  			Expect(parsers).To(HaveLen(1))
    27  			structmatcher.ExpectStructsToMatchExcluding(&expectedParser, &parsers[0], "Oid")
    28  		})
    29  		It("returns a text search parser with a headline", func() {
    30  			testhelper.AssertQueryRuns(connectionPool, "CREATE TEXT SEARCH PARSER public.testparser(START = prsd_start, GETTOKEN = prsd_nexttoken, END = prsd_end, LEXTYPES = prsd_lextype, HEADLINE = prsd_headline);")
    31  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH PARSER public.testparser")
    32  			parsers := backup.GetTextSearchParsers(connectionPool)
    33  
    34  			expectedParser := backup.TextSearchParser{Oid: 1, Schema: "public", Name: "testparser", StartFunc: "prsd_start", TokenFunc: "prsd_nexttoken", EndFunc: "prsd_end", LexTypesFunc: "prsd_lextype", HeadlineFunc: "prsd_headline"}
    35  
    36  			Expect(parsers).To(HaveLen(1))
    37  			structmatcher.ExpectStructsToMatchExcluding(&expectedParser, &parsers[0], "Oid")
    38  		})
    39  		It("returns a text search parser from a specific schema ", func() {
    40  			testhelper.AssertQueryRuns(connectionPool, "CREATE TEXT SEARCH PARSER public.testparser(START = prsd_start, GETTOKEN = prsd_nexttoken, END = prsd_end, LEXTYPES = prsd_lextype);")
    41  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH PARSER public.testparser")
    42  			testhelper.AssertQueryRuns(connectionPool, "CREATE SCHEMA testschema")
    43  			defer testhelper.AssertQueryRuns(connectionPool, "DROP SCHEMA testschema")
    44  			testhelper.AssertQueryRuns(connectionPool, "CREATE TEXT SEARCH PARSER testschema.testparser(START = prsd_start, GETTOKEN = prsd_nexttoken, END = prsd_end, LEXTYPES = prsd_lextype);")
    45  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH PARSER testschema.testparser")
    46  			_ = backupCmdFlags.Set(options.INCLUDE_SCHEMA, "testschema")
    47  
    48  			parsers := backup.GetTextSearchParsers(connectionPool)
    49  
    50  			expectedParser := backup.TextSearchParser{Oid: 1, Schema: "testschema", Name: "testparser", StartFunc: "prsd_start", TokenFunc: "prsd_nexttoken", EndFunc: "prsd_end", LexTypesFunc: "prsd_lextype", HeadlineFunc: ""}
    51  
    52  			Expect(parsers).To(HaveLen(1))
    53  			structmatcher.ExpectStructsToMatchExcluding(&expectedParser, &parsers[0], "Oid")
    54  		})
    55  	})
    56  	Describe("GetTextSearchTemplates", func() {
    57  		BeforeEach(func() {
    58  			testutils.SkipIfBefore5(connectionPool)
    59  		})
    60  		It("returns a text search template without an init function", func() {
    61  			testhelper.AssertQueryRuns(connectionPool, "CREATE TEXT SEARCH TEMPLATE public.testtemplate(LEXIZE = dsimple_lexize);")
    62  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH TEMPLATE public.testtemplate")
    63  			templates := backup.GetTextSearchTemplates(connectionPool)
    64  
    65  			expectedTemplate := backup.TextSearchTemplate{Oid: 1, Schema: "public", Name: "testtemplate", InitFunc: "", LexizeFunc: "dsimple_lexize"}
    66  
    67  			Expect(templates).To(HaveLen(1))
    68  			structmatcher.ExpectStructsToMatchExcluding(&expectedTemplate, &templates[0], "Oid")
    69  		})
    70  		It("returns a text search template with an init function", func() {
    71  			testhelper.AssertQueryRuns(connectionPool, "CREATE TEXT SEARCH TEMPLATE public.testtemplate(INIT = dsimple_init, LEXIZE = dsimple_lexize);")
    72  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH TEMPLATE public.testtemplate")
    73  			templates := backup.GetTextSearchTemplates(connectionPool)
    74  
    75  			expectedTemplate := backup.TextSearchTemplate{Oid: 1, Schema: "public", Name: "testtemplate", InitFunc: "dsimple_init", LexizeFunc: "dsimple_lexize"}
    76  
    77  			Expect(templates).To(HaveLen(1))
    78  			structmatcher.ExpectStructsToMatchExcluding(&expectedTemplate, &templates[0], "Oid")
    79  		})
    80  		It("returns a text search template from a specific schema", func() {
    81  			testhelper.AssertQueryRuns(connectionPool, "CREATE TEXT SEARCH TEMPLATE public.testtemplate(LEXIZE = dsimple_lexize);")
    82  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH TEMPLATE public.testtemplate")
    83  			testhelper.AssertQueryRuns(connectionPool, "CREATE SCHEMA testschema")
    84  			defer testhelper.AssertQueryRuns(connectionPool, "DROP SCHEMA testschema")
    85  			testhelper.AssertQueryRuns(connectionPool, "CREATE TEXT SEARCH TEMPLATE testschema.testtemplate(LEXIZE = dsimple_lexize);")
    86  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH TEMPLATE testschema.testtemplate")
    87  
    88  			_ = backupCmdFlags.Set(options.INCLUDE_SCHEMA, "testschema")
    89  			templates := backup.GetTextSearchTemplates(connectionPool)
    90  
    91  			expectedTemplate := backup.TextSearchTemplate{Oid: 1, Schema: "testschema", Name: "testtemplate", InitFunc: "", LexizeFunc: "dsimple_lexize"}
    92  
    93  			Expect(templates).To(HaveLen(1))
    94  			structmatcher.ExpectStructsToMatchExcluding(&expectedTemplate, &templates[0], "Oid")
    95  		})
    96  	})
    97  	Describe("GetTextSearchDictionaries", func() {
    98  		BeforeEach(func() {
    99  			testutils.SkipIfBefore5(connectionPool)
   100  		})
   101  		It("returns a text search dictionary with init options", func() {
   102  			testhelper.AssertQueryRuns(connectionPool, "CREATE TEXT SEARCH DICTIONARY public.testdictionary(TEMPLATE = snowball, LANGUAGE = 'russian', STOPWORDS = 'russian');")
   103  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH DICTIONARY public.testdictionary")
   104  			dictionaries := backup.GetTextSearchDictionaries(connectionPool)
   105  
   106  			expectedDictionary := backup.TextSearchDictionary{Oid: 1, Schema: "public", Name: "testdictionary", Template: "pg_catalog.snowball", InitOption: "language = 'russian', stopwords = 'russian'"}
   107  			Expect(dictionaries).To(HaveLen(1))
   108  			structmatcher.ExpectStructsToMatchExcluding(&expectedDictionary, &dictionaries[0], "Oid")
   109  		})
   110  		It("returns a text search dictionary without init options", func() {
   111  			testhelper.AssertQueryRuns(connectionPool, "CREATE TEXT SEARCH DICTIONARY public.testdictionary (TEMPLATE = 'simple');")
   112  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH DICTIONARY public.testdictionary")
   113  			dictionaries := backup.GetTextSearchDictionaries(connectionPool)
   114  
   115  			expectedDictionary := backup.TextSearchDictionary{Oid: 1, Schema: "public", Name: "testdictionary", Template: "pg_catalog.simple", InitOption: ""}
   116  			Expect(dictionaries).To(HaveLen(1))
   117  			structmatcher.ExpectStructsToMatchExcluding(&expectedDictionary, &dictionaries[0], "Oid")
   118  		})
   119  		It("returns a text search dictionary from a specific schema", func() {
   120  			testhelper.AssertQueryRuns(connectionPool, "CREATE TEXT SEARCH DICTIONARY public.testdictionary (TEMPLATE = 'simple');")
   121  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH DICTIONARY public.testdictionary")
   122  			testhelper.AssertQueryRuns(connectionPool, "CREATE SCHEMA testschema")
   123  			defer testhelper.AssertQueryRuns(connectionPool, "DROP SCHEMA testschema")
   124  			testhelper.AssertQueryRuns(connectionPool, "CREATE TEXT SEARCH DICTIONARY testschema.testdictionary (TEMPLATE = 'simple');")
   125  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH DICTIONARY testschema.testdictionary")
   126  
   127  			_ = backupCmdFlags.Set(options.INCLUDE_SCHEMA, "testschema")
   128  			dictionaries := backup.GetTextSearchDictionaries(connectionPool)
   129  
   130  			expectedDictionary := backup.TextSearchDictionary{Oid: 1, Schema: "testschema", Name: "testdictionary", Template: "pg_catalog.simple", InitOption: ""}
   131  			Expect(dictionaries).To(HaveLen(1))
   132  			structmatcher.ExpectStructsToMatchExcluding(&expectedDictionary, &dictionaries[0], "Oid")
   133  		})
   134  	})
   135  	Describe("GetTextSearchConfigurations", func() {
   136  		BeforeEach(func() {
   137  			testutils.SkipIfBefore5(connectionPool)
   138  		})
   139  		It("returns a text search configuration without an init function", func() {
   140  			testhelper.AssertQueryRuns(connectionPool, `CREATE TEXT SEARCH CONFIGURATION public.testconfiguration (PARSER = pg_catalog."default");`)
   141  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH CONFIGURATION public.testconfiguration")
   142  			configurations := backup.GetTextSearchConfigurations(connectionPool)
   143  
   144  			expectedConfiguration := backup.TextSearchConfiguration{Oid: 1, Schema: "public", Name: "testconfiguration", Parser: `pg_catalog."default"`, TokenToDicts: map[string][]string{}}
   145  
   146  			Expect(configurations).To(HaveLen(1))
   147  			structmatcher.ExpectStructsToMatchExcluding(&expectedConfiguration, &configurations[0], "Oid")
   148  		})
   149  		It("returns a text search configuration with an init function", func() {
   150  			testhelper.AssertQueryRuns(connectionPool, `CREATE TEXT SEARCH CONFIGURATION public.testconfiguration ( PARSER = pg_catalog."default");`)
   151  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH CONFIGURATION public.testconfiguration")
   152  			configurations := backup.GetTextSearchConfigurations(connectionPool)
   153  
   154  			expectedConfiguration := backup.TextSearchConfiguration{Oid: 1, Schema: "public", Name: "testconfiguration", Parser: `pg_catalog."default"`, TokenToDicts: map[string][]string{}}
   155  
   156  			Expect(configurations).To(HaveLen(1))
   157  			structmatcher.ExpectStructsToMatchExcluding(&expectedConfiguration, &configurations[0], "Oid")
   158  		})
   159  		It("returns a text search configuration with mappings", func() {
   160  			testhelper.AssertQueryRuns(connectionPool, `CREATE TEXT SEARCH CONFIGURATION public.testconfiguration ( PARSER = pg_catalog."default");`)
   161  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH CONFIGURATION public.testconfiguration")
   162  
   163  			testhelper.AssertQueryRuns(connectionPool, "ALTER TEXT SEARCH CONFIGURATION public.testconfiguration ADD MAPPING FOR uint WITH simple;")
   164  			testhelper.AssertQueryRuns(connectionPool, "ALTER TEXT SEARCH CONFIGURATION public.testconfiguration ADD MAPPING FOR asciiword WITH danish_stem;")
   165  
   166  			configurations := backup.GetTextSearchConfigurations(connectionPool)
   167  
   168  			expectedConfiguration := backup.TextSearchConfiguration{Oid: 1, Schema: "public", Name: "testconfiguration", Parser: `pg_catalog."default"`, TokenToDicts: map[string][]string{}}
   169  			expectedConfiguration.TokenToDicts = map[string][]string{"uint": {"simple"}, "asciiword": {"danish_stem"}}
   170  
   171  			Expect(configurations).To(HaveLen(1))
   172  			structmatcher.ExpectStructsToMatchExcluding(&expectedConfiguration, &configurations[0], "Oid")
   173  		})
   174  		It("returns a text search configuration from a specific schema", func() {
   175  			testhelper.AssertQueryRuns(connectionPool, `CREATE TEXT SEARCH CONFIGURATION public.testconfiguration (PARSER = pg_catalog."default");`)
   176  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH CONFIGURATION public.testconfiguration")
   177  			testhelper.AssertQueryRuns(connectionPool, "CREATE SCHEMA testschema")
   178  			defer testhelper.AssertQueryRuns(connectionPool, "DROP SCHEMA testschema")
   179  			testhelper.AssertQueryRuns(connectionPool, `CREATE TEXT SEARCH CONFIGURATION testschema.testconfiguration (PARSER = pg_catalog."default");`)
   180  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH CONFIGURATION testschema.testconfiguration")
   181  
   182  			_ = backupCmdFlags.Set(options.INCLUDE_SCHEMA, "testschema")
   183  			configurations := backup.GetTextSearchConfigurations(connectionPool)
   184  
   185  			expectedConfiguration := backup.TextSearchConfiguration{Oid: 1, Schema: "testschema", Name: "testconfiguration", Parser: `pg_catalog."default"`, TokenToDicts: map[string][]string{}}
   186  
   187  			Expect(configurations).To(HaveLen(1))
   188  			structmatcher.ExpectStructsToMatchExcluding(&expectedConfiguration, &configurations[0], "Oid")
   189  		})
   190  	})
   191  })