mirror of https://github.com/on4kjm/FLEcli.git
parent
1077b7254f
commit
6172f13193
@ -1,111 +0,0 @@
|
||||
package cmd
|
||||
|
||||
/*
|
||||
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 (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// SprintLogRecord outputs the content of a logline
|
||||
func SprintLogRecord(logLine LogLine) (output string) {
|
||||
output = ""
|
||||
output = output + "Date " + logLine.Date + "\n"
|
||||
output = output + "MyCall " + logLine.MyCall + "\n"
|
||||
output = output + "Operator " + logLine.Operator + "\n"
|
||||
output = output + "MyWWFF " + logLine.MyWWFF + "\n"
|
||||
output = output + "MySOTA " + logLine.MySOTA + "\n"
|
||||
output = output + "QslMsg " + logLine.QslMsg + "\n"
|
||||
output = output + "Nickname " + logLine.Nickname + "\n"
|
||||
output = output + "Mode " + logLine.Mode + "\n"
|
||||
output = output + "ModeType " + logLine.ModeType + "\n"
|
||||
output = output + "Band " + logLine.Band + "\n"
|
||||
output = output + " Lower " + fmt.Sprintf("%f", logLine.BandLowerLimit) + "\n"
|
||||
output = output + " Upper " + fmt.Sprintf("%f", logLine.BandUpperLimit) + "\n"
|
||||
output = output + "Frequency " + logLine.Frequency + "\n"
|
||||
output = output + "Time " + logLine.Time + "\n"
|
||||
output = output + "Call " + logLine.Call + "\n"
|
||||
output = output + "Comment " + logLine.Comment + "\n"
|
||||
output = output + "QSLmsg " + logLine.QSLmsg + "\n"
|
||||
output = output + "OMname " + logLine.OMname + "\n"
|
||||
output = output + "GridLoc " + logLine.GridLoc + "\n"
|
||||
output = output + "RSTsent " + logLine.RSTsent + "\n"
|
||||
output = output + "RSTrcvd " + logLine.RSTrcvd + "\n"
|
||||
output = output + "SOTA " + logLine.SOTA + "\n"
|
||||
output = output + "WWFF " + logLine.WWFF + "\n"
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
// SprintHeaderValues displays the header values
|
||||
func SprintHeaderValues(logLine LogLine) (output string) {
|
||||
output = ""
|
||||
|
||||
output = output + "MyCall " + logLine.MyCall
|
||||
if logLine.Operator != "" {
|
||||
output = output + " (" + logLine.Operator + ")"
|
||||
}
|
||||
output = output + "\n"
|
||||
|
||||
if logLine.MyWWFF != "" {
|
||||
output = output + "MyWWFF " + logLine.MyWWFF + "\n"
|
||||
}
|
||||
|
||||
if logLine.MySOTA != "" {
|
||||
output = output + "MySOTA " + logLine.MySOTA + "\n"
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
// Date, Time, band, mode, call, report sent, report rcvd, Notes
|
||||
var logLineFormat = "%-10s %-4s %-4s %-4s %-10s %-4s %-4s %s \n"
|
||||
|
||||
// SprintColumnTitles displays the column titles for a log line
|
||||
func SprintColumnTitles(logLine LogLine) (output string) {
|
||||
output = fmt.Sprintf(logLineFormat, "Date", "Time", "Band", "Mode", "Call", "Sent", "Rcvd", "Notes")
|
||||
output = output + fmt.Sprintf(logLineFormat, "----", "----", "----", "----", "----", "----", "----", "----")
|
||||
return output
|
||||
}
|
||||
|
||||
// SprintLogInColumn displays the logLine in column mode
|
||||
func SprintLogInColumn(logLine LogLine) (output string) {
|
||||
notes := ""
|
||||
if logLine.Frequency != "" {
|
||||
notes = notes + "QRG: " + logLine.Frequency + " "
|
||||
}
|
||||
if logLine.Comment != "" {
|
||||
notes = notes + "[" + logLine.Comment + "] "
|
||||
}
|
||||
if logLine.QSLmsg != "" {
|
||||
notes = notes + "[" + logLine.QSLmsg + "] "
|
||||
}
|
||||
if logLine.OMname != "" {
|
||||
notes = notes + logLine.OMname + " "
|
||||
}
|
||||
if logLine.GridLoc != "" {
|
||||
notes = notes + logLine.GridLoc + " "
|
||||
}
|
||||
if logLine.WWFF != "" {
|
||||
notes = notes + logLine.WWFF + " "
|
||||
}
|
||||
if logLine.SOTA != "" {
|
||||
notes = notes + logLine.SOTA + " "
|
||||
}
|
||||
|
||||
output = fmt.Sprintf(logLineFormat, logLine.Date, logLine.Time, logLine.Band, logLine.Mode, logLine.Call, logLine.RSTsent, logLine.RSTrcvd, notes)
|
||||
|
||||
return output
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package cmd
|
||||
|
||||
/*
|
||||
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 (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// SprintLogRecord outputs the content of a logline
|
||||
func SprintLogRecord(logLine LogLine) string {
|
||||
var output strings.Builder
|
||||
|
||||
output.WriteString("Date " + logLine.Date + "\n")
|
||||
output.WriteString("MyCall " + logLine.MyCall + "\n")
|
||||
output.WriteString("Operator " + logLine.Operator + "\n")
|
||||
output.WriteString("MyWWFF " + logLine.MyWWFF + "\n")
|
||||
output.WriteString("MySOTA " + logLine.MySOTA + "\n")
|
||||
output.WriteString("QslMsg " + logLine.QslMsg + "\n")
|
||||
output.WriteString("Nickname " + logLine.Nickname + "\n")
|
||||
output.WriteString("Mode " + logLine.Mode + "\n")
|
||||
output.WriteString("ModeType " + logLine.ModeType + "\n")
|
||||
output.WriteString("Band " + logLine.Band + "\n")
|
||||
output.WriteString(" Lower " + fmt.Sprintf("%f", logLine.BandLowerLimit) + "\n")
|
||||
output.WriteString(" Upper " + fmt.Sprintf("%f", logLine.BandUpperLimit) + "\n")
|
||||
output.WriteString("Frequency " + logLine.Frequency + "\n")
|
||||
output.WriteString("Time " + logLine.Time + "\n")
|
||||
output.WriteString("Call " + logLine.Call + "\n")
|
||||
output.WriteString("Comment " + logLine.Comment + "\n")
|
||||
output.WriteString("QSLmsg " + logLine.QSLmsg + "\n")
|
||||
output.WriteString("OMname " + logLine.OMname + "\n")
|
||||
output.WriteString("GridLoc " + logLine.GridLoc + "\n")
|
||||
output.WriteString("RSTsent " + logLine.RSTsent + "\n")
|
||||
output.WriteString("RSTrcvd " + logLine.RSTrcvd + "\n")
|
||||
output.WriteString("SOTA " + logLine.SOTA + "\n")
|
||||
output.WriteString("WWFF " + logLine.WWFF + "\n")
|
||||
|
||||
return output.String()
|
||||
}
|
||||
|
||||
// SprintHeaderValues displays the header values
|
||||
func SprintHeaderValues(logLine LogLine) string {
|
||||
var output strings.Builder
|
||||
|
||||
output.WriteString("MyCall " + logLine.MyCall)
|
||||
if logLine.Operator != "" {
|
||||
output.WriteString(" (" + logLine.Operator + ")")
|
||||
}
|
||||
output.WriteString("\n")
|
||||
|
||||
if logLine.MyWWFF != "" {
|
||||
output.WriteString("MyWWFF " + logLine.MyWWFF + "\n")
|
||||
}
|
||||
|
||||
if logLine.MySOTA != "" {
|
||||
output.WriteString("MySOTA " + logLine.MySOTA + "\n")
|
||||
}
|
||||
|
||||
return output.String()
|
||||
}
|
||||
|
||||
// Date, Time, band, mode, call, report sent, report rcvd, Notes
|
||||
var logLineFormat = "%-10s %-4s %-4s %-4s %-10s %-4s %-4s %s \n"
|
||||
|
||||
// SprintColumnTitles displays the column titles for a log line
|
||||
func SprintColumnTitles(logLine LogLine) string {
|
||||
var output strings.Builder
|
||||
output.WriteString(fmt.Sprintf(logLineFormat, "Date", "Time", "Band", "Mode", "Call", "Sent", "Rcvd", "Notes"))
|
||||
output.WriteString(fmt.Sprintf(logLineFormat, "----", "----", "----", "----", "----", "----", "----", "----"))
|
||||
return output.String()
|
||||
}
|
||||
|
||||
// SprintLogInColumn displays the logLine in column mode
|
||||
func SprintLogInColumn(logLine LogLine) (output string) {
|
||||
var notes strings.Builder
|
||||
if logLine.Frequency != "" {
|
||||
notes.WriteString("QRG: " + logLine.Frequency + " ")
|
||||
}
|
||||
if logLine.Comment != "" {
|
||||
notes.WriteString("[" + logLine.Comment + "] ")
|
||||
}
|
||||
if logLine.QSLmsg != "" {
|
||||
notes.WriteString("[" + logLine.QSLmsg + "] ")
|
||||
}
|
||||
if logLine.OMname != "" {
|
||||
notes.WriteString(logLine.OMname + " ")
|
||||
}
|
||||
if logLine.GridLoc != "" {
|
||||
notes.WriteString(logLine.GridLoc + " ")
|
||||
}
|
||||
if logLine.WWFF != "" {
|
||||
notes.WriteString(logLine.WWFF + " ")
|
||||
}
|
||||
if logLine.SOTA != "" {
|
||||
notes.WriteString(logLine.SOTA + " ")
|
||||
}
|
||||
|
||||
output = fmt.Sprintf(logLineFormat, logLine.Date, logLine.Time, logLine.Band, logLine.Mode, logLine.Call, logLine.RSTsent, logLine.RSTrcvd, notes.String())
|
||||
|
||||
return output
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
//InferTimeBlock contains the information describing a time gap
|
||||
type InferTimeBlock struct {
|
||||
lastRecordedTime time.Time
|
||||
nextValidTime time.Time
|
||||
//Number of records without actual time
|
||||
noTimeCount int
|
||||
//Position in file of the first log entry with missing date
|
||||
logFilePosition int
|
||||
//Computed time interval
|
||||
deltatime time.Duration
|
||||
}
|
||||
|
||||
//ADIFdateTimeFormat describes the ADIF date & time parsing and displaying format pattern
|
||||
const ADIFdateTimeFormat = "2006-01-02 1504"
|
||||
|
||||
//displayTimeGapInfo will print the details stored in an InferTimeBlock
|
||||
func (tb *InferTimeBlock) String() string {
|
||||
var buffer strings.Builder
|
||||
buffer.WriteString(fmt.Sprintf("Last Recorded Time: %s\n", tb.lastRecordedTime.Format(ADIFdateTimeFormat)))
|
||||
buffer.WriteString(fmt.Sprintf("next Recorded Time: %s\n", tb.nextValidTime.Format(ADIFdateTimeFormat)))
|
||||
buffer.WriteString(fmt.Sprintf("Log position of last recorded time: %d\n", tb.logFilePosition))
|
||||
buffer.WriteString(fmt.Sprintf("Nbr of entries without time: %d\n", tb.noTimeCount))
|
||||
buffer.WriteString(fmt.Sprintf("Computed interval: %ds\n", int(tb.deltatime.Seconds())))
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
//finalizeTimeGap makes the necessary checks and computation
|
||||
func (tb *InferTimeBlock) finalizeTimeGap() error {
|
||||
|
||||
//Check that lastRecordedTime and nextValidTime are not null
|
||||
if tb.lastRecordedTime.IsZero() {
|
||||
return errors.New("Gap start time is empty")
|
||||
}
|
||||
if tb.nextValidTime.IsZero() {
|
||||
return errors.New("Gap end time is empty")
|
||||
}
|
||||
|
||||
//Are the two times equal?
|
||||
if tb.nextValidTime == tb.lastRecordedTime {
|
||||
return errors.New("The start and end gap times are equal")
|
||||
}
|
||||
|
||||
//Fail if we have a negative time difference
|
||||
if tb.nextValidTime.Before(tb.lastRecordedTime) {
|
||||
return errors.New("Gap start time is later than the Gap end time")
|
||||
}
|
||||
|
||||
//Compute the gap
|
||||
diff := tb.nextValidTime.Sub(tb.lastRecordedTime)
|
||||
tb.deltatime = time.Duration(diff / time.Duration(tb.noTimeCount+1))
|
||||
|
||||
//Do we have a positive noTimeCount
|
||||
if tb.noTimeCount < 1 {
|
||||
return fmt.Errorf("Invalid number of records without time (%d)", tb.noTimeCount)
|
||||
}
|
||||
|
||||
//TODO: What should we expect as logFilePosition?
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
//storeTimeGap updates an InferTimeBLock (last valid time, nbr of records without time). It returns true if we reached the end of the time gap.
|
||||
func (tb *InferTimeBlock) storeTimeGap(logline LogLine, position int) (bool, error) {
|
||||
var err error
|
||||
|
||||
//TODO: try to return fast and/or simpllify
|
||||
|
||||
//ActualTime is filled if a time could be found in the FLE input
|
||||
if logline.ActualTime != "" {
|
||||
//Are we starting a new block
|
||||
if tb.noTimeCount == 0 {
|
||||
if tb.lastRecordedTime, err = time.Parse(ADIFdateTimeFormat, logline.Date+" "+logline.ActualTime); err != nil {
|
||||
log.Println("Fatal error during internal date concersion: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
tb.logFilePosition = position
|
||||
} else {
|
||||
// We reached the end of the gap
|
||||
if tb.lastRecordedTime.IsZero(){
|
||||
return false, errors.New("Gap start time is empty")
|
||||
}
|
||||
if tb.nextValidTime, err = time.Parse(ADIFdateTimeFormat, logline.Date+" "+logline.ActualTime); err != nil {
|
||||
log.Println("Fatal error during internal date concersion: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
} else {
|
||||
//Check the data is correct.
|
||||
if tb.lastRecordedTime.IsZero() {
|
||||
err = errors.New("Gap start time is empty")
|
||||
//TODO: this smells
|
||||
}
|
||||
if !tb.nextValidTime.IsZero() {
|
||||
err = errors.New("Gap end time is not empty")
|
||||
}
|
||||
tb.noTimeCount++
|
||||
}
|
||||
return false, err
|
||||
}
|
@ -0,0 +1,298 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestInferTimeBlock_full_happyCase(t *testing.T) {
|
||||
//Given
|
||||
recordNumber := 4
|
||||
|
||||
logLine1 := LogLine{}
|
||||
logLine1.Date = "2020-05-24"
|
||||
logLine1.Time = "1401"
|
||||
logLine1.ActualTime = "1401"
|
||||
|
||||
logLine2 := LogLine{}
|
||||
logLine2.Date = "2020-05-24"
|
||||
logLine2.Time = "1401"
|
||||
|
||||
logLine3 := LogLine{}
|
||||
logLine3.Date = "2020-05-24"
|
||||
logLine3.Time = "1410"
|
||||
logLine3.ActualTime = "1410"
|
||||
|
||||
//When
|
||||
tb := InferTimeBlock{}
|
||||
isEndGap, err := tb.storeTimeGap(logLine1, recordNumber)
|
||||
if isEndGap == true || err != nil {
|
||||
t.Error("Unexpected results processing logline 1")
|
||||
}
|
||||
|
||||
isEndGap, err = tb.storeTimeGap(logLine2, recordNumber+1)
|
||||
if isEndGap == true || err != nil {
|
||||
t.Error("Unexpected results processing logline 2")
|
||||
}
|
||||
|
||||
isEndGap, err = tb.storeTimeGap(logLine3, recordNumber+2)
|
||||
if isEndGap == false || err != nil {
|
||||
t.Error("Unexpected results processing logline 3")
|
||||
}
|
||||
|
||||
err = tb.finalizeTimeGap()
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error finalizing the timeGap")
|
||||
}
|
||||
|
||||
fmt.Println(tb.String())
|
||||
|
||||
//Then
|
||||
expectedCount := 1
|
||||
if tb.noTimeCount != expectedCount {
|
||||
t.Errorf("Unexpected number of missing records: %d, expected %d", tb.noTimeCount, expectedCount)
|
||||
}
|
||||
|
||||
expectedInterval := time.Duration(time.Second * 270)
|
||||
if tb.deltatime != expectedInterval {
|
||||
t.Errorf("Unexpected interval: %d, expected %d", tb.deltatime, expectedInterval)
|
||||
}
|
||||
|
||||
expectedLastRecordedTime := time.Date(2020, time.May, 24, 14, 01, 0, 0, time.UTC)
|
||||
if tb.lastRecordedTime != expectedLastRecordedTime {
|
||||
t.Errorf("Unexpected last recorded time: %s, expected %s", tb.lastRecordedTime, expectedLastRecordedTime)
|
||||
}
|
||||
|
||||
expectedNextValidTime := time.Date(2020, time.May, 24, 14, 10, 0, 0, time.UTC)
|
||||
if tb.nextValidTime != expectedNextValidTime {
|
||||
t.Errorf("Unexpected last recorded time: %s, expected %s", tb.nextValidTime, expectedNextValidTime)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferTimeBlock_display_happyCase(t *testing.T) {
|
||||
//Given
|
||||
tb := InferTimeBlock{}
|
||||
tb.lastRecordedTime = time.Date(2020, time.May, 24, 14, 01, 0, 0, time.UTC)
|
||||
tb.nextValidTime = time.Date(2020, time.May, 24, 14, 10, 10, 0, time.UTC)
|
||||
tb.noTimeCount = 1
|
||||
|
||||
//When
|
||||
buffer1 := tb.String()
|
||||
|
||||
tb.finalizeTimeGap()
|
||||
|
||||
buffer2 := tb.String()
|
||||
|
||||
//Then
|
||||
expectedBuffer1 := "Last Recorded Time: 2020-05-24 1401\nnext Recorded Time: 2020-05-24 1410\nLog position of last recorded time: 0\nNbr of entries without time: 1\nComputed interval: 0s\n"
|
||||
expectedBuffer2 := "Last Recorded Time: 2020-05-24 1401\nnext Recorded Time: 2020-05-24 1410\nLog position of last recorded time: 0\nNbr of entries without time: 1\nComputed interval: 275s\n"
|
||||
|
||||
if buffer1 != expectedBuffer1 {
|
||||
t.Errorf("Not the expected display: got: \n%s\n while expecting: \n%s\n", buffer1, expectedBuffer1)
|
||||
}
|
||||
if buffer2 != expectedBuffer2 {
|
||||
t.Errorf("Not the expected finalized display: got: \n%s\n while expecting: \n%s\n", buffer2, expectedBuffer2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferTimeBlock_computeGaps_invalidData(t *testing.T) {
|
||||
//Given
|
||||
tb := InferTimeBlock{}
|
||||
|
||||
//When
|
||||
err := tb.finalizeTimeGap()
|
||||
|
||||
//Then
|
||||
if err == nil {
|
||||
t.Error("Should have failed with an error")
|
||||
}
|
||||
if err.Error() != "Gap start time is empty" {
|
||||
t.Error("Did not not fail with the expected error.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferTimeBlock_computeGaps_missingEnTime(t *testing.T) {
|
||||
//Given
|
||||
tb := InferTimeBlock{}
|
||||
tb.lastRecordedTime = time.Date(2020, time.May, 24, 14, 01, 0, 0, time.UTC)
|
||||
|
||||
//When
|
||||
err := tb.finalizeTimeGap()
|
||||
|
||||
//Then
|
||||
if err == nil {
|
||||
t.Error("Should have failed with an error")
|
||||
}
|
||||
if err.Error() != "Gap end time is empty" {
|
||||
t.Errorf("Did not not fail with the expected error. Failed with %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferTimeBlock_computeGaps_negativeDifference(t *testing.T) {
|
||||
//Given
|
||||
tb := InferTimeBlock{}
|
||||
tb.lastRecordedTime = time.Date(2020, time.May, 24, 14, 10, 0, 0, time.UTC)
|
||||
tb.nextValidTime = time.Date(2020, time.May, 24, 14, 01, 10, 0, time.UTC)
|
||||
|
||||
//When
|
||||
err := tb.finalizeTimeGap()
|
||||
|
||||
//Then
|
||||
if err == nil {
|
||||
t.Error("Should have failed with an error")
|
||||
}
|
||||
if err.Error() != "Gap start time is later than the Gap end time" {
|
||||
t.Errorf("Did not not fail with the expected error. Failed with %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferTimeBlock_computeGaps_noDifference(t *testing.T) {
|
||||
//Given
|
||||
tb := InferTimeBlock{}
|
||||
tb.lastRecordedTime = time.Date(2020, time.May, 24, 14, 00, 0, 0, time.UTC)
|
||||
tb.nextValidTime = time.Date(2020, time.May, 24, 14, 00, 00, 0, time.UTC)
|
||||
|
||||
//When
|
||||
err := tb.finalizeTimeGap()
|
||||
|
||||
//Then
|
||||
if err == nil {
|
||||
t.Error("Should have failed with an error")
|
||||
}
|
||||
if err.Error() != "The start and end gap times are equal" {
|
||||
t.Errorf("Did not not fail with the expected error. Failed with %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferTimeBlock_computeGaps_happyCase(t *testing.T) {
|
||||
//Given
|
||||
tb := InferTimeBlock{}
|
||||
tb.lastRecordedTime = time.Date(2020, time.May, 24, 14, 01, 0, 0, time.UTC)
|
||||
tb.nextValidTime = time.Date(2020, time.May, 24, 14, 10, 10, 0, time.UTC)
|
||||
tb.noTimeCount = 1
|
||||
|
||||
//When
|
||||
err := tb.finalizeTimeGap()
|
||||
|
||||
//Then
|
||||
if err != nil {
|
||||
t.Error("Should not have failed")
|
||||
}
|
||||
|
||||
//TODO: add some other validation
|
||||
}
|
||||
|
||||
func TestInferTimeBlock_startsNewBlock(t *testing.T) {
|
||||
// Given
|
||||
logLine := LogLine{}
|
||||
logLine.Date = "2020-05-24"
|
||||
logLine.Time = "1401"
|
||||
logLine.ActualTime = "1401"
|
||||
|
||||
recordNbr := 4
|
||||
|
||||
tb := InferTimeBlock{}
|
||||
|
||||
// When
|
||||
isEndGap, err := tb.storeTimeGap(logLine, recordNbr)
|
||||
|
||||
// Then
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %s", err)
|
||||
}
|
||||
if isEndGap == true {
|
||||
t.Errorf("Result is true while expectig false")
|
||||
}
|
||||
if tb.lastRecordedTime != time.Date(2020, time.May, 24, 14, 01, 0, 0, time.UTC) {
|
||||
t.Errorf("Not the expected lastRecordedTime")
|
||||
}
|
||||
if tb.noTimeCount != 0 {
|
||||
t.Errorf("nTimeCount should be 0, but is %d", tb.noTimeCount)
|
||||
}
|
||||
if tb.logFilePosition != recordNbr {
|
||||
t.Errorf("logFilePosition not set correctly: is %d while expecting %d", tb.logFilePosition, recordNbr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferTimeBlock_incrementCounter(t *testing.T) {
|
||||
// Given
|
||||
logLine := LogLine{}
|
||||
logLine.Date = "2020-05-24"
|
||||
logLine.Time = "1401"
|
||||
|
||||
recordNbr := 4
|
||||
|
||||
tb := InferTimeBlock{}
|
||||
tb.lastRecordedTime = time.Date(2020, time.May, 24, 14, 01, 0, 0, time.UTC)
|
||||
tb.logFilePosition = recordNbr
|
||||
|
||||
// When
|
||||
isEndGap, err := tb.storeTimeGap(logLine, recordNbr)
|
||||
|
||||
// Then
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %s", err)
|
||||
}
|
||||
if isEndGap == true {
|
||||
t.Errorf("Result is true while expectig false")
|
||||
}
|
||||
if tb.lastRecordedTime != time.Date(2020, time.May, 24, 14, 01, 0, 0, time.UTC) {
|
||||
t.Errorf("Not the expected lastRecordedTime")
|
||||
}
|
||||
if tb.noTimeCount != 1 {
|
||||
t.Errorf("nTimeCount should be 1, but is %d", tb.noTimeCount)
|
||||
}
|
||||
if tb.logFilePosition != recordNbr {
|
||||
t.Errorf("logFilePosition not set correctly: is %d while expecting %d", tb.logFilePosition, recordNbr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferTimeBlock_increment_missingLastTime(t *testing.T) {
|
||||
// Given
|
||||
logLine := LogLine{}
|
||||
logLine.Date = "2020-05-24"
|
||||
logLine.Time = "1401"
|
||||
|
||||
recordNbr := 4
|
||||
|
||||
tb := InferTimeBlock{}
|
||||
//tb.lastRecordedTime = time.Date(2020, time.May, 24, 14, 01, 0, 0, time.UTC)
|
||||
tb.logFilePosition = recordNbr
|
||||
|
||||
// When
|
||||
isEndGap, err := tb.storeTimeGap(logLine, recordNbr)
|
||||
|
||||
// Then
|
||||
if err.Error() != "Gap start time is empty" {
|
||||
t.Errorf("Unexpected error: %s", err)
|
||||
}
|
||||
if isEndGap == true {
|
||||
t.Errorf("Result is true while expectig false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferTimeBlock_increment_alreadyDefinedNewTime(t *testing.T) {
|
||||
// Given
|
||||
logLine := LogLine{}
|
||||
logLine.Date = "2020-05-24"
|
||||
logLine.Time = "1401"
|
||||
|
||||
recordNbr := 4
|
||||
|
||||
tb := InferTimeBlock{}
|
||||
tb.lastRecordedTime = time.Date(2020, time.May, 24, 14, 01, 0, 0, time.UTC)
|
||||
tb.nextValidTime = time.Date(2020, time.May, 24, 14, 01, 0, 0, time.UTC)
|
||||
tb.logFilePosition = recordNbr
|
||||
|
||||
// When
|
||||
isEndGap, err := tb.storeTimeGap(logLine, recordNbr)
|
||||
|
||||
// Then
|
||||
if err.Error() != "Gap end time is not empty" {
|
||||
t.Errorf("Unexpected error: %s", err)
|
||||
}
|
||||
if isEndGap == true {
|
||||
t.Errorf("Result is true while expectig false")
|
||||
}
|
||||
}
|
Loading…
Reference in new issue