This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce unit tests and corresponding GH workflow (#19)
- Loading branch information
1 parent
ee6e2ea
commit 1a42d11
Showing
12 changed files
with
818 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Unit Tests | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
workflow_call: | ||
outputs: | ||
workflow_output: | ||
description: "Unit tests output" | ||
value: ${{ jobs.go_test.outputs.test_output_failure }} | ||
|
||
jobs: | ||
go_test: | ||
name: Execution | ||
runs-on: ubuntu-latest | ||
outputs: | ||
test_output_failure: ${{ steps.run_tests_failure.outputs.test_output }} | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.21.x | ||
|
||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
|
||
- name: Run Go Test | ||
run: make unit-tests | ||
|
||
- name: Run Go Test Failed | ||
if: failure() | ||
id: run_tests_failure | ||
run: echo "test_output=false" >> $GITHUB_OUTPUT | ||
|
||
- name: SonarCloud Scan | ||
if: ${{ env.HAVE_SONAR_TOKEN == 'true' }} | ||
uses: SonarSource/sonarcloud-github-action@master | ||
env: | ||
HAVE_SONAR_TOKEN: ${{ secrets.SONAR_TOKEN != '' }} | ||
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dist | ||
docker/data | ||
docker/data | ||
coverage.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestResolveAddr(t *testing.T) { | ||
t.Parallel() | ||
|
||
tcpAddrBuilder := func(t *testing.T, address string) *net.TCPAddr { | ||
tcpAddr, err := net.ResolveTCPAddr("", address) | ||
require.NoError(t, err) | ||
|
||
return tcpAddr | ||
} | ||
|
||
cases := []struct { | ||
name string | ||
address string | ||
defaultIP string | ||
errMsg string | ||
}{ | ||
{ | ||
name: "incorrect address", | ||
address: "Foo Bar", | ||
errMsg: "failed to parse addr", | ||
}, | ||
{ | ||
name: "only port provided", | ||
address: ":8080", | ||
defaultIP: "127.0.0.1", | ||
}, | ||
{ | ||
name: "both address and port provided", | ||
address: "0.0.0.0:9000", | ||
defaultIP: "", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
c := c | ||
t.Run(c.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
ipAddr, err := ResolveAddr(c.address, c.defaultIP) | ||
if c.errMsg != "" { | ||
require.ErrorContains(t, err, c.errMsg) | ||
} else { | ||
require.NoError(t, err) | ||
expectedIPAddr := tcpAddrBuilder(t, fmt.Sprintf("%s%s", c.defaultIP, c.address)) | ||
require.Equal(t, expectedIPAddr, ipAddr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.