github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/service/sqlite_service_test.go (about) 1 package service_test 2 3 import ( 4 "os" 5 6 . "github.com/onsi/gomega" 7 8 "github.com/pyroscope-io/pyroscope/pkg/config" 9 "github.com/pyroscope-io/pyroscope/pkg/sqlstore" 10 ) 11 12 // testSuite is supposed to be DB-specific: once we add support for other 13 // SQL databases, each of them should have its own one; build tags are to 14 // be used in order to run tests with a particular SQL driver. 15 type testSuite struct { 16 *sqlstore.SQLStore 17 path string 18 } 19 20 func (s *testSuite) BeforeEach() { 21 c := config.Database{ 22 Type: "sqlite3", 23 URL: "file::memory:?cache=shared", 24 } 25 if s.path != "" { 26 c.URL = s.path 27 } 28 var err error 29 s.SQLStore, err = sqlstore.Open(&config.Server{Database: c}) 30 Expect(err).ToNot(HaveOccurred()) 31 } 32 33 func (s *testSuite) AfterEach() { 34 defer func() { 35 if s.path != "" { 36 Expect(os.RemoveAll(s.path)).ToNot(HaveOccurred()) 37 } 38 }() 39 Expect(s.Close()).ToNot(HaveOccurred()) 40 }