2022-06-28 23:40:35 +02:00
|
|
|
// Copyright 2022 wanderer <a_mirre at utb dot cz>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-07-10 20:54:48 +02:00
|
|
|
package util
|
2022-06-28 23:40:35 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// nolint: ifshort
|
|
|
|
func TestCreateFolder(t *testing.T) {
|
|
|
|
// let's assume this will never exist in a clean project...
|
|
|
|
testPath := "whatever-path"
|
2022-07-10 20:54:48 +02:00
|
|
|
got := CreateFolder(testPath)
|
2022-06-28 23:40:35 +02:00
|
|
|
|
|
|
|
var want error
|
|
|
|
|
|
|
|
if want != got {
|
2022-06-29 17:02:13 +02:00
|
|
|
t.Errorf("issue creating folder, testPath: %q, full cmd: %q", testPath, got.Error())
|
2022-06-28 23:40:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
os.RemoveAll(testPath)
|
|
|
|
}
|
2022-06-29 16:54:55 +02:00
|
|
|
|
|
|
|
// nolint: ifshort
|
|
|
|
func TestCreatePath(t *testing.T) {
|
|
|
|
// let's assume this, too, will never exist in a clean project...
|
2022-07-08 22:11:30 +02:00
|
|
|
testPathRoot := "whatever-path"
|
|
|
|
testPath := testPathRoot + "/whatever-subpath/subsubpath"
|
2022-07-10 20:54:48 +02:00
|
|
|
got := CreatePath(testPath)
|
2022-06-29 16:54:55 +02:00
|
|
|
|
|
|
|
var want error
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("issue creating folders in path, testPath: %q, full cmd: %q", testPath, got.Error())
|
|
|
|
}
|
|
|
|
|
2022-07-08 22:11:30 +02:00
|
|
|
// clean up from the root.
|
|
|
|
if err := os.RemoveAll(testPathRoot); err != nil {
|
|
|
|
t.Error("error cleaning up: ", err)
|
|
|
|
}
|
2022-06-29 16:54:55 +02:00
|
|
|
}
|
2022-07-17 21:50:19 +02:00
|
|
|
|
|
|
|
func TestSanitiseFname(t *testing.T) {
|
|
|
|
want := "Stochastic--Hill--Climbing"
|
|
|
|
got := SanitiseFName("Stochastic Hill Climbing")
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("failed to sanitise file name, want: %s, got: %s", want, got)
|
|
|
|
}
|
|
|
|
}
|