<commit_before>package database_test

import (
	"os"
	"testing"

	"github.com/josephspurrier/gocleanarchitecture/database"
	"github.com/josephspurrier/gocleanarchitecture/domain/user"
)

// TestClient ensures the client works properly.
func TestClient(t *testing.T) {
	c := database.NewClient("db.json")

	// Check the output.
	AssertEqual(t, c.Path, "db.json")
	AssertEqual(t, c.Write(), nil)
	AssertEqual(t, c.Read(), nil)
	AssertEqual(t, c.Write(), nil)

	// Test adding a record and reading it.
	u := new(user.Item)
	u.Email = "<EMAIL>"
	u.Password = "<PASSWORD>"
	c.AddRecord(*u)
	AssertEqual(t, len(c.Records()), 1)

	// Cleanup
	os.Remove("db.json")
}<commit_msg>Add additional failure checks on client.<commit_after>package database_test

import (
	"io/ioutil"
	"os"
	"testing"

	"github.com/josephspurrier/gocleanarchitecture/database"
	"github.com/josephspurrier/gocleanarchitecture/domain/user"
)

// TestClient ensures the client works properly.
func TestClient(t *testing.T) {
	c := database.NewClient("db.json")

	// Check the output.
	AssertEqual(t, c.Path, "db.json")
	AssertEqual(t, c.Write(), nil)
	AssertEqual(t, c.Read(), nil)
	AssertEqual(t, c.Write(), nil)

	// Test adding a record and reading it.
	u := new(user.Item)
	u.Email = "<EMAIL>"
	u.Password = "<PASSWORD>"
	c.AddRecord(*u)
	AssertEqual(t, len(c.Records()), 1)

	// Cleanup
	os.Remove("db.json")
}

// TestClient ensures the client fails properly.
func TestClientFail(t *testing.T) {
	c := database.NewClient("")

	// Check the output.
	AssertEqual(t, c.Path, "")
	AssertNotNil(t, c.Write())
	AssertNotNil(t, c.Read())
}

// TestClientFailOpen ensures the client fails properly.
func TestClientFailOpen(t *testing.T) {
	c := database.NewClient("dbbad.json")

	// Write a bad file.
	ioutil.WriteFile("dbbad.json", []byte("{"), 0644)

	// Check the output.
	AssertNotNil(t, c.Read())

	// Cleanup
	os.Remove("dbbad.json")
}
{'fraction_non_alphanumeric': 0.16701680672268907, 'fraction_numerical': 0.0031512605042016808, 'mean_word_length': 4.291666666666667, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7284134', 'n_tokens_mistral': 734, 'n_tokens_neox': 715, 'n_words': 155}