Skip to content

Commit

Permalink
Merge pull request #1257 from adamdecaf/gotest-on-windows
Browse files Browse the repository at this point in the history
build: run Go tests on Windows
  • Loading branch information
adamdecaf authored Jun 30, 2023
2 parents 5603e9e + 8b46ed1 commit 86560b3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
23 changes: 12 additions & 11 deletions cmd/writeACH/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,24 @@ func write(path string) {
for i := 0; i < 1250; i++ {
entrySeq = entrySeq + 1

entryEntrySeq := ach.NewEntryDetail()
entryEntrySeq.TransactionCode = ach.CheckingCredit
entryEntrySeq.SetRDFI("231380104")
entryEntrySeq.DFIAccountNumber = randomdata.StringNumber(10, "")
entryEntrySeq.IndividualName = randomdata.FullName(randomdata.RandomGender)
entryEntrySeq.SetTraceNumber(bh.ODFIIdentification, entrySeq)
entryEntrySeq.IdentificationNumber = "#" + randomdata.StringNumber(6, "") + "#"
entryEntrySeq.Category = ach.CategoryForward
entryEntrySeq.AddendaRecordIndicator = 1
entryDetail := ach.NewEntryDetail()
entryDetail.TransactionCode = ach.CheckingCredit
entryDetail.SetRDFI("231380104")
entryDetail.DFIAccountNumber = randomdata.StringNumber(10, "")
entryDetail.IndividualName = randomdata.FullName(randomdata.RandomGender)
entryDetail.SetTraceNumber(bh.ODFIIdentification, entrySeq)
entryDetail.IdentificationNumber = "#" + randomdata.StringNumber(6, "") + "#"
entryDetail.Category = ach.CategoryForward
entryDetail.AddendaRecordIndicator = 1
entryDetail.Amount = 10023

// Add addenda record for an entry
addendaEntrySeq := ach.NewAddenda05()
addendaEntrySeq.PaymentRelatedInformation = randomdata.SillyName() + " bonus pay for amazing work on #OSS"
entryEntrySeq.AddAddenda05(addendaEntrySeq)
entryDetail.AddAddenda05(addendaEntrySeq)

// Add entries
batch.AddEntry(entryEntrySeq)
batch.AddEntry(entryDetail)

}

Expand Down
26 changes: 8 additions & 18 deletions cmd/writeACH/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,24 @@
package main

import (
"fmt"
"os"
"path/filepath"
"testing"
"time"
)

// TestFileCreate tests creating an ACH File
func TestFileWrite(t *testing.T) {
testFileWrite(t)
}

/*//BenchmarkTestFileCreate benchmarks creating an ACH File
func BenchmarkTestFileWrite(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testFileWrite(b)
}
}*/

// FileCreate creates an ACH File
func testFileWrite(t testing.TB) {
filename, err := os.MkdirTemp("", "ach-writeACH-test")
dir, err := os.MkdirTemp("", "ach-writeACH-test")
if err != nil {
t.Fatal(err.Error())
}
defer os.Remove(filename)
defer os.RemoveAll(dir)

write(filename)
path := filepath.Join(dir, fmt.Sprintf("%s.ach", time.Now().UTC().Format("200601021504")))
write(path)

s, err := os.Stat(filename)
s, err := os.Stat(path)
if err != nil {
t.Fatal(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ clean:
.PHONY: check
check:
ifeq ($(OS),Windows_NT)
@echo "Skipping checks on Windows, currently unsupported."
go test ./...
else
@wget -O lint-project.sh https://raw.githubusercontent.com/moov-io/infra/master/go/lint-project.sh
@chmod +x ./lint-project.sh
Expand Down
8 changes: 7 additions & 1 deletion reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io"
"os"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -2048,7 +2049,12 @@ func TestReadFile_SkipValidation(t *testing.T) {

// checking output
var buf bytes.Buffer
if err := NewWriter(&buf).Write(&f); err != nil {
w := NewWriter(&buf)
if runtime.GOOS == "windows" {
w.LineEnding = "\r\n"
}
err = w.Write(&f)
if err != nil {
t.Errorf("%T: %s", err, err)
}
output := strings.TrimSpace(buf.String())
Expand Down

0 comments on commit 86560b3

Please sign in to comment.