/**************************************************************************************
 *
 *     Project:    kvmstoreserver
 *     File name:  keyNameToIdConverter_test.go
 *     Version:    1.0.0
 *     Date:       2018-01-13
 *
 *     Autor:      Bogdanovic Theodor
 *     Contact:    t.bogdanovic@hotmail.com
 *
 *     License:    GPLv3
 *
 **************************************************************************************/
/**************************************************************************************
 * Copyright 2018 Bogdanovic Theodor
 *
 * This file is part of kvmstoreserver.
 *
 * kvmstoreserver is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * kvmstoreserver 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with kvmstoreserver.  If not, see <http://www.gnu.org/licenses/>.
 **************************************************************************************/
/**************************************************************************************
 *  Further explanations:  This source code is under the license specified by the
 *                         Autor above. Core components or other packages are still
 *                         in source code form, under the license specified by the
 *                         respective author.
 **************************************************************************************/

package keyNameHandling

import (
	"reflect"
	"testing"
)

func TestNewKeyContext(t *testing.T) {

	// Crate comparative data
	var iHandelWithIdsTestsystem1000 IHandelWithIds = &keyContext{
		dataNodeID:      23451191704648,
		keyNameAsString: "Testsystem_Name_1000",
	}
	var iHandelWithIdsTheodor IHandelWithIds = &keyContext{
		dataNodeID:      8018417516249221,
		keyNameAsString: "Theodor",
	}
	var iHandelWithIdstheodor IHandelWithIds = &keyContext{
		dataNodeID:      25422015718236214,
		keyNameAsString: "theodor",
	}

	// Create test data
	tests := []struct {
		name    string
		key     string
		want    IHandelWithIds
		wantErr bool
	}{
		{name: "Test 1: with key name -> Testsystem_Name_1000", key: "Testsystem_Name_1000", want: iHandelWithIdsTestsystem1000, wantErr: false},
		{name: "Test 2: with key name -> Theodor", key: "Theodor", want: iHandelWithIdsTheodor, wantErr: false},
		{name: "Test 3: with key name -> theodor", key: "theodor", want: iHandelWithIdstheodor, wantErr: false},
	}

	// Execute the test series
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := NewKeyContext(tt.key)

			if (err != nil) != tt.wantErr {
				t.Errorf("NewKeyContext() error = %v, wantErr %v", err, tt.wantErr)
				return
			}

			// Add the generated MD5 checksum to the comparative data
			// (only the checksum)
			(tt.want).(*keyContext).keyMd5Hash = (got).(*keyContext).keyMd5Hash

			if !reflect.DeepEqual(got, tt.want) {
				t.Errorf("NewKeyContext() = %v, want %v", got, tt.want)
			}
		})
	}
}
