<commit_before>/*
 *  Charon: A game authentication server
 *  Copyright (C) 2014-2016  <NAME> <<EMAIL>>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package charon

import "testing"

func TestNewDatabase(t *testing.T) {
	_, err := NewDatabase(NewConfig(nil))
	if err != nil {
		t.Errorf("%s", err.Error())
	}
}

func TestAddUser(t *testing.T) {
	database, err := NewDatabase(NewConfig(nil))
	if err != nil {
		t.Errorf("%s", err.Error())
	}

	err = database.AddUser("TestUser", "<EMAIL>", "VsGnJghDUW6C")
	if err != nil {
		t.Errorf("%s", err.Error())
	}
}

func TestAddUserErrors(t *testing.T) {
	database, err := NewDatabase(NewConfig(nil))
	if err != nil {
		t.Errorf("%s", err.Error())
	}

	err = database.Import("fixture/user.sql")
	if err != nil {
		t.Errorf("%s", err.Error())
	}

	err = database.AddUser("TestUser", "<EMAIL>", "VsGnJghDUW6C")
	if err == nil {
		t.Errorf("Username is not unique")
	}
}

func TestFindUser(t *testing.T) {
	database, err := NewDatabase(NewConfig(nil))
	if err != nil {
		t.Errorf("%s", err.Error())
	}

	err = database.Import("fixture/user.sql")
	if err != nil {
		t.Errorf("%s", err.Error())
	}

	_, err = database.FindUser("TestUser")
	if err != nil {
		t.Errorf("%s", err.Error())
	}
}

func TestLoginUser(t *testing.T) {
	database, err := NewDatabase(NewConfig(nil))
	if err != nil {
		t.Errorf("%s", err.Error())
	}
<commit_msg>Better unit test failure message.<commit_after>/*
 *  Charon: A game authentication server
 *  Copyright (C) 2014-2016  <NAME> <<EMAIL>>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package charon

import "testing"

func TestNewDatabase(t *testing.T) {
	_, err := NewDatabase(NewConfig(nil))
	if err != nil {
		t.Errorf("%s", err.Error())
	}
}

func TestAddUser(t *testing.T) {
	database, err := NewDatabase(NewConfig(nil))
	if err != nil {
		t.Errorf("%s", err.Error())
	}

	err = database.AddUser("TestUser", "<EMAIL>", "VsGnJghDUW6C")
	if err != nil {
		t.Errorf("%s", err.Error())
	}
}

func TestAddUserErrors(t *testing.T) {
	database, err := NewDatabase(NewConfig(nil))
	if err != nil {
		t.Errorf("%s", err.Error())
	}

	err = database.Import("fixture/user.sql")
	if err != nil {
		t.Errorf("%s", err.Error())
	}

	err = database.AddUser("TestUser", "<EMAIL>", "VsGnJghDUW6C")
	if err == nil {
		t.Errorf("charon: user added despite uniqueness constraint")
	}
}

func TestFindUser(t *testing.T) {
	database, err := NewDatabase(NewConfig(nil))
	if err != nil {
		t.Errorf("%s", err.Error())
	}

	err = database.Import("fixture/user.sql")
	if err != nil {
		t.Errorf("%s", err.Error())
	}

	_, err = database.FindUser("TestUser")
	if err != nil {
		t.Errorf("%s", err.Error())
	}
}

func TestLoginUser(t *testing.T) {
	database, err := NewDatabase(NewConfig(nil))
	if err != nil {
		t.Errorf("%s", err.Error())
	}

{'fraction_non_alphanumeric': 0.1512770137524558, 'fraction_numerical': 0.0054027504911591355, 'mean_word_length': 3.803066037735849, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4178261', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1374, 'n_words': 430}