<commit_before>package main

import (
	"github.com/stretchr/testify/assert"
)

func TestInitialMigration(t *testing.T) {
	assert := assert.New(t)

}<commit_msg>Add migration tests<commit_after>package main

import (
	"github.com/boltdb/bolt"
	"github.com/stretchr/testify/assert"
	"io/ioutil"
	"log"
	"os"
	"strconv"
	"strings"
	"testing"
)

func testDB(fn string) *bolt.DB {
	// Reset it
	_ = os.Remove(fn)

	db, err := bolt.Open(fn, 0600, nil)
	if err != nil {
		log.Fatal(err)
	}
	return db
}

func TestInitialMigration(t *testing.T) {
	assert := assert.New(t)

	db := testDB("test/migration1.db")
	err := InitialMigration(db)
	assert.Nil(err)

	v, err := getVersion(db)
	assert.Nil(err)
	assert.Equal(1, v)
}

func TestBackup(t *testing.T) {
	assert := assert.New(t)
	path := "test/backups/"
	_ = os.RemoveAll(path)

	db := testDB("test/backup.db")

	err := backup(db, 255, path)
	assert.Nil(err)

	files, err := ioutil.ReadDir(path)
	assert.Nil(err)
	assert.Equal(1, len(files))

	assert.True(
		strings.Contains(files[0].Name(), "_"+strconv.Itoa(255)+"-"),
		"Backup file did not contain the version number",
	)
}
{'fraction_non_alphanumeric': 0.1742627345844504, 'fraction_numerical': 0.012511170688114389, 'mean_word_length': 4.185185185185185, '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': '7274257', 'n_tokens_mistral': 479, 'n_tokens_neox': 462, 'n_words': 88}