diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..6cadf56 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/pkg/configmanager/resources/.gitignore b/pkg/configmanager/resources/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/pkg/configmanager/resources/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/pkg/rest/resources/.gitignore b/pkg/rest/resources/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/pkg/rest/resources/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/pkg/rest/static/.gitignore b/pkg/rest/static/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/pkg/rest/static/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/pkg/wireguard/wireguardclientconfig_test.go b/pkg/wireguard/wireguardclientconfig_test.go index c7074db..3e2c159 100644 --- a/pkg/wireguard/wireguardclientconfig_test.go +++ b/pkg/wireguard/wireguardclientconfig_test.go @@ -10,6 +10,7 @@ import ( "net/netip" "strings" "testing" + "time" testingmocks "github.com/in4it/wireguard-server/pkg/testing/mocks" ) @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) {