<commit_before>package octav_test

import (
	"flag"
	"os"
	"testing"

	"github.com/builderscon/octav/octav"
	"github.com/builderscon/octav/octav/db"
	"github.com/lestrrat/go-pdebug"
	"github.com/stretchr/testify/assert"
)

func TestMain(m *testing.M) {
	flag.Parse()
	// We don't call m.Run() directly here so that we can
	// make sure that defer() gets fired.
	os.Exit(setupAndRun(m))
}

func setupAndRun(m *testing.M) int {
	if pdebug.Enabled {
		if fn := os.Getenv("OCTAV_DEBUG_FILE"); fn != "" {
			f, err := os.Create(fn)
			if err == nil {
				// Before setting the output file, notify via
				// the standard channel what's going to happen
				pdebug.Printf("OCTAV_DEBUG_FILE (%s) is available. Redirecting pdebug output", fn)
				pdebug.DefaultCtx.Writer = f
				defer f.Close()
			} else {
				pdebug.DefaultCtx.Writer = os.Stderr
				pdebug.Printf("Failed to open file '%s': %s", fn, err)
			}
		}
	}

	if dsn := os.Getenv("OCTAV_TEST_DSN"); dsn != "" {
		if pdebug.Enabled {
			pdebug.Printf("OCTAV_TEST_DSN (%s) is available. Initializing database", dsn)
		}
		if err := db.Init(dsn); err != nil {
			panic(err.Error())
		}
	}


	return m.Run()
}

func TestVenueDB(t *testing.T) {
	v := db.Venue{EID: octav.UUID()}
	if err := testVenueDBCreate(t, &v); err != nil {
		return
	}
	defer testVenueDBDelete(t, &v)
}

func testVenueDBDelete(t *testing.T, v *db.Venue) error {
	tx, err := db.Begin()<commit_msg>Use default DSN for test<commit_after>package octav_test

import (
	"flag"
	"os"
	"testing"

	"github.com/builderscon/octav/octav"
	"github.com/builderscon/octav/octav/db"
	"github.com/lestrrat/go-pdebug"
	"github.com/stretchr/testify/assert"
)

func TestMain(m *testing.M) {
	flag.Parse()
	// We don't call m.Run() directly here so that we can
	// make sure that defer() gets fired.
	os.Exit(setupAndRun(m))
}

func setupAndRun(m *testing.M) int {
	if pdebug.Enabled {
		if fn := os.Getenv("OCTAV_DEBUG_FILE"); fn != "" {
			f, err := os.Create(fn)
			if err == nil {
				// Before setting the output file, notify via
				// the standard channel what's going to happen
				pdebug.Printf("OCTAV_DEBUG_FILE (%s) is available. Redirecting pdebug output", fn)
				pdebug.DefaultCtx.Writer = f
				defer f.Close()
			} else {
				pdebug.DefaultCtx.Writer = os.Stderr
				pdebug.Printf("Failed to open file '%s': %s", fn, err)
			}
		}
	}

	var dsn string
	if dsn = os.Getenv("OCTAV_TEST_DSN"); dsn != "" {
		if pdebug.Enabled {
			pdebug.Printf("OCTAV_TEST_DSN (%s) is available", dsn)
		}
	} else {
		dsn = db.DefaultDSN
		if pdebug.Enabled {
			pdebug.Printf("Using default DSN '%s'", dsn)
		}
	}

	if pdebug.Enabled {
		pdebug.Printf("Initializing database...")
	}
	if err := db.Init(dsn); err != nil {
		panic(err.Error())
	}

	return m.Run()
}

func TestVenueDB(t *testing.T) {
	v := db.Venue{EID: octav.UUID()}
	if err := testVenueDBCreate(t, &v); err != nil {
		return
	}
	defer testVenueDBDelete(t, &v)
}

func testVenueDBDelete(t *testing.T, v *db.Venue) error {
	tx, err := db.Begin()
{'fraction_non_alphanumeric': 0.156686626746507, 'fraction_numerical': 0.0, 'mean_word_length': 3.383381924198251, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2838707', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1196, 'n_words': 278}