<commit_before>package goriak

import (
	"log"
	"math/rand"
	"os"
	"testing"
	"time"
)

// Cleanup Bucket
func TestMain(m *testing.M) {
	deleteAllIn("testsuite", "tests")
	deleteAllIn("customtype", "maps")
	deleteAllIn("testsuitemap", "maps")
	deleteAllIn("json", "default")
	deleteAllIn("testdelete", "default")

	rand.Seed(time.Now().UnixNano())

	os.Exit(m.Run())
}

func deleteAllIn(bucket, bucketType string) {

	cb := func(res []string) error {

		for _, key := range res {
			Bucket(bucket, bucketType).Key(key).Delete().Run(con())
			log.Println("Delete: " + key)
		}

		return nil
	}

	Bucket(bucket, bucketType).AllKeys(cb).Run(con())
}

func TestAllKeys(t *testing.T) {

	c := con()

	Bucket("testdelete", "default").SetRaw([]byte{1, 2, 3, 4}).Run(c)
	Bucket("testdelete", "default").SetRaw([]byte{1, 2, 3, 4}).Run(c)
	Bucket("testdelete", "default").SetRaw([]byte{1, 2, 3, 4}).Run(c)
	Bucket("testdelete", "default").SetRaw([]byte{1, 2, 3, 4}).Run(c)

	foundCount := 0

	_, err := Bucket("testdelete", "default").AllKeys(func(res []string) error {
		foundCount = foundCount + len(res)
		return nil
	}).Run(con())

	if err != nil {
		t.Error(err)
	}

	if foundCount == 0 {
		t.Error("No keys found")
	}
}

func TestDelete(t *testing.T) {
	res, err := Bucket("testdelete", "default").SetRaw([]byte{1, 2, 3, 4}).Run(con())

	if err != nil {
		t.Error(err)
	}

	_, err = Bucket("testdelete", "default").Key(res.Key).Delete().Run(con())

	if err != nil {
		t.Error(err)
	}

	var out []byte
	res, err = Bucket("testdelete", "default").Key(res.Key).GetRaw(&out).Run(con())

	if !res.NotFound {
		t.Error("Found after delete")
	}

	if err == nil {
		t.Error("No error")
		return
	}

	if err.Error() != "Not found" {
		t.Error("Unexpected error:", err)
	}
}<commit_msg>#17 - Added more tests to error cases<commit_after>package goriak

import (
	"log"
	"math/rand"
	"os"
	"testing"
	"time"
)

// Cleanup Bucket
func TestMain(m *testing.M) {
	deleteAllIn("testsuite", "tests")
	deleteAllIn("customtype", "maps")
	deleteAllIn("testsuitemap", "maps")
	deleteAllIn("json", "default")
	deleteAllIn("testdelete", "default")

	rand.Seed(time.Now().UnixNano())

	os.Exit(m.Run())
}

func deleteAllIn(bucket, bucketType string) {

	cb := func(res []string) error {

		for _, key := range res {
			Bucket(bucket, bucketType).Key(key).Delete().Run(con())
			log.Println("Delete: " + key)
		}

		return nil
	}

	Bucket(bucket, bucketType).AllKeys(cb).Run(con())
}

func TestAllKeys(t *testing.T) {

	c := con()

	Bucket("testdelete", "default").SetRaw([]byte{1, 2, 3, 4}).Run(c)
	Bucket("testdelete", "default").SetRaw([]byte{1, 2, 3, 4}).Run(c)
	Bucket("testdelete", "default").SetRaw([]byte{1, 2, 3, 4}).Run(c)
	Bucket("testdelete", "default").SetRaw([]byte{1, 2, 3, 4}).Run(c)

	foundCount := 0

	_, err := Bucket("testdelete", "default").AllKeys(func(res []string) error {
		foundCount = foundCount + len(res)
		return nil
	}).Run(con())

	if err != nil {
		t.Error(err)
	}

	if foundCount == 0 {
		t.Error("No keys found")
	}
}

func TestAllKeysNoBucket(t *testing.T) {
	_, err := Command{}.AllKeys(func(res []string) error {
		return nil
	}).Run(con())

	if err.Error() != "ClientError|Bucket is required" {
		t.Error("Unexpected error")
	}
}

func TestDelete(t *testing.T) {
	res, err := Bucket("testdelete", "default").SetRaw([]byte{1, 2, 3, 4}).Run(con())

	if err != nil {
		t.Error(err)
	}

	_, err = Bucket("testdelete", "default").Key(res.Key).Delete().Run(con())

	if err != nil {
		t.Error(err)
	}

	var out []byte
	res, err = Bucket("testdelete", "default").Key(res.Key).GetRaw(&out).Run(con())

	if !res.NotFound {
		t.Error("Found after delete")
	}

	if err == nil {
		t.Error("No error")
		return
	}

	if err.Error() != "Not found" {
		t.Error("Unexpected error:", err)
	}
}

func TestDeleteNoKey(t *testing.T) {
	_, err := Bucket("testdelete", "default").Delete().Run(con())

	if err.Error() != "ClientError|Key is required" {
		t.Error("Unexpected error")
	}
}
{'fraction_non_alphanumeric': 0.21374622356495468, 'fraction_numerical': 0.011581067472306143, 'mean_word_length': 4.332885906040269, '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': '1012963', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1526, 'n_words': 314}