@ -1,31 +1,14 @@
package fleprocess
package fleprocess
/ *
Copyright © 2020 Jean - Marc Meessen , ON4KJM < on4kjm @ gmail . com >
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
import (
import (
"fmt"
"fmt"
"testing"
"testing"
)
)
func Test_validateDataforAdif ( t * testing . T ) {
func Test_validateDataforAdif2 ( t * testing . T ) {
type args struct {
type args struct {
loadedLogFile [ ] LogLine
loadedLogFile [ ] LogLine
isWWFFcli bool
adifParams AdifParams
isSOTAcli bool
}
}
tests := [ ] struct {
tests := [ ] struct {
name string
name string
@ -33,77 +16,125 @@ func Test_validateDataforAdif(t *testing.T) {
want error
want error
} {
} {
{
{
"Happy Case (no sota or wwff)" ,
"Happy Case (no sota, pota or wwff)" ,
args { isWWFFcli : false , isSOTAcli : false , loadedLogFile : [ ] LogLine {
args {
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
adifParams : AdifParams { IsWWFF : false , IsSOTA : false , IsPOTA : false } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
loadedLogFile : [ ] LogLine {
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
} ,
} ,
} ,
nil ,
nil ,
} ,
} ,
{
{
"No data" ,
"No data" ,
args { isWWFFcli : false , isSOTAcli : false , loadedLogFile : [ ] LogLine { } } ,
args {
fmt . Errorf ( "No QSO found" ) ,
adifParams : AdifParams { IsWWFF : false , IsSOTA : false , IsPOTA : false } ,
loadedLogFile : [ ] LogLine { } ,
} ,
fmt . Errorf ( "no QSO found" ) ,
} ,
} ,
{
{
"Missing Date" ,
"Missing Date" ,
args { isWWFFcli : false , isSOTAcli : false , loadedLogFile : [ ] LogLine {
args {
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:01" , Call : "call" } ,
adifParams : AdifParams { IsWWFF : false , IsSOTA : false , IsPOTA : false } ,
{ Date : "" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:02" , Call : "call" } ,
loadedLogFile : [ ] LogLine {
{ Date : "" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:03" , Call : "call" } } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:01" , Call : "call" } ,
{ Date : "" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:02" , Call : "call" } ,
{ Date : "" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:03" , Call : "call" } ,
} ,
} ,
} ,
fmt . Errorf ( "missing date for log entry at 12:02 (#2), missing date for log entry at 12:03 (#3)" ) ,
fmt . Errorf ( "missing date for log entry at 12:02 (#2), missing date for log entry at 12:03 (#3)" ) ,
} ,
} ,
{
{
"Missing MyCall" ,
"Missing MyCall" ,
args { isWWFFcli : true , isSOTAcli : true , loadedLogFile : [ ] LogLine {
args {
{ Date : "date" , MyCall : "" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:01" , Call : "call" } ,
adifParams : AdifParams { IsWWFF : true , IsSOTA : true , IsPOTA : true } ,
{ Date : "date" , MyCall : "" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:02" , Call : "call" } ,
loadedLogFile : [ ] LogLine {
{ Date : "date" , MyCall : "" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:03" , Call : "call" } } ,
{ Date : "date" , MyCall : "" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:01" , Call : "call" } ,
{ Date : "date" , MyCall : "" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:02" , Call : "call" } ,
{ Date : "date" , MyCall : "" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:03" , Call : "call" } ,
} ,
} ,
} ,
fmt . Errorf ( "Missing MyCall" ) ,
fmt . Errorf ( "missing MyCall" ) ,
} ,
{
"Missing MyCall (POTA)" ,
args {
adifParams : AdifParams { IsWWFF : false , IsSOTA : false , IsPOTA : true } ,
loadedLogFile : [ ] LogLine {
{ Date : "date" , MyCall : "" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:01" , Call : "call" } ,
{ Date : "date" , MyCall : "" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:02" , Call : "call" } ,
{ Date : "date" , MyCall : "" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:03" , Call : "call" } ,
} ,
} ,
fmt . Errorf ( "missing MyCall" ) ,
} ,
} ,
{
{
"Missing MySota" ,
"Missing MySota" ,
args { isWWFFcli : false , isSOTAcli : true , loadedLogFile : [ ] LogLine {
args {
{ Date : "date" , MyCall : "myCall" , MySOTA : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
adifParams : AdifParams { IsWWFF : false , IsSOTA : true , IsPOTA : false } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
loadedLogFile : [ ] LogLine {
{ Date : "date" , MyCall : "myCall" , MySOTA : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
} ,
} ,
} ,
fmt . Errorf ( "Missing MY-SOTA reference" ) ,
fmt . Errorf ( "missing MY-SOTA reference" ) ,
} ,
{
"Missing MyPota" ,
args {
adifParams : AdifParams { IsWWFF : false , IsSOTA : false , IsPOTA : true } ,
loadedLogFile : [ ] LogLine {
{ Date : "date" , MyCall : "myCall" , MySOTA : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
} ,
} ,
fmt . Errorf ( "missing MY-POTA reference" ) ,
} ,
} ,
{
{
"Misc. missing data (Band, Time, Mode, Call)" ,
"Misc. missing data (Band, Time, Mode, Call)" ,
args { isWWFFcli : false , isSOTAcli : false , loadedLogFile : [ ] LogLine {
args {
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "" , Time : "" , Call : "call" } ,
adifParams : AdifParams { IsWWFF : false , IsSOTA : false , IsPOTA : false } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "" , Band : "band" , Time : "12:02" , Call : "call" } ,
loadedLogFile : [ ] LogLine {
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:03" , Call : "" } } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "" , Time : "" , Call : "call" } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "" , Band : "band" , Time : "12:02" , Call : "call" } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , Mode : "mode" , Band : "band" , Time : "12:03" , Call : "" } ,
} ,
} ,
} ,
fmt . Errorf ( "missing band for log entry #1, missing QSO time for log entry #1, missing mode for log entry at 12:02 (#2), missing call for log entry at 12:03 (#3)" ) ,
fmt . Errorf ( "missing band for log entry #1, missing QSO time for log entry #1, missing mode for log entry at 12:02 (#2), missing call for log entry at 12:03 (#3)" ) ,
} ,
} ,
{
{
"Missing MY-WWFF" ,
"Missing MY-WWFF" ,
args { isWWFFcli : true , isSOTAcli : false , loadedLogFile : [ ] LogLine {
args {
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , MyWWFF : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
adifParams : AdifParams { IsWWFF : true , IsSOTA : false , IsPOTA : false } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , MyWWFF : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
loadedLogFile : [ ] LogLine {
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , MyWWFF : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , MyWWFF : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , MyWWFF : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
{ Date : "date" , MyCall : "myCall" , MySOTA : "mySota" , MyWWFF : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
} ,
} ,
} ,
fmt . Errorf ( "Missing MY-WWFF reference" ) ,
fmt . Errorf ( " m issing MY-WWFF reference") ,
} ,
} ,
{
{
"Missing MY-WWFF" ,
"Missing Operator with isWWFF" ,
args { isWWFFcli : true , isSOTAcli : false , loadedLogFile : [ ] LogLine {
args {
{ Date : "date" , MyCall : "myCall" , MyWWFF : "myWwff" , Operator : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
adifParams : AdifParams { IsWWFF : true , IsSOTA : false , IsPOTA : false } ,
{ Date : "date" , MyCall : "myCall" , MyWWFF : "myWwff" , Operator : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
loadedLogFile : [ ] LogLine {
{ Date : "date" , MyCall : "myCall" , MyWWFF : "myWwff" , Operator : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } } ,
{ Date : "date" , MyCall : "myCall" , MyWWFF : "myWwff" , Operator : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
{ Date : "date" , MyCall : "myCall" , MyWWFF : "myWwff" , Operator : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
{ Date : "date" , MyCall : "myCall" , MyWWFF : "myWwff" , Operator : "" , Mode : "mode" , Band : "band" , Time : "time" , Call : "call" } ,
} ,
} ,
} ,
fmt . Errorf ( "Missing Operator call sign" ) ,
fmt . Errorf ( " m issing Operator call sign") ,
} ,
} ,
}
}
for _ , tt := range tests {
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
t . Run ( tt . name , func ( t * testing . T ) {
got := validateDataforAdif ( tt . args . loadedLogFile , tt . args . isWWFFcli, tt . args . isSOTAcli )
got := validateDataforAdif ( tt . args . loadedLogFile , tt . args . adifParams )
//Test the error message, if any
//Test the error message, if any
if got != nil && tt . want != nil {
if got != nil && tt . want != nil {
@ -119,14 +150,10 @@ func Test_validateDataforAdif(t *testing.T) {
}
}
}
}
func TestProcessAdifCommand ( t * testing . T ) {
func TestProcessAdifCommand ( t * testing . T ) {
type args struct {
type args struct {
inputFilename string
adifParams AdifParams
outputFilename string
isInterpolateTime bool
isWWFFcli bool
isSOTAcli bool
isOverwrite bool
}
}
tests := [ ] struct {
tests := [ ] struct {
name string
name string
@ -135,29 +162,57 @@ func TestProcessAdifCommand(t *testing.T) {
} {
} {
{
{
"Bad output filename (directory)" ,
"Bad output filename (directory)" ,
args { inputFilename : "../test/data/fle-4-no-qso.txt" , outputFilename : "../test/data" , isInterpolateTime : false , isOverwrite : false } ,
args {
adifParams : AdifParams {
InputFilename : "../test/data/fle-4-no-qso.txt" ,
OutputFilename : "../test/data" ,
IsInterpolateTime : false ,
IsOverwrite : false ,
} ,
} ,
true ,
true ,
} ,
} ,
{
{
"input file parsing errors (missing band)" ,
"input file parsing errors (missing band)" ,
args { inputFilename : "../test/data/fle-3-error.txt" , outputFilename : "" , isInterpolateTime : false , isOverwrite : false } ,
args {
adifParams : AdifParams {
InputFilename : "../test/data/fle-3-error.txt" ,
OutputFilename : "" ,
IsInterpolateTime : false ,
IsOverwrite : false ,
} ,
} ,
true ,
true ,
} ,
} ,
{
{
"input file parsing errors (wrong call)" ,
"input file parsing errors (wrong call)" ,
args { inputFilename : "../test/data/fle-5-wrong-call.txt" , outputFilename : "" , isInterpolateTime : false , isOverwrite : false } ,
args {
adifParams : AdifParams {
InputFilename : "../test/data/fle-5-wrong-call.txt" ,
OutputFilename : "" ,
IsInterpolateTime : false ,
IsOverwrite : false ,
} ,
} ,
true ,
true ,
} ,
} ,
{
{
"No QSO in loaded file" ,
"No QSO in loaded file" ,
args { inputFilename : "../test/data/fle-4-no-qso.txt" , outputFilename : "" , isInterpolateTime : false , isOverwrite : false } ,
args {
adifParams : AdifParams {
InputFilename : "../test/data/fle-4-no-qso.txt" ,
OutputFilename : "" ,
IsInterpolateTime : false ,
IsOverwrite : false ,
} ,
} ,
true ,
true ,
} ,
} ,
}
}
for _ , tt := range tests {
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
t . Run ( tt . name , func ( t * testing . T ) {
if err := ProcessAdifCommand ( tt . args . inputFilename , tt . args . outputFilename , tt . args . isInterpolateTime , tt . args . isWWFFcli , tt . args . isSOTAcli , tt . args . isOverwrite ) ; ( err != nil ) != tt . wantErr {
if err := ProcessAdifCommand ( tt . args . adifParams ) ; ( err != nil ) != tt . wantErr {
t . Errorf ( "ProcessCsvCommand() error = %v, wantErr %v" , err , tt . wantErr )
t . Errorf ( "Process Adif Command() error = %v, wantErr %v", err , tt . wantErr )
}
}
} )
} )
}
}