z_test.go 627 B

123456789101112131415161718192021222324252627282930313233
  1. package nosql
  2. import (
  3. "context"
  4. "io/ioutil"
  5. "testing"
  6. "github.com/jackc/pgx/v5"
  7. )
  8. var (
  9. dbConn string
  10. )
  11. func init() {
  12. // read postgres connection string from file z_data.config
  13. connSource, _ := ioutil.ReadFile("z_data.config")
  14. dbConn = string(connSource)
  15. }
  16. func TestNoSQL(t *testing.T) {
  17. if db, err := pgx.Connect(context.Background(), dbConn); err == nil {
  18. ex := New(func(ctx context.Context) (pgx.Tx, error) {
  19. return db.Begin(ctx)
  20. })
  21. res, err := ex.Call(context.Background(), "public.arr_count", map[string]interface{}{
  22. "input": []int{0, 1, 2},
  23. })
  24. t.Log(res, err)
  25. } else {
  26. t.Error(err)
  27. }
  28. }