github.com/github/skeema@v1.2.6/util/cache_test.go (about)

     1  package util
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/skeema/tengo"
     7  )
     8  
     9  func TestNewInstance(t *testing.T) {
    10  	getNewInstance := func(driver, dsn string) *tengo.Instance {
    11  		t.Helper()
    12  		inst, err := NewInstance(driver, dsn)
    13  		if err != nil {
    14  			t.Fatalf("Unexpected error from NewInstance: %s", err)
    15  		}
    16  		return inst
    17  	}
    18  
    19  	inst1 := getNewInstance("mysql", "username:password@tcp(1.2.3.4:3306)/?param1=value1&readTimeout=5s&interpolateParams=0")
    20  	inst2 := getNewInstance("mysql", "username:password@tcp(1.2.3.4:3306)/?param1=value1&readTimeout=5s&interpolateParams=0")
    21  	inst3 := getNewInstance("mysql", "username:password@tcp(1.2.3.4:3306)/?readTimeout=5s&interpolateParams=0")
    22  	if inst1 != inst2 {
    23  		t.Error("Expected inst1 and inst2 to point to same instance, but they do not")
    24  	} else if inst1 == inst3 {
    25  		t.Error("Expected inst1 and inst3 to point to different instances, but they do not")
    26  	}
    27  
    28  	if _, err := NewInstance("btrieve", "username:password@tcp(some.host)/dbname?param=value"); err == nil {
    29  		t.Error("Expected bad driver to return error, but it did not")
    30  	}
    31  }