Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene committed Oct 15, 2024
1 parent 705bb76 commit d3ac251
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
- name: Go generate
run: |
go generate ./...
touch pkg/rest/static/placeholder # we're not building frontend, so we put a placeholder
touch cmd/rest-server/static/placeholder # we're not building frontend, so we put a placeholder
- name: Test
run: make test
2 changes: 1 addition & 1 deletion cmd/rest-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
log.Fatalf("startup failed: userstore initialization error: %s", err)
}

scimInstance := scim.New(localStorage, userStore, "", wireguard.DisableAllClientConfigs, wireguard.ReactivateAllClientConfigs)
scimInstance := scim.New(localStorage, userStore, "")

apps := map[string]rest.AppClient{
"vpn": vpn.New(localStorage, userStore),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
golang.org/x/term v0.25.0
)

require github.com/in4it/go-devops-platform v0.0.0-20241015173332-a45080cabae5 // indirect
require github.com/in4it/go-devops-platform v0.0.0-20241015191315-e2f711a32e69 // indirect

require (
github.com/aws/aws-sdk-go-v2 v1.32.2 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ github.com/in4it/go-devops-platform v0.0.0-20241015173130-0b49ea0db408 h1:iQl/CX
github.com/in4it/go-devops-platform v0.0.0-20241015173130-0b49ea0db408/go.mod h1:xugWZer+8U7DcIWlE95SiPvtVPmJzhB9YCYiIScLK5Q=
github.com/in4it/go-devops-platform v0.0.0-20241015173332-a45080cabae5 h1:pcZ2PeYjk5/Bis6llji5uTqocjbIpxPlm4flLoweVt0=
github.com/in4it/go-devops-platform v0.0.0-20241015173332-a45080cabae5/go.mod h1:xugWZer+8U7DcIWlE95SiPvtVPmJzhB9YCYiIScLK5Q=
github.com/in4it/go-devops-platform v0.0.0-20241015191019-e2183445416a h1:y0pHhwuhAZYB4v99PHYScjyPv45mfCM5iiUWL6rAhIg=
github.com/in4it/go-devops-platform v0.0.0-20241015191019-e2183445416a/go.mod h1:xugWZer+8U7DcIWlE95SiPvtVPmJzhB9YCYiIScLK5Q=
github.com/in4it/go-devops-platform v0.0.0-20241015191315-e2f711a32e69 h1:/1BTKr5cqiQKAf8KMhR8z6Pup7eqzDbh32qQb+xh4Tw=
github.com/in4it/go-devops-platform v0.0.0-20241015191315-e2f711a32e69/go.mod h1:xugWZer+8U7DcIWlE95SiPvtVPmJzhB9YCYiIScLK5Q=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
Expand Down
33 changes: 28 additions & 5 deletions pkg/vpn/vpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ const USERSTORE_MAX_USERS = 1000

func TestSCIMCreateUserConnectionDeleteUserFlow(t *testing.T) {
storage := &memorystorage.MockMemoryStorage{}
userStore, err := users.NewUserStore(storage, USERSTORE_MAX_USERS)
userStore, err := users.NewUserStoreWithHooks(storage, USERSTORE_MAX_USERS, users.UserHooks{
DisableFunc: wireguard.DisableAllClientConfigs,
DeleteFunc: wireguard.DeleteAllClientConfigs,
ReactivateFunc: wireguard.ReactivateAllClientConfigs,
})
if err != nil {
t.Fatalf("cannot create new user store: %s", err)
}
userStore.Empty()
if err != nil {
t.Fatalf("cannot empty user store")
}
s := scim.New(storage, userStore, "token", wireguard.DisableAllClientConfigs, wireguard.ReactivateAllClientConfigs)
s := scim.New(storage, userStore, "token")

l, err := net.Listen("tcp", wireguard.CONFIGMANAGER_URI)
if err != nil {
Expand Down Expand Up @@ -145,15 +149,19 @@ func TestSCIMCreateUserConnectionDeleteUserFlow(t *testing.T) {
func TestCreateUserConnectionSuspendUserFlow(t *testing.T) {
storage := &memorystorage.MockMemoryStorage{}

userStore, err := users.NewUserStore(storage, USERSTORE_MAX_USERS)
userStore, err := users.NewUserStoreWithHooks(storage, USERSTORE_MAX_USERS, users.UserHooks{
DisableFunc: wireguard.DisableAllClientConfigs,
DeleteFunc: wireguard.DeleteAllClientConfigs,
ReactivateFunc: wireguard.ReactivateAllClientConfigs,
})
if err != nil {
t.Fatalf("cannot create new user store: %s", err)
}
userStore.Empty()
if err != nil {
t.Fatalf("cannot empty user store")
}
s := scim.New(storage, userStore, "token", wireguard.DisableAllClientConfigs, wireguard.ReactivateAllClientConfigs)
s := scim.New(storage, userStore, "token")

l, err := net.Listen("tcp", wireguard.CONFIGMANAGER_URI)
if err != nil {
Expand Down Expand Up @@ -316,7 +324,16 @@ func TestCreateUserConnectionDeleteUserFlow(t *testing.T) {
// first create a new user
storage := &memorystorage.MockMemoryStorage{}

v := New(storage, &users.UserStore{})
userStore, err := users.NewUserStoreWithHooks(storage, USERSTORE_MAX_USERS, users.UserHooks{
DisableFunc: wireguard.DisableAllClientConfigs,
DeleteFunc: wireguard.DeleteAllClientConfigs,
ReactivateFunc: wireguard.ReactivateAllClientConfigs,
})
if err != nil {
t.Fatalf("cannot create new user store: %s", err)
}

v := New(storage, userStore)

err = v.UserStore.Empty()
if err != nil {
Expand Down Expand Up @@ -392,6 +409,12 @@ func TestCreateUserConnectionDeleteUserFlow(t *testing.T) {
t.Fatalf("user deletion error: %s", err)
}

err = v.UserStore.UserHooks.DeleteFunc(v.Storage, users.User{ID: user.ID})
if err != nil {
t.Fatalf("could not delete all clients for user %s: %s", user.ID, err)

}

_, err = storage.ReadFile(userConfigFilename)
if err == nil {
t.Fatalf("could read user config file, expected not to")
Expand Down
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build && cp -r dist/* ../pkg/rest/static",
"build": "tsc && vite build && cp -r dist/* ../cmd/rest-server/static",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"test": "vitest"
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/Routes/Logs/Logs.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Card, Container, Text, Table, Title, Button, Grid, Popover, Group, TextInput, rem, ActionIcon, Checkbox, Highlight, MultiSelect} from "@mantine/core";
import { Container, Table, Title, Button, Grid, Popover, Group, TextInput, rem, ActionIcon, Checkbox, Highlight} from "@mantine/core";
import { AppSettings } from "../../Constants/Constants";
import { useInfiniteQuery } from "@tanstack/react-query";
import { useAuthContext } from "../../Auth/Auth";
import { Link, useSearchParams } from "react-router-dom";
import { TbArrowRight, TbSearch, TbSettings } from "react-icons/tb";
import { useSearchParams } from "react-router-dom";
import { TbArrowRight, TbSearch } from "react-icons/tb";
import { DatePickerInput } from "@mantine/dates";
import { useEffect, useState } from "react";
import React from "react";
Expand Down

0 comments on commit d3ac251

Please sign in to comment.