<commit_before>package queue

import (
	"code.google.com/p/go-uuid/uuid"

	"os"
	"path"
	"testing"
)

func TestStorage(t *testing.T) {
	var (
		directory   = path.Join(os.TempDir(), uuid.New())
		data        = []byte("test")
		numMessages = 5
		messageIDs  = make([]string, numMessages)
		m           = &Message{}
	)
	if err := os.MkdirAll(directory, 0755); err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(directory)
	if s, messages, err := NewStorage(directory); err == nil {
		if len(messages) != 0 {
			t.Fatalf("%d != 0", len(messages))
		}
		if w, id, err := s.NewBody(); err == nil {
			if _, err := w.Write(data); err != nil {
				t.Fatal(err)
			}
			if err := w.Close(); err != nil {
				t.Fatal(err)
			}
			m.Body = id
		} else {
			t.Fatal(err)
		}
		for i := 0; i < numMessages; i++ {
			if id, err := s.NewMessage(m); err == nil {
				messageIDs[i] = id
			} else {
				t.Fatal(err)
			}
		}
	} else {
		t.Fatal(err)
	}
	if s, messages, err := NewStorage(directory); err == nil {
		if len(messages) != numMessages {
			t.Fatalf("%d != %d", len(messages), numMessages)
		}
		for _, id := range messageIDs {
			if err := s.DeleteMessage(id); err != nil {
				t.Fatal(err)
			}
		}
		if _, err := s.GetBody(m.Body); err != InvalidID {
			t.Fatalf("%v != %v", err, InvalidID)
		}
	} else {
		t.Fatal(err)
	}
}
<commit_msg>Switched Storage tests to using TempDir.<commit_after>package queue

import (
	"github.com/nathan-osman/go-cannon/util"

	"testing"
)

func TestStorage(t *testing.T) {
	var (
		data        = []byte("test")
		numMessages = 5
		messageIDs  = make([]string, numMessages)
		m           = &Message{}
	)
	if d, err := util.NewTempDir(); err == nil {
		defer d.Delete()
		if s, messages, err := NewStorage(d.Path); err == nil {
			if len(messages) != 0 {
				t.Fatalf("%d != 0", len(messages))
			}
			if w, id, err := s.NewBody(); err == nil {
				if _, err := w.Write(data); err != nil {
					t.Fatal(err)
				}
				if err := w.Close(); err != nil {
					t.Fatal(err)
				}
				m.Body = id
			} else {
				t.Fatal(err)
			}
			for i := 0; i < numMessages; i++ {
				if id, err := s.NewMessage(m); err == nil {
					messageIDs[i] = id
				} else {
					t.Fatal(err)
				}
			}
		} else {
			t.Fatal(err)
		}
		if s, messages, err := NewStorage(d.Path); err == nil {
			if len(messages) != numMessages {
				t.Fatalf("%d != %d", len(messages), numMessages)
			}
			for _, id := range messageIDs {
				if err := s.DeleteMessage(id); err != nil {
					t.Fatal(err)
				}
			}
			if _, err := s.GetBody(m.Body); err != InvalidID {
				t.Fatalf("%v != %v", err, InvalidID)
			}
		} else {
			t.Fatal(err)
		}
	} else {
		t.Fatal(err)
	}
}

{'fraction_non_alphanumeric': 0.18850920015020653, 'fraction_numerical': 0.004506196019526849, 'mean_word_length': 2.4197689345314504, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2719643', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1045, 'n_words': 243}