<commit_before>package dashboard

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

var (
	dbMigrator = NewMigrator("test.db")
	dbManager = NewDbManager("test.db")
)

func TestDbManager(t *testing.T) {
	errors, ok := dbMigrator.Up()
	if !ok {
		t.Fatal("Migrations Up: ", errors)
	}
	t.Run("Successfully insert widget info", func(t *testing.T) {
		var widget = &Widget{Url:"http://example.com", ID:"test_widget_1", Height:350, Width:400}
		count, err := dbManager.InsertWidget(widget)
		if err != nil {
			t.Fatal("ERROR:", err)
		}
		assert.Equal(t, int64(1), count)
	})
	errors, ok = dbMigrator.Down()
	if !ok {
		t.Fatal("Migrations Down: ", errors)
	}
	err := dbManager.Close()
	if err != nil {
		t.Fatal("DB MANAGER: ", err)
	}
}<commit_msg>SM-6 #time: 10m Added test for check inserting of widget with same name.<commit_after>package dashboard

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

var (
	dbMigrator = NewMigrator("test.db")
	dbManager = NewDbManager("test.db")
)

func TestDbManager(t *testing.T) {
	errors, ok := dbMigrator.Up()
	if !ok {
		t.Fatal("Migrations Up: ", errors)
	}
	t.Run("Successfully insert widget info", func(t *testing.T) {
		var widget = &Widget{Url:"http://example.com", ID:"test_widget_1", Height:350, Width:400}
		count, err := dbManager.InsertWidget(widget)
		if err != nil {
			t.Fatal("ERROR:", err)
		}
		assert.Equal(t, int64(1), count)
	})
	t.Run("Fail to insert widget with same name", func(t *testing.T) {
		var widget = &Widget{Url:"http://example.com", ID:"test_widget_1", Height:350, Width:400}
		var widget2 = &Widget{Url:"http://some.site.com", ID:"test_widget_1", Height:450, Width:350}
		dbManager.InsertWidget(widget)
		count, err := dbManager.InsertWidget(widget2)
		assert.NotNil(t, err)
		assert.Equal(t, "UNIQUE constraint failed: widgets.id", err.Error())
		assert.Equal(t, int64(0), count)
	})
	errors, ok = dbMigrator.Down()
	if !ok {
		t.Fatal("Migrations Down: ", errors)
	}
	err := dbManager.Close()
	if err != nil {
		t.Fatal("DB MANAGER: ", err)
	}
}
{'fraction_non_alphanumeric': 0.17474302496328928, 'fraction_numerical': 0.020558002936857563, 'mean_word_length': 4.407407407407407, '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': '5418177', 'n_tokens_mistral': 850, 'n_tokens_neox': 780, 'n_words': 168}