mirror of https://github.com/on4kjm/FLEcli.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.4 KiB
93 lines
2.4 KiB
4 years ago
|
package fleprocess
|
||
4 years ago
|
|
||
|
import (
|
||
|
"os"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
const testDir string = "test_dir"
|
||
|
const testFile string = "test.adi"
|
||
|
|
||
|
func setupTestCase(t *testing.T) func(t *testing.T) {
|
||
|
t.Log("setup test case")
|
||
|
//create test directory
|
||
|
os.Mkdir(testDir, os.FileMode(0522))
|
||
|
//create test file
|
||
|
f, _ := os.OpenFile(testFile, os.O_WRONLY|os.O_CREATE, 0666)
|
||
|
defer f.Close()
|
||
|
|
||
|
return func(t *testing.T) {
|
||
|
t.Log("teardown test case")
|
||
|
//delete test directory
|
||
|
os.Remove(testDir)
|
||
|
//detete test file
|
||
|
os.Remove(testFile)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Test_buildOutputFilename(t *testing.T) {
|
||
|
type args struct {
|
||
|
output string
|
||
|
input string
|
||
|
overwrite bool
|
||
4 years ago
|
extension string
|
||
4 years ago
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
wantOutputFilename string
|
||
|
wantWasOK bool
|
||
|
}{
|
||
|
{
|
||
|
"input file not provided",
|
||
4 years ago
|
args{input: "", output: "xxx", overwrite: false, extension: ".adi"},
|
||
4 years ago
|
"", false,
|
||
|
},
|
||
|
{
|
||
|
"Output file does not exist",
|
||
4 years ago
|
args{input: "a file", output: "output.adi", overwrite: false, extension: ".adi"},
|
||
4 years ago
|
"output.adi", true,
|
||
|
},
|
||
|
{
|
||
|
"Output name is a directory",
|
||
4 years ago
|
args{input: "a file", output: testDir, overwrite: false, extension: ".adi"},
|
||
4 years ago
|
"", false,
|
||
|
},
|
||
|
{
|
||
4 years ago
|
"Output exist but no overwrite",
|
||
4 years ago
|
args{input: "a file", output: testFile, overwrite: false, extension: ".adi"},
|
||
4 years ago
|
"", false,
|
||
|
},
|
||
4 years ago
|
{
|
||
|
"no output, input provided with extention",
|
||
4 years ago
|
args{input: "/test/data/file.txt", output: "", overwrite: false, extension: ".adi"},
|
||
4 years ago
|
"/test/data/file.adi", true,
|
||
|
},
|
||
|
{
|
||
|
"no output, input provided without extention",
|
||
4 years ago
|
args{input: "/test/data/file", output: "", overwrite: false, extension: ".adi"},
|
||
4 years ago
|
"/test/data/file.adi", true,
|
||
|
},
|
||
|
{
|
||
|
"no output, input provided, enfing with a point",
|
||
4 years ago
|
args{input: "/test/data/file.", output: "", overwrite: false, extension: ".adi"},
|
||
4 years ago
|
"/test/data/file.adi", true,
|
||
|
},
|
||
4 years ago
|
}
|
||
|
|
||
|
teardownTestCase := setupTestCase(t)
|
||
|
defer teardownTestCase(t)
|
||
|
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
4 years ago
|
gotOutputFilename, gotWasOK := buildOutputFilename(tt.args.output, tt.args.input, tt.args.overwrite, tt.args.extension)
|
||
4 years ago
|
if gotOutputFilename != tt.wantOutputFilename {
|
||
|
t.Errorf("buildOutputFilename() gotOutputFilename = %v, want %v", gotOutputFilename, tt.wantOutputFilename)
|
||
|
}
|
||
|
if gotWasOK != tt.wantWasOK {
|
||
|
t.Errorf("buildOutputFilename() gotWasOK = %v, want %v", gotWasOK, tt.wantWasOK)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|