github.com/bishtawi/migrate/v4@v4.8.11/internal/url/url_test.go (about)

     1  package url
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestSchemeFromUrl(t *testing.T) {
     8  	cases := []struct {
     9  		name      string
    10  		urlStr    string
    11  		expected  string
    12  		expectErr error
    13  	}{
    14  		{
    15  			name:     "Simple",
    16  			urlStr:   "protocol://path",
    17  			expected: "protocol",
    18  		},
    19  		{
    20  			// See issue #264
    21  			name:     "MySQLWithPort",
    22  			urlStr:   "mysql://user:pass@tcp(host:1337)/db",
    23  			expected: "mysql",
    24  		},
    25  		{
    26  			name:      "Empty",
    27  			urlStr:    "",
    28  			expectErr: errEmptyURL,
    29  		},
    30  		{
    31  			name:      "NoScheme",
    32  			urlStr:    "hello",
    33  			expectErr: errNoScheme,
    34  		},
    35  	}
    36  
    37  	for _, tc := range cases {
    38  		t.Run(tc.name, func(t *testing.T) {
    39  			s, err := SchemeFromURL(tc.urlStr)
    40  			if err != tc.expectErr {
    41  				t.Fatalf("expected %q, but received %q", tc.expectErr, err)
    42  			}
    43  			if s != tc.expected {
    44  				t.Fatalf("expected %q, but received %q", tc.expected, s)
    45  			}
    46  		})
    47  	}
    48  }