Skip to content

Commit

Permalink
Merge pull request #240 from adamdecaf/misc-cleanup-2023-08-24
Browse files Browse the repository at this point in the history
Misc cleanup
  • Loading branch information
adamdecaf authored Aug 24, 2023
2 parents c5e6e61 + dfe7482 commit c211e00
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 23 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ jobs:
if: runner.os == 'Linux'
run: bash <(curl -s https://codecov.io/bash)

docker:
name: Docker Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: 'stable'
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Docker Build
if: runner.os == 'Linux'
run: make docker && make build && make test-integration && make clean-integration
5 changes: 3 additions & 2 deletions .github/workflows/podman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:

- name: Buildah Action
id: build-image
if: ${{ github.event.pull_request.head.repo.full_name == 'moov-io/fed' }}
uses: redhat-actions/buildah-build@v2
with:
image: moov/fed
Expand All @@ -42,15 +43,15 @@ jobs:
./Dockerfile
- name: Log in to the GitHub Container registry
if: runner.os == 'Linux' && github.repository == 'moov-io/fed'
if: ${{ github.event.pull_request.head.repo.full_name == 'moov-io/fed' }}
uses: redhat-actions/podman-login@v1
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Push to GitHub Container Repository
if: runner.os == 'Linux' && github.repository == 'moov-io/fed'
if: ${{ github.event.pull_request.head.repo.full_name == 'moov-io/fed' }}
id: push-to-ghcr
uses: redhat-actions/push-to-registry@v2
with:
Expand Down
20 changes: 17 additions & 3 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ func main() {
}

// Start Admin server (with Prometheus metrics)
adminServer := admin.NewServer(*adminAddr)
adminServer, err := admin.New(admin.Opts{
Addr: *adminAddr,
})
if err != nil {
logger.LogErrorf("problem creating admin server: %v", err)
os.Exit(1)
}
adminServer.AddVersionHandler(fed.Version) // Setup 'GET /version'
go func() {
logger.Info().Logf(fmt.Sprintf("listening on %s", adminServer.BindAddr()))
Expand All @@ -113,8 +119,16 @@ func main() {
// Start our searcher
searcher := &searcher{logger: logger}

fedACHData := fedACHDataFile(logger)
fedWireData := fedWireDataFile(logger)
fedACHData, err := fedACHDataFile(logger)
if err != nil {
logger.LogErrorf("problem downloading FedACH: %v", err)
os.Exit(1)
}
fedWireData, err := fedWireDataFile(logger)
if err != nil {
logger.LogErrorf("problem downloading FedWire: %v", err)
os.Exit(1)
}

if err := setupSearcher(logger, searcher, fedACHData, fedWireData); err != nil {
logger.Logf("read: %v", err)
Expand Down
20 changes: 10 additions & 10 deletions cmd/server/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,38 @@ import (
"github.com/moov-io/fed/pkg/download"
)

func fedACHDataFile(logger log.Logger) io.Reader {
func fedACHDataFile(logger log.Logger) (io.Reader, error) {
if file, err := attemptFileDownload(logger, "fedach"); file != nil {
return file
return file, nil
} else if err != nil {
panic(fmt.Sprintf("problem downloading fedach: %v", err))
return nil, fmt.Errorf("problem downloading fedach: %v", err)
}

path := readDataFilepath("FEDACH_DATA_PATH", "./data/FedACHdir.txt")
logger.Logf("search: loading %s for ACH data", path)

file, err := os.Open(path)
if err != nil {
panic(fmt.Sprintf("problem opening %s: %v", path, err))
return nil, fmt.Errorf("problem opening %s: %v", path, err)
}
return file
return file, nil
}

func fedWireDataFile(logger log.Logger) io.Reader {
func fedWireDataFile(logger log.Logger) (io.Reader, error) {
if file, err := attemptFileDownload(logger, "fedwire"); file != nil {
return file
return file, nil
} else if err != nil {
panic(fmt.Sprintf("problem downloading fedwire: %v", err))
return nil, fmt.Errorf("problem downloading fedwire: %v", err)
}

path := readDataFilepath("FEDWIRE_DATA_PATH", "./data/fpddir.txt")
logger.Logf("search: loading %s for Wire data", path)

file, err := os.Open(path)
if err != nil {
panic(fmt.Sprintf("problem opening %s: %v", path, err))
return nil, fmt.Errorf("problem opening %s: %v", path, err)
}
return file
return file, nil
}

func attemptFileDownload(logger log.Logger, listName string) (io.Reader, error) {
Expand Down
20 changes: 20 additions & 0 deletions cmd/server/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,28 @@ import (
"testing"

"github.com/moov-io/base/log"

"github.com/stretchr/testify/require"
)

func TestReader__fedACHDataFile(t *testing.T) {
t.Setenv("FRB_ROUTING_NUMBER", "")
t.Setenv("FRB_DOWNLOAD_CODE", "")

r, err := fedACHDataFile(log.NewTestLogger())
require.Nil(t, r)
require.ErrorContains(t, err, "no such file or directory")
}

func TestReader__fedWireDataFile(t *testing.T) {
t.Setenv("FRB_ROUTING_NUMBER", "")
t.Setenv("FRB_DOWNLOAD_CODE", "")

r, err := fedWireDataFile(log.NewTestLogger())
require.Nil(t, r)
require.ErrorContains(t, err, "no such file or directory")
}

func TestReader__readFEDACHData(t *testing.T) {
s := &searcher{logger: log.NewNopLogger()}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-kit/kit v0.12.0
github.com/gorilla/mux v1.8.0
github.com/hashicorp/golang-lru v0.6.0
github.com/moov-io/base v0.45.1
github.com/moov-io/base v0.46.0
github.com/prometheus/client_golang v1.16.0
github.com/stretchr/testify v1.8.4
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/moov-io/base v0.45.1 h1:1gZuINLBAw+HS78NLcKjSd8cH8fmA2qIHZwgYP+N/WU=
github.com/moov-io/base v0.45.1/go.mod h1:F2hLIojBgQJxRWTFLRTYuta/w+z2BBgDcd5k0BSifGA=
github.com/moov-io/base v0.46.0 h1:4sgFjfD9EELJ+i6cGfPtezoPAAxwE3imLJ64bbHtBwM=
github.com/moov-io/base v0.46.0/go.mod h1:AFoLPJA1uuylLp33g1nGzTnGk8zyqYH7KfBS7flc0P8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8=
Expand Down
5 changes: 0 additions & 5 deletions pkg/strcmp/strcmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
mrand "math/rand"
"strings"
"testing"
"time"

"github.com/docker/docker/pkg/namesgenerator"
)
Expand All @@ -21,10 +20,6 @@ var (
flagIterations = flag.Int("iterations", 1000, "How many iterations of each algorithm to test")
)

func init() {
mrand.Seed(time.Now().Unix())
}

func randString() string {
size := mrand.Uint32() % 1000 //nolint:gosec // max string size of 1k
bs := make([]byte, size)
Expand Down

0 comments on commit c211e00

Please sign in to comment.