github.com/newrelic/go-agent@v3.26.0+incompatible/_integrations/nrsqlite3/nrsqlite3_test.go (about)

     1  // Copyright 2020 New Relic Corporation. All rights reserved.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package nrsqlite3
     5  
     6  import (
     7  	"path/filepath"
     8  	"runtime"
     9  	"testing"
    10  )
    11  
    12  func TestGetPortPathOrID(t *testing.T) {
    13  	_, here, _, _ := runtime.Caller(0)
    14  	currentDir := filepath.Dir(here)
    15  
    16  	testcases := []struct {
    17  		dsn      string
    18  		expected string
    19  	}{
    20  		{":memory:", ":memory:"},
    21  		{"test.db", filepath.Join(currentDir, "test.db")},
    22  		{"file:/test.db?cache=shared&mode=memory", "/test.db"},
    23  		{"file::memory:", ":memory:"},
    24  		{"", ""},
    25  	}
    26  
    27  	for _, test := range testcases {
    28  		if actual := getPortPathOrID(test.dsn); actual != test.expected {
    29  			t.Errorf(`incorrect port path or id: dsn="%s", actual="%s"`, test.dsn, actual)
    30  		}
    31  	}
    32  }