github.com/haalcala/mattermost-server-change-repo/v5@v5.33.2/store/sqlstore/post_store_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package sqlstore
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/mattermost/mattermost-server/v5/store/searchtest"
    12  	"github.com/mattermost/mattermost-server/v5/store/storetest"
    13  )
    14  
    15  func TestPostStore(t *testing.T) {
    16  	StoreTestWithSqlStore(t, storetest.TestPostStore)
    17  }
    18  
    19  func TestSearchPostStore(t *testing.T) {
    20  	StoreTestWithSearchTestEngine(t, searchtest.TestSearchPostStore)
    21  }
    22  
    23  func TestMysqlStopWords(t *testing.T) {
    24  	mysqlStopWordsTests := []struct {
    25  		Name     string
    26  		Args     []string
    27  		Expected []string
    28  		Empty    bool
    29  	}{
    30  		{
    31  			Name:     "Should remove only the stop words",
    32  			Args:     []string{"where is my car", "so this is real", "test this-and-that is awesome"},
    33  			Expected: []string{"my car", "so real", "test this-and-that awesome"},
    34  		},
    35  		{
    36  			Name:     "Should not remove part of a word containing stop words",
    37  			Args:     []string{"whereabouts", "wherein", "tothis", "thisorthat", "waswhen", "whowas", "inthe", "whowill", "thewww"},
    38  			Expected: []string{"whereabouts", "wherein", "tothis", "thisorthat", "waswhen", "whowas", "inthe", "whowill", "thewww"},
    39  		},
    40  		{
    41  			Name:  "Should remove all words from terms",
    42  			Args:  []string{"where about", "where in", "to this", "this or that", "was when", "who was", "in the", "who will", "the www"},
    43  			Empty: true,
    44  		},
    45  		{
    46  			Name:     "Should not remove part of a word containing stop words separated by hyphens",
    47  			Args:     []string{"where-about", "where-in", "to-this", "this-or-that", "was-when", "who-was", "in-the", "who-will", "the-www"},
    48  			Expected: []string{"where-about", "where-in", "to-this", "this-or-that", "was-when", "who-was", "in-the", "who-will", "the-www"},
    49  		},
    50  	}
    51  
    52  	for _, tc := range mysqlStopWordsTests {
    53  		t.Run(tc.Name, func(t *testing.T) {
    54  			for i, term := range tc.Args {
    55  				got, err := removeMysqlStopWordsFromTerms(term)
    56  				require.NoError(t, err)
    57  				if tc.Empty {
    58  					require.Empty(t, got)
    59  				} else {
    60  					require.Equal(t, tc.Expected[i], got)
    61  				}
    62  			}
    63  		})
    64  	}
    65  }