<commit_before>// BaruwaAPI Golang bindings for Baruwa REST API
// Copyright (C) 2019 <NAME> <<EMAIL>>

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.

package api
<commit_msg>TST: Add Address Alias tests<commit_after>// BaruwaAPI Golang bindings for Baruwa REST API
// Copyright (C) 2019 <NAME> <<EMAIL>>

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.

package api

import (
	"fmt"
	"net/http"
	"testing"
)

func TestGetAliasAddressError(t *testing.T) {
	data := ``
	server, client, err := getTestServerAndClient(http.StatusOK, data)
	if err != nil {
		t.Fatalf("An error should not be returned")
	}
	defer server.Close()
	alias, err := client.GetAliasAddress(0)
	if err == nil {
		t.Fatalf("An error should be returned")
	}
	if alias != nil {
		t.Errorf("Expected %v got %v", nil, alias)
	}
}

func TestGetAliasAddressOK(t *testing.T) {
	aliasID := 3
	data := fmt.Sprintf(`
	{
		"enabled": false,
		"id": %d,
		"address": "<EMAIL>"
	}
	`, aliasID)
	server, client, err := getTestServerAndClient(http.StatusOK, data)
	if err != nil {
		t.Fatalf("An error should not be returned")
	}
	defer server.Close()
	alias, err := client.GetAliasAddress(aliasID)
	if err != nil {
		t.Fatalf("An error should not be returned: %s", err)
	}
	if alias.ID != aliasID {
		t.Errorf("Expected %d got %d", aliasID, alias.ID)
	}
}

func TestCreateAliasAddressError(t *testing.T) {
	data := ``
	server, client, err := getTestServerAndClient(http.StatusOK, data)
	if err != nil {
		t.Fatalf("An error should not be returned")
	}
	defer server.Close()
	err = client.CreateAliasAddress(0, nil)
	if err == nil {
		t.Fatalf("An error should be returned")
	}
	if err.Error() != userIDError {
		t.Errorf("Expected '%s' got '%s'", userIDError, err)
	}
	err = client.CreateAliasAddress(1, nil)
	if err == nil {
		t.Fatalf("An error should be returned")
	}
	if err.Error() != aliasParamError {
		t.Errorf("Expected '%s' got '%s'", aliasParamError, err)
	}
}

func TestCreateAliasAddressOK(t *testing.T) {
	data := ``
	server, client, err := getTestServerAndClient(http.StatusOK, data)
	if err != nil {
		t.Fatalf("An error should not be returned")
	}
	defer server.Close()
	a := &AliasAddress{
		Address: "<EMAIL>",
		Enabled: false,
	}
	err = client.CreateAliasAddress(1, a)
	if err != nil {
		t.Fatalf("An error should not be returned: %s", err)
	}
}

func TestUpdateAliasAddressError(t *testing.T) {
	data := ``
	server, client, err := getTestServerAndClient(http.StatusOK, data)
	if err != nil {
		t.Fatalf("An error should not be returned")
	}
	defer server.Close()
	err = client.UpdateAliasAddress(nil)
	if err == nil {
		t.Fatalf("An error should be returned")
	}
	if err.Error() != aliasParamError {
		t.Errorf("Expected '%s' got '%s'", aliasParamError, err)
	}
	a := &AliasAddress{
		Address: "<EMAIL>",
		Enabled: false,
	}
	err = client.UpdateAliasAddress(a)
	if err == nil {
		t.Fatalf("An error should be returned")
	}
	if err.Error() != aliasSIDError {
		t.Errorf("Expected '%s' got '%s'", aliasSIDError, err)
	}
}

func TestUpdateAliasAddressOK(t *testing.T) {
	data := ``
	server, client, err := getTestServerAndClient(http.StatusOK, data)
	if err != nil {
		t.Fatalf("An error should not be returned")
	}
	defer server.Close()
	a := &AliasAddress{
		ID:      2,
		Address: "<EMAIL>",
		Enabled: true,
	}
	err = client.UpdateAliasAddress(a)
	if err != nil {
		t.Fatalf("An error should not be returned: %s", err)
	}
}

func TestDeleteAliasAddressError(t *testing.T) {
	data := ``
	server, client, err := getTestServerAndClient(http.StatusOK, data)
	if err != nil {
		t.Fatalf("An error should not be returned")
	}
	defer server.Close()
	err = client.DeleteAliasAddress(nil)
	if err == nil {
		t.Fatalf("An error should be returned")
	}
	if err.Error() != aliasParamError {
		t.Errorf("Expected '%s' got '%s'", aliasParamError, err)
	}
	a := &AliasAddress{
		Address: "<EMAIL>",
		Enabled: false,
	}
	err = client.DeleteAliasAddress(a)
	if err == nil {
		t.Fatalf("An error should be returned")
	}
	if err.Error() != aliasSIDError {
		t.Errorf("Expected '%s' got '%s'", aliasSIDError, err)
	}
}

func TestDeleteAliasAddressOK(t *testing.T) {
	data := ``
	server, client, err := getTestServerAndClient(http.StatusNoContent, data)
	if err != nil {
		t.Fatalf("An error should not be returned")
	}
	defer server.Close()
	a := &AliasAddress{
		ID:      2,
		Address: "<EMAIL>",
		Enabled: true,
	}
	err = client.DeleteAliasAddress(a)
	if err != nil {
		t.Fatalf("An error should not be returned: %s", err)
	}
}

{'fraction_non_alphanumeric': 0.15056226572261558, 'fraction_numerical': 0.004789670970428988, 'mean_word_length': 3.841733870967742, 'pattern_counts': {'":': 3, '<': 15, '<?xml version=': 0, '>': 15, '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': '4788958', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1711, 'n_words': 509}