Skip to content

Commit

Permalink
go test workflow (#3)
Browse files Browse the repository at this point in the history
* go test workflow
  • Loading branch information
wardviaene authored Aug 15, 2024
1 parent e0d278b commit 6154629
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 18 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Go test

on: [push]

jobs:
build:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go 1.21.x
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- name: Install dependencies
run: |
go get ./...
- name: Go generate
run: |
go generate ./...
touch pkg/rest/static/placeholder # we're not building frontend, so we put a placeholder
- name: Test
run: make test
4 changes: 4 additions & 0 deletions pkg/configmanager/resources/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
4 changes: 4 additions & 0 deletions pkg/rest/resources/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
4 changes: 4 additions & 0 deletions pkg/rest/static/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
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 6154629

Please sign in to comment.