Skip to content

Commit

Permalink
go test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene committed Aug 15, 2024
1 parent e0d278b commit 2926acb
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 18 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Go test

on: [push]

jobs:
build:

runs-on: ubuntu-latest
steps:
- name: Setup Go 1.21.x
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- name: Install dependencies
run: |
go get .
- name: Test
run: make test
103 changes: 85 additions & 18 deletions pkg/wireguard/wireguardclientconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/netip"
"strings"
"testing"
"time"

testingmocks "github.com/in4it/wireguard-server/pkg/testing/mocks"
)
Expand Down Expand Up @@ -52,9 +53,20 @@ func TestGetConfigNumberFromConnectionFile(t *testing.T) {
}

func TestWriteConfig(t *testing.T) {
l, err := net.Listen("tcp", CONFIGMANAGER_URI)
if err != nil {
t.Fatal(err)
var (
l net.Listener
err error
)
for {
l, err = net.Listen("tcp", CONFIGMANAGER_URI)
if err != nil {
if !strings.HasSuffix(err.Error(), "address already in use") {
t.Fatal(err)
}
time.Sleep(1 * time.Second)
} else {
break
}
}

ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -113,9 +125,20 @@ func TestWriteConfig(t *testing.T) {
}

func TestWriteConfigMultipleClients(t *testing.T) {
l, err := net.Listen("tcp", CONFIGMANAGER_URI)
if err != nil {
t.Fatal(err)
var (
l net.Listener
err error
)
for {
l, err = net.Listen("tcp", CONFIGMANAGER_URI)
if err != nil {
if !strings.HasSuffix(err.Error(), "address already in use") {
t.Fatal(err)
}
time.Sleep(1 * time.Second)
} else {
break
}
}

ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -176,9 +199,20 @@ func TestWriteConfigMultipleClients(t *testing.T) {
}

func TestCreateAndDeleteAllClientConfig(t *testing.T) {
l, err := net.Listen("tcp", CONFIGMANAGER_URI)
if err != nil {
t.Fatal(err)
var (
l net.Listener
err error
)
for {
l, err = net.Listen("tcp", CONFIGMANAGER_URI)
if err != nil {
if !strings.HasSuffix(err.Error(), "address already in use") {
t.Fatal(err)
}
time.Sleep(1 * time.Second)
} else {
break
}
}

ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -253,9 +287,20 @@ func TestCreateAndDeleteAllClientConfig(t *testing.T) {
}
}
func TestCreateAndDeleteClientConfig(t *testing.T) {
l, err := net.Listen("tcp", CONFIGMANAGER_URI)
if err != nil {
t.Fatal(err)
var (
l net.Listener
err error
)
for {
l, err = net.Listen("tcp", CONFIGMANAGER_URI)
if err != nil {
if !strings.HasSuffix(err.Error(), "address already in use") {
t.Fatal(err)
}
time.Sleep(1 * time.Second)
} else {
break
}
}

ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -331,9 +376,20 @@ func TestCreateAndDeleteClientConfig(t *testing.T) {
}

func TestCreateAndDisableAllClientConfig(t *testing.T) {
l, err := net.Listen("tcp", CONFIGMANAGER_URI)
if err != nil {
t.Fatal(err)
var (
l net.Listener
err error
)
for {
l, err = net.Listen("tcp", CONFIGMANAGER_URI)
if err != nil {
if !strings.HasSuffix(err.Error(), "address already in use") {
t.Fatal(err)
}
time.Sleep(1 * time.Second)
} else {
break
}
}

ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -444,9 +500,20 @@ func TestCreateAndDisableAllClientConfig(t *testing.T) {
}

func TestUpdateClientConfig(t *testing.T) {
l, err := net.Listen("tcp", CONFIGMANAGER_URI)
if err != nil {
t.Fatal(err)
var (
l net.Listener
err error
)
for {
l, err = net.Listen("tcp", CONFIGMANAGER_URI)
if err != nil {
if !strings.HasSuffix(err.Error(), "address already in use") {
t.Fatal(err)
}
time.Sleep(1 * time.Second)
} else {
break
}
}

ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 2926acb

Please sign in to comment.