Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov committed Oct 18, 2024
1 parent 193143f commit b22f85f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
19 changes: 3 additions & 16 deletions pkg/solana/internal/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,18 @@ func (t *testLoader) load() (any, error) {
return nil, nil
}

func newTestLoader(lazyLoad bool) *testLoader {
func newTestLoader() *testLoader {
loader := testLoader{}
loader.Loader = NewLoader[any](lazyLoad, loader.load)
loader.Loader = NewLoader[any](loader.load)
return &loader
}

func TestLoader(t *testing.T) {
t.Run("direct loading", func(t *testing.T) {
loader := newTestLoader(false)
loader := newTestLoader()
_, _ = loader.Get()
_, _ = loader.Get()
_, _ = loader.Get()
require.Equal(t, 3, loader.callCount)
})

t.Run("lazy loading", func(t *testing.T) {
loader := newTestLoader(true)
_, _ = loader.Get()
_, _ = loader.Get()
require.Equal(t, 1, loader.callCount)

// Calls load function again after Reset()
loader.Reset()
_, _ = loader.Get()
_, _ = loader.Get()
require.Equal(t, 2, loader.callCount)
})
}
5 changes: 2 additions & 3 deletions pkg/solana/monitor/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ func TestBalanceMonitor(t *testing.T) {
}
}

getClient := func() (BalanceClient, error) {
b.reader = internal.NewLoader[BalanceClient](func() (BalanceClient, error) {
return client, nil
}
b.reader = internal.NewLoader[BalanceClient](true, getClient)
})

servicetest.Run(t, b)
select {
Expand Down

0 comments on commit b22f85f

Please sign in to comment.