github.com/mad-app/mattermost-server@v5.11.1+incompatible/store/sqlstore/utils_test.go (about)

     1  package sqlstore
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestMapStringsToQueryParams(t *testing.T) {
     8  	t.Run("one item", func(t *testing.T) {
     9  		input := []string{"apple"}
    10  
    11  		keys, params := MapStringsToQueryParams(input, "Fruit")
    12  
    13  		if len(params) != 1 || params["Fruit0"] != "apple" {
    14  			t.Fatal("returned incorrect params", params)
    15  		} else if keys != "(:Fruit0)" {
    16  			t.Fatal("returned incorrect query", keys)
    17  		}
    18  	})
    19  
    20  	t.Run("multiple items", func(t *testing.T) {
    21  		input := []string{"carrot", "tomato", "potato"}
    22  
    23  		keys, params := MapStringsToQueryParams(input, "Vegetable")
    24  
    25  		if len(params) != 3 || params["Vegetable0"] != "carrot" ||
    26  			params["Vegetable1"] != "tomato" || params["Vegetable2"] != "potato" {
    27  			t.Fatal("returned incorrect params", params)
    28  		} else if keys != "(:Vegetable0,:Vegetable1,:Vegetable2)" {
    29  			t.Fatal("returned incorrect query", keys)
    30  		}
    31  	})
    32  }