github.com/emcfarlane/larking@v0.0.0-20220605172417-1704b45ee6c3/examples/library/main_test.go (about)

     1  package main
     2  
     3  import (
     4  	"database/sql"
     5  	"testing"
     6  
     7  	"github.com/emcfarlane/larking"
     8  	"github.com/emcfarlane/larking/examples/library/apipb"
     9  	"github.com/emcfarlane/larking/starlib"
    10  	"go.starlark.net/starlark"
    11  )
    12  
    13  func TestScripts(t *testing.T) {
    14  	db, err := sql.Open("sqlite", "file::memory:?cache=shared")
    15  	if err != nil {
    16  		t.Fatal(err)
    17  	}
    18  	t.Cleanup(func() { db.Close() })
    19  	if err := createTables(db); err != nil {
    20  		t.Fatal(err)
    21  	}
    22  
    23  	s := &Server{db: db}
    24  
    25  	mux, err := larking.NewMux()
    26  	if err != nil {
    27  		t.Fatal(err)
    28  	}
    29  	mux.RegisterService(&apipb.Library_ServiceDesc, s)
    30  
    31  	starlib.RunTests(t, "testdata/*.star", starlark.StringDict{
    32  		"mux": mux,
    33  	})
    34  }