Skip to content

Commit

Permalink
Fix unit test (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
linxGnu authored Sep 14, 2022
1 parent 6294f8b commit 7d0352f
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 22 deletions.
26 changes: 19 additions & 7 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,44 @@ on: [push, pull_request]
jobs:
build:
name: Build
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up GCC
run: |
sudo apt install gcc g++ -y
shell: bash

- name: Set up Go 1.15
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.15

- name: Linter
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.42
version: v1.29

- name: Start SMSC
run: |
g++ example/smsc.cpp -o smsc
./smsc&
shell: bash

- name: Test Coverage
run: go test -v -race -count=1 -coverprofile=coverage.out

- name: Convert coverage to lcov
uses: jandelgado/gcov2lcov-action@v1.0.4
uses: jandelgado/gcov2lcov-action@v1
with:
version: latest
infile: coverage.out
outfile: coverage.lcov

- name: Coveralls
uses: coverallsapp/github-action@v1.1.0
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
2 changes: 1 addition & 1 deletion connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var auths = [][2]string{
}

const (
smscAddr = "smscsim.melroselabs.com:2775"
smscAddr = "127.0.0.1:2775"
mess = "Thử nghiệm: chuẩn bị nế mễ"
)

Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion example/smsc/run.sh

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/linxGnu/gosmpp

require (
github.com/stretchr/testify v1.7.1
github.com/stretchr/testify v1.8.0
golang.org/x/text v0.3.7
)

Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
4 changes: 2 additions & 2 deletions transceivable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ func TestTRXSubmitSM(t *testing.T) {
time.Sleep(5 * time.Second)

// wait response received
require.EqualValues(t, 20, atomic.LoadInt32(&countSubmitSMResp))
require.True(t, atomic.LoadInt32(&countSubmitSMResp) >= 15)

// rebind and submit again
trans.rebind()
err = trans.Transceiver().Submit(newSubmitSM(auth.SystemID))
require.Nil(t, err)
time.Sleep(time.Second)
require.EqualValues(t, 21, atomic.LoadInt32(&countSubmitSMResp))
require.True(t, atomic.LoadInt32(&countSubmitSMResp) >= 16)
}

func newSubmitSM(systemID string) *pdu.SubmitSM {
Expand Down
2 changes: 1 addition & 1 deletion transmittable.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (t *transmittable) check(p pdu.PDU, n int, err error) (closing bool) {

if n == 0 {
if nErr, ok := err.(net.Error); ok {
closing = nErr.Timeout() || !nErr.Temporary()
closing = nErr.Timeout()
} else {
closing = true
}
Expand Down
9 changes: 2 additions & 7 deletions transmittable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func TestTransmit(t *testing.T) {
})

errorHandling := func(t *testing.T, trigger func(*transmittable)) {
conn, err := net.Dial("tcp", "smscsim.melroselabs.com:2775")
require.Nil(t, err)
conn, err := net.Dial("tcp", smscAddr)
require.NoError(t, err)

var tr transmittable
tr.input = make(chan pdu.PDU, 1)
Expand Down Expand Up @@ -103,11 +103,6 @@ func TestTransmit(t *testing.T) {
var p pdu.CancelSM
tr.check(&p, 0, fmt.Errorf("fake error"))
})

errorHandling(t, func(tr *transmittable) {
var p pdu.CancelSM
tr.check(&p, 0, &net.DNSError{IsTemporary: false})
})
})

t.Run("SubmitErr", func(t *testing.T) {
Expand Down

0 comments on commit 7d0352f

Please sign in to comment.