github.com/mrqzzz/migrate@v5.1.7+incompatible/database/util_test.go (about)

     1  package database
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestGenerateAdvisoryLockId(t *testing.T) {
     8  	testcases := []struct {
     9  		dbname     string
    10  		additional []string
    11  		expectedID string // empty string signifies that an error is expected
    12  	}{
    13  		{
    14  			dbname:     "database_name",
    15  			expectedID: "1764327054",
    16  		},
    17  		{
    18  			dbname:     "database_name",
    19  			additional: []string{"schema_name_1"},
    20  			expectedID: "2453313553",
    21  		},
    22  		{
    23  			dbname:     "database_name",
    24  			additional: []string{"schema_name_2"},
    25  			expectedID: "235207038",
    26  		},
    27  		{
    28  			dbname:     "database_name",
    29  			additional: []string{"schema_name_1", "schema_name_2"},
    30  			expectedID: "3743845847",
    31  		},
    32  	}
    33  
    34  	for _, tc := range testcases {
    35  		t.Run(tc.dbname, func(t *testing.T) {
    36  			if id, err := GenerateAdvisoryLockId(tc.dbname, tc.additional...); err == nil {
    37  				if id != tc.expectedID {
    38  					t.Error("Generated incorrect ID:", id, "!=", tc.expectedID)
    39  				}
    40  			} else {
    41  				if tc.expectedID != "" {
    42  					t.Error("Got unexpected error:", err)
    43  				}
    44  			}
    45  		})
    46  	}
    47  }