github.com/tuhaihe/gpbackup@v1.0.3/integration/predata_textsearch_create_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/testutils"
     8  
     9  	. "github.com/onsi/ginkgo/v2"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("backup integration create statement tests", func() {
    14  	BeforeEach(func() {
    15  		testutils.SkipIfBefore5(connectionPool)
    16  		tocfile, backupfile = testutils.InitializeTestTOC(buffer, "predata")
    17  	})
    18  	Describe("PrintCreateTextSearchParserStatements", func() {
    19  		parser := backup.TextSearchParser{Oid: 0, Schema: "public", Name: "testparser", StartFunc: "prsd_start", TokenFunc: "prsd_nexttoken", EndFunc: "prsd_end", LexTypesFunc: "prsd_lextype", HeadlineFunc: "prsd_headline"}
    20  		It("creates a basic text search parser", func() {
    21  			backup.PrintCreateTextSearchParserStatement(backupfile, tocfile, parser, backup.ObjectMetadata{})
    22  
    23  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
    24  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH PARSER public.testparser")
    25  
    26  			resultParsers := backup.GetTextSearchParsers(connectionPool)
    27  
    28  			Expect(resultParsers).To(HaveLen(1))
    29  			structmatcher.ExpectStructsToMatchExcluding(&parser, &resultParsers[0], "Oid")
    30  		})
    31  		It("creates a basic text search parser with a comment", func() {
    32  			parserMetadata := testutils.DefaultMetadata("TEXT SEARCH PARSER", false, false, true, false)
    33  
    34  			backup.PrintCreateTextSearchParserStatement(backupfile, tocfile, parser, parserMetadata)
    35  
    36  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
    37  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH PARSER public.testparser")
    38  
    39  			resultParsers := backup.GetTextSearchParsers(connectionPool)
    40  			resultMetadataMap := backup.GetCommentsForObjectType(connectionPool, backup.TYPE_TSPARSER)
    41  
    42  			Expect(resultParsers).To(HaveLen(1))
    43  			structmatcher.ExpectStructsToMatchExcluding(&parser, &resultParsers[0], "Oid")
    44  			resultMetadata := resultMetadataMap[resultParsers[0].GetUniqueID()]
    45  			structmatcher.ExpectStructsToMatch(&parserMetadata, &resultMetadata)
    46  		})
    47  	})
    48  	Describe("PrintCreateTextSearchTemplateStatement", func() {
    49  		template := backup.TextSearchTemplate{Oid: 1, Schema: "public", Name: "testtemplate", InitFunc: "dsimple_init", LexizeFunc: "dsimple_lexize"}
    50  		It("creates a basic text search template", func() {
    51  			backup.PrintCreateTextSearchTemplateStatement(backupfile, tocfile, template, backup.ObjectMetadata{})
    52  
    53  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
    54  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH TEMPLATE public.testtemplate")
    55  
    56  			resultTemplates := backup.GetTextSearchTemplates(connectionPool)
    57  
    58  			Expect(resultTemplates).To(HaveLen(1))
    59  			structmatcher.ExpectStructsToMatchExcluding(&template, &resultTemplates[0], "Oid")
    60  		})
    61  		It("creates a basic text search template with a comment", func() {
    62  			templateMetadata := testutils.DefaultMetadata("TEXT SEARCH TEMPLATE", false, false, true, false)
    63  
    64  			backup.PrintCreateTextSearchTemplateStatement(backupfile, tocfile, template, templateMetadata)
    65  
    66  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
    67  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH TEMPLATE public.testtemplate")
    68  
    69  			resultTemplates := backup.GetTextSearchTemplates(connectionPool)
    70  			resultMetadataMap := backup.GetCommentsForObjectType(connectionPool, backup.TYPE_TSTEMPLATE)
    71  
    72  			Expect(resultTemplates).To(HaveLen(1))
    73  			uniqueID := testutils.UniqueIDFromObjectName(connectionPool, "public", "testtemplate", backup.TYPE_TSTEMPLATE)
    74  			resultMetadata := resultMetadataMap[uniqueID]
    75  			structmatcher.ExpectStructsToMatchExcluding(&template, &resultTemplates[0], "Oid")
    76  			structmatcher.ExpectStructsToMatch(&templateMetadata, &resultMetadata)
    77  		})
    78  	})
    79  	Describe("PrintCreateTextSearchDictionaryStatement", func() {
    80  		dictionary := backup.TextSearchDictionary{Oid: 1, Schema: "public", Name: "testdictionary", Template: "pg_catalog.snowball", InitOption: "language = 'russian', stopwords = 'russian'"}
    81  		It("creates a basic text search dictionary", func() {
    82  
    83  			backup.PrintCreateTextSearchDictionaryStatement(backupfile, tocfile, dictionary, backup.ObjectMetadata{})
    84  
    85  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
    86  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH DICTIONARY public.testdictionary")
    87  
    88  			resultDictionaries := backup.GetTextSearchDictionaries(connectionPool)
    89  
    90  			Expect(resultDictionaries).To(HaveLen(1))
    91  			structmatcher.ExpectStructsToMatchExcluding(&dictionary, &resultDictionaries[0], "Oid")
    92  		})
    93  		It("creates a basic text search dictionary with a comment and owner", func() {
    94  			dictionaryMetadata := testutils.DefaultMetadata("TEXT SEARCH DICTIONARY", false, true, true, false)
    95  
    96  			backup.PrintCreateTextSearchDictionaryStatement(backupfile, tocfile, dictionary, dictionaryMetadata)
    97  
    98  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
    99  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH DICTIONARY public.testdictionary")
   100  
   101  			resultDictionaries := backup.GetTextSearchDictionaries(connectionPool)
   102  			resultMetadataMap := backup.GetMetadataForObjectType(connectionPool, backup.TYPE_TSDICTIONARY)
   103  
   104  			Expect(resultDictionaries).To(HaveLen(1))
   105  			uniqueID := testutils.UniqueIDFromObjectName(connectionPool, "public", "testdictionary", backup.TYPE_TSDICTIONARY)
   106  			resultMetadata := resultMetadataMap[uniqueID]
   107  			structmatcher.ExpectStructsToMatchExcluding(&dictionary, &resultDictionaries[0], "Oid")
   108  			structmatcher.ExpectStructsToMatch(&dictionaryMetadata, &resultMetadata)
   109  		})
   110  	})
   111  	Describe("PrintCreateTextSearchConfigurationStatement", func() {
   112  		configuration := backup.TextSearchConfiguration{Oid: 1, Schema: "public", Name: "testconfiguration", Parser: `pg_catalog."default"`, TokenToDicts: map[string][]string{}}
   113  		It("creates a basic text search configuration", func() {
   114  			backup.PrintCreateTextSearchConfigurationStatement(backupfile, tocfile, configuration, backup.ObjectMetadata{})
   115  
   116  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   117  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH CONFIGURATION public.testconfiguration")
   118  
   119  			resultConfigurations := backup.GetTextSearchConfigurations(connectionPool)
   120  
   121  			Expect(resultConfigurations).To(HaveLen(1))
   122  			structmatcher.ExpectStructsToMatchExcluding(&configuration, &resultConfigurations[0], "Oid")
   123  		})
   124  		It("creates a basic text search configuration with a comment and owner", func() {
   125  			configurationMetadata := testutils.DefaultMetadata("TEXT SEARCH CONFIGURATION", false, true, true, false)
   126  
   127  			backup.PrintCreateTextSearchConfigurationStatement(backupfile, tocfile, configuration, configurationMetadata)
   128  
   129  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   130  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TEXT SEARCH CONFIGURATION public.testconfiguration")
   131  
   132  			resultConfigurations := backup.GetTextSearchConfigurations(connectionPool)
   133  			resultMetadataMap := backup.GetMetadataForObjectType(connectionPool, backup.TYPE_TSCONFIGURATION)
   134  
   135  			Expect(resultConfigurations).To(HaveLen(1))
   136  			uniqueID := testutils.UniqueIDFromObjectName(connectionPool, "public", "testconfiguration", backup.TYPE_TSCONFIGURATION)
   137  			resultMetadata := resultMetadataMap[uniqueID]
   138  			structmatcher.ExpectStructsToMatchExcluding(&configuration, &resultConfigurations[0], "Oid")
   139  			structmatcher.ExpectStructsToMatch(&configurationMetadata, &resultMetadata)
   140  		})
   141  	})
   142  })