github.com/google/fleetspeak@v0.1.15-0.20240426164851-4f31f62c1aea/fleetspeak/src/server/sqlite/sqlite_test.go (about)

     1  // Copyright 2017 Google Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package sqlite
    16  
    17  import (
    18  	"fmt"
    19  	"path"
    20  	"testing"
    21  
    22  	"github.com/google/fleetspeak/fleetspeak/src/comtesting"
    23  
    24  	log "github.com/golang/glog"
    25  
    26  	"github.com/google/fleetspeak/fleetspeak/src/server/db"
    27  	"github.com/google/fleetspeak/fleetspeak/src/server/dbtesting"
    28  )
    29  
    30  type sqliteTestEnv struct {
    31  	tempDirCleanup func()
    32  	counter        int
    33  }
    34  
    35  func (e *sqliteTestEnv) Create() error {
    36  	return nil
    37  }
    38  
    39  func (e *sqliteTestEnv) Clean() (db.Store, error) {
    40  	dir, fn := comtesting.GetTempDir("sqlite_test")
    41  	e.tempDirCleanup = fn
    42  
    43  	p := path.Join(dir, fmt.Sprintf("%d.sqlite", e.counter))
    44  	e.counter++
    45  
    46  	log.Infof("Using database: %v", p)
    47  	s, err := MakeDatastore(p)
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  	return s, nil
    52  }
    53  
    54  func (e *sqliteTestEnv) Destroy() error {
    55  	e.tempDirCleanup()
    56  	return nil
    57  }
    58  
    59  func TestSqliteStore(t *testing.T) {
    60  	dbtesting.DataStoreTestSuite(t, &sqliteTestEnv{})
    61  }