<commit_before>package database

import (
	"testing"

	cfg "github.com/grvcoelho/webhulk/pkg/config"
	"github.com/stretchr/testify/assert"
)

func TestDatabase(t *testing.T) {
	t.Run("NewDatabase", func(t *testing.T) {
		db, err := NewDatabase(&cfg.Database{
			Address: "postgres://postgres:postgres@database/webhulk?sslmode=disable",
		})

		assert.NoError(t, err, "Should create a database instance")

		err = db.Ping()

		assert.NoError(t, err, "Should connect to the database")
	})

	t.Run("WebhookStore", func(t *testing.T) {
		db, _ := NewDatabase(&cfg.Database{
			Address: "postgres://postgres:postgres@database/webhulk?sslmode=disable",
		})

		store, err := NewWebhookStore(db)
		assert.NoError(t, err)

		w1, err := NewWebhook("events", "https://receiver.com", true)
		assert.NoError(t, err)

		_, err = store.Store(w1)
		assert.NoError(t, err, "Should store a webhook")

		w2, ok := store.Retrieve(w1.ID)
		assert.True(t, ok)
		assert.Equal(t, w1.ID, w2.ID)
	})<commit_msg>message: add tests for type and store<commit_after>package database

import (
	"testing"

	cfg "github.com/grvcoelho/webhulk/pkg/config"
	"github.com/stretchr/testify/assert"
)

func TestDatabase(t *testing.T) {
	t.Run("NewDatabase", func(t *testing.T) {
		db, err := NewDatabase(&cfg.Database{
			Address: "postgres://postgres:postgres@database/webhulk?sslmode=disable",
		})

		assert.NoError(t, err, "Should create a database instance")

		err = db.Ping()

		assert.NoError(t, err, "Should connect to the database")
	})

	t.Run("WebhookStore", func(t *testing.T) {
		db, _ := NewDatabase(&cfg.Database{
			Address: "postgres://postgres:postgres@database/webhulk?sslmode=disable",
		})

		webhookStore, err := NewWebhookStore(db)
		assert.NoError(t, err)

		w1, err := NewWebhook("events", "https://receiver.com", true)
		assert.NoError(t, err)

		_, err = webhookStore.Store(w1)
		assert.NoError(t, err, "Should store a webhook")

		w2, ok := webhookStore.Retrieve(w1.ID)
		assert.True(t, ok)
		assert.Equal(t, w1.ID, w2.ID)
	})

	t.Run("MessageStore", func(t *testing.T) {
		db, _ := NewDatabase(&cfg.Database{
			Address: "postgres://postgres:postgres@database/webhulk?sslmode=disable",
		})

		webhookStore, _ := NewWebhookStore(db)
		messageStore, err := NewMessageStore(db)
		assert.NoError(t, err)

		w1, _ := NewWebhook("events", "https://receiver.com", true)
		w1, _ = webhookStore.Store(w1)

		m1, err := NewMessage(w1.ID, `{"event": "status_changed"}`)
		assert.NoError(t, err)

		_, err = messageStore.Store(m1)
		assert.NoError(t, err, "Should store a message")

		m2, ok := messageStore.Retrieve(m1.ID)
		assert.True(t, ok)
		assert.Equal(t, m1.ID, m2.ID)
	})
{'fraction_non_alphanumeric': 0.1698609545283728, 'fraction_numerical': 0.008267568583239383, 'mean_word_length': 4.477366255144033, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, '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': '1744209', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1015, 'n_words': 187}