package configmdl

import (
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"
)

type tomlConfig struct {
	Title           string
	Name            string
	AdditionalField string
	Version         string
}

func TestInitConfig(t *testing.T) {
	var config tomlConfig
	InitConfig("../testingdata/testData/config/config.toml", &config)
	assert.True(t, config.Name == "github.com/OneOfOne/xxhash", "this should not throw error")
}

func TestSaveConfig(t *testing.T) {
	var config tomlConfig
	InitConfig("../testingdata/testData/config/config.toml", &config)
	err := SaveConfig("../testingdata/testData/config/config-save.toml", config)
	assert.NoError(t, err, "This should not throw error")
}

func TestSaveConfigSecure(t *testing.T) {
	var config tomlConfig
	InitConfig("../testingdata/testData/config/config.toml", &config)
	key := "1234567891234567"
	err := SaveConfigSecure("../testingdata/testData/config/config-save-secure.toml", config, []byte(key))
	assert.NoError(t, err, "This should not throw error")
}

func TestInitConfigSecure(t *testing.T) {
	var config tomlConfig
	InitConfig("../testingdata/testData/config/config.toml", &config)
	key := "1234567891234567"
	SaveConfigSecure("../testingdata/testData/config/config-save-secure.toml", config, []byte(key))

	_, err := InitConfigSecure("../testingdata/testData/config/config-save-secure.toml", &config, []byte(key))
	fmt.Println("config: ", config)
	assert.NoError(t, err, "This should not throw error")
}