diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..33b5845 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,27 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.25' + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... diff --git a/configuration_test.go b/configuration_test.go index 5a87ce3..a608a03 100644 --- a/configuration_test.go +++ b/configuration_test.go @@ -3,6 +3,7 @@ package timewlib import ( "fmt" "testing" + "time" ) var testCases = map[string]bool{ @@ -54,22 +55,24 @@ func TestRequireConfirmation(t *testing.T) { func TestGetReportStartDate(t *testing.T) { var config Configuration = map[string]string{"temp.report.start": "20240308T230000Z"} start, err := config.GetReportStartDate() + var expected = time.Date(2024, 3, 8, 23, 0, 0, 0, time.UTC).Local() if err != nil { t.Fatal(err) } - if start.Day() != 9 || start.Month() != 3 || start.Year() != 2024 || start.Hour() != 0 || start.Minute() != 0 { - t.Fatalf("Parsed date is not 20240308T230000Z but %s", start) + if expected != start { + t.Fatalf("Parsed date is not %s but %s", expected, start) } } func TestGetReportEndDate(t *testing.T) { var config Configuration = map[string]string{"temp.report.end": "20240309T230000Z"} - start, err := config.GetReportEndDate() + end, err := config.GetReportEndDate() + var expected = time.Date(2024, 3, 9, 23, 0, 0, 0, time.UTC).Local() if err != nil { t.Fatal(err) } - if start.Day() != 10 || start.Month() != 3 || start.Year() != 2024 || start.Hour() != 0 || start.Minute() != 0 { - t.Fatalf("Parsed date is not 20240309T230000Z but %s", start) + if expected != end { + t.Fatalf("Parsed date is not %s but %s", expected, end) } } diff --git a/interval_test.go b/interval_test.go index b94f224..5016556 100644 --- a/interval_test.go +++ b/interval_test.go @@ -31,7 +31,7 @@ func TestNewInterval(t *testing.T) { t.Errorf("interval.IsSameHour() is not correct :%t", interval.IsSameHour()) } today := time.Now().Format("2006-01-02") - timezone := time.Now().Format("Z0700 MST") + timezone := time.Now().Local().Format("-0700 MST") expectedStringValue := fmt.Sprintf("[%s 10:00:00 %s-%s 10:30:00 %s]", today, timezone, today, timezone) if interval.String() != expectedStringValue { t.Errorf("interval.String() is not correct :%s != %s", expectedStringValue, interval.String()) diff --git a/output_test.go b/output_test.go index c92e1f3..167779b 100644 --- a/output_test.go +++ b/output_test.go @@ -1,14 +1,18 @@ package timewlib import ( + "fmt" "testing" + "time" ) func TestGenerateNoDataMessageComplete(t *testing.T) { var config Configuration = map[string]string{"temp.report.start": "20240308T230000Z", "temp.report.end": "20240309T230000Z"} message := GenerateNoDataMessage(config) t.Log(message) - expected := "No filtered data found in the range 2024-03-09T00:00:00 - 2024-03-10T00:00:00." + startDate := time.Date(2024, 3, 8, 23, 0, 0, 0, time.UTC).Local().Format("2006-01-02T15:04:05") + endDate := time.Date(2024, 3, 9, 23, 0, 0, 0, time.UTC).Local().Format("2006-01-02T15:04:05") + expected := fmt.Sprintf("No filtered data found in the range %s - %s.", startDate, endDate) if message != expected { t.Fatalf("Actual message [%s] is different from expected [%s]", message, expected) } diff --git a/processor_test.go b/processor_test.go index 6afa3bc..668834e 100644 --- a/processor_test.go +++ b/processor_test.go @@ -95,9 +95,9 @@ func TestProcessEndDateError(t *testing.T) { func TestParseIsoLocal(t *testing.T) { parsedDate, err := parseIsoLocal("20230101T003000Z") if err != nil { - t.Errorf("Error while parsing date") + t.Errorf("Error while parsing date %v", err) } - expectedDate := time.Date(2023, 01, 01, 01, 30, 0, 0, time.Local) + expectedDate := time.Date(2023, 01, 01, 00, 30, 0, 0, time.UTC).Local() if parsedDate != expectedDate { t.Errorf("Expected start date to be [%v], found instead [%v]", expectedDate, parsedDate) }