Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,11 @@ on:

jobs:
test:
name: Run Tests
runs-on: ubuntu-20.04
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.21.x
- name: Checkout
uses: actions/checkout@v3
- name: Cache Modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-v1-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run tests
run: go test -v ./...
uses: upfluence/actions/.github/workflows/lib-go-test.yml@master
secrets: inherit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when i said, no private i meant you can use the public action: https://github.com/upfluence/actions/blob/master/.github/workflows/lib-go-test.yml

release:
needs: test
if: github.ref == 'refs/heads/master'
uses: upfluence/actions/.github/workflows/lib-any-release.yml@master
secrets: inherit
16 changes: 2 additions & 14 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,5 @@ on: [pull_request]

jobs:
lint:
name: runner / golangci-lint
runs-on: ubuntu-20.04
timeout-minutes: 30
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.21.x
- name: Checkout
uses: actions/checkout@v3
- name: golanci-lint
uses: upfluence/action-golangci-lint@master
with:
github_token: ${{ secrets.github_token }}
uses: upfluence/actions/.github/workflows/lint.yml@master
secrets: inherit
19 changes: 14 additions & 5 deletions currency/rate_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ type Exchanger struct {
}

func (e *Exchanger) Exchange(ctx context.Context, m Money, c Currency) (Money, error) {
exm, err := e.exchange(ctx, m, c)

return exm, errors.WithTags(err, map[string]interface{}{
"target_currency": c,
"source_currency": m.Currency,
"source_cents": m.Cents,
})
}

func (e *Exchanger) exchange(ctx context.Context, m Money, c Currency) (Money, error) {
if c == m.Currency {
return m, nil
}
Expand All @@ -34,27 +44,26 @@ func (e *Exchanger) Exchange(ctx context.Context, m Money, c Currency) (Money, e
}

var (
err error

fromRate = 1.
toRate = 1.
)

if m.Currency != e.BaseCurrency() {
var err error

fromRate, err = e.Rate(ctx, m.Currency)

if err != nil {
return Money{}, err
return Money{}, errors.Wrap(err, "could not get source rate")
}
}

if c != e.BaseCurrency() {
var err error

toRate, err = e.Rate(ctx, c)

if err != nil {
return Money{}, err
return Money{}, errors.Wrap(err, "could not get target rate")
}
}

Expand Down
2 changes: 1 addition & 1 deletion currency/rate_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestExchange(t *testing.T) {

res, err := e.Exchange(context.Background(), tt.in, tt.t)

assert.Equal(t, tt.wantErr, err)
assert.ErrorIs(t, err, tt.wantErr)
assert.Equal(t, tt.wantMoney, res)
}
}
11 changes: 9 additions & 2 deletions syncutil/singleflight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func TestSingleflightStopOnClose(t *testing.T) {
var (
sf Singleflight
ctr int32
wg sync.WaitGroup

ctx = context.Background()
donec = make(chan struct{})
Expand All @@ -130,17 +131,23 @@ func TestSingleflightStopOnClose(t *testing.T) {
return nil
}

wg.Add(1)

go func() {
ok, err := sf.Do(ctx, fn)

assert.True(t, ok)
assert.Equal(t, context.Canceled, err)

wg.Done()
}()

time.Sleep(10 * time.Millisecond)

sf.Close()
close(donec)
assert.Equal(t, int32(0), atomic.LoadInt32(&ctr))

sf.Close()
wg.Wait()

assert.Equal(t, int32(0), atomic.LoadInt32(&ctr))
}
Loading