Skip to content

Commit e452ddb

Browse files
cleaned up the changes
1 parent bea0595 commit e452ddb

6 files changed

Lines changed: 136 additions & 84 deletions

File tree

tags/tagsbun/apply_postgres_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package tagsbun_test
66
import (
77
"context"
88
"database/sql"
9-
"os"
109
"testing"
1110
"time"
1211

@@ -20,16 +19,9 @@ import (
2019
)
2120

2221
func WithPostgres(t *testing.T) *bun.DB {
23-
dbName := "test"
24-
dbUser := "test"
25-
dbPassword := "test"
26-
2722
postgresC, err := postgres.Run(
2823
t.Context(),
2924
"postgres:18-alpine",
30-
postgres.WithDatabase(dbName),
31-
postgres.WithUsername(dbUser),
32-
postgres.WithPassword(dbPassword),
3325
testcontainers.WithWaitStrategy(
3426
wait.ForLog("database system is ready to accept connections").
3527
WithOccurrence(2).
@@ -63,10 +55,6 @@ func TestTagsExprToWherePostgres(t *testing.T) {
6355
if testing.Short() {
6456
t.Skip("skipping tests that require testcontainers.")
6557
}
66-
// Skip on Windows where Docker/rootless containers may not be available
67-
if os.Getenv("SKIP_DOCKER_TESTS") != "" {
68-
t.Skip("skipping Docker tests (SKIP_DOCKER_TESTS set)")
69-
}
7058

7159
runTests(t, WithPostgres(t))
7260
}

ui/tui/maintest/main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ import (
88
"os"
99

1010
tui "github.com/toeirei/keymaster/ui/tui"
11-
"github.com/toeirei/keymaster/uiadapters"
1211
)
1312

1413
func main() {
15-
// Use the store adapter for the test TUI
16-
store := uiadapters.NewStoreAdapter()
17-
if err := tui.Run(store); err != nil {
14+
if err := tui.Run(); err != nil {
1815
fmt.Println(err)
1916
os.Exit(1)
2017
}

ui/tui/tui.go

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,51 @@
44
package tui
55

66
import (
7+
"context"
8+
"time"
9+
710
tea "github.com/charmbracelet/bubbletea"
11+
"github.com/toeirei/keymaster/client"
12+
"github.com/toeirei/keymaster/client/mock"
13+
"github.com/toeirei/keymaster/client/testui"
14+
"github.com/toeirei/keymaster/tags"
815
"github.com/toeirei/keymaster/ui/tui/views/root"
916
)
1017

11-
func Run(store interface{}) error {
12-
_, err := tea.NewProgram(
13-
root.New(store),
14-
tea.WithAltScreen(),
15-
// tea.WithMouseCellMotion(),
16-
).Run()
18+
func Run() error {
19+
c := client.Client(testui.NewClient())
20+
21+
// test accounts
22+
_, _ = c.CreateAccount(context.Background(), "root", "1.2.3.4", 22, "ssh", "password123")
23+
_, _ = c.CreateAccount(context.Background(), "user", "1.2.3.4", 22, "ssh", "password123")
24+
_, _ = c.CreateAccount(context.Background(), "srv", "10.0.0.1", 22, "ssh", "password123")
25+
_, _ = c.CreateAccount(context.Background(), "mark", "1.2.3.4", 22, "ssh", "password123")
26+
_, _ = c.CreateAccount(context.Background(), "admin", "10.20.0.1", 222, "cisco", "password123")
27+
// test publicKeys
28+
_, _ = c.CreatePublicKey(context.Background(), "Sha-your-mom ashtdjhk-fbaskjdfhal_sdvkhaösdljhask-zdpjwb", "my-key", tags.Tags{"user:jannes", "company:work", "server-ci"})
29+
_, _ = c.CreatePublicKey(context.Background(), "Sha-your-mom ashtdjhk-fbaskjdfhal_sdvkhaösdljhask-öutyfb", "my-key", tags.Tags{"user:jannes", "company:none"})
30+
_, _ = c.CreatePublicKey(context.Background(), "Sha-420 asdjhk-fbaskdasral_jklkhathrösdljhask-fdjfb", "419", tags.Tags{"user:toeirei", "company:big_money"})
31+
_, _ = c.CreatePublicKey(context.Background(), "Sha-420 asdjhk-fbaskjdfhal_sdvtzuthrösdljhaha-ögjfb", "420", tags.Tags{"user:toeirei", "company:work", "server-ci"})
32+
_, _ = c.CreatePublicKey(context.Background(), "Sha-420 asdjhk-fbaskjterhl_sdvkhaghdjfdljhask-ödhfb", "421", tags.Tags{"user:toeirei", "company:none"})
33+
_, _ = c.CreatePublicKey(context.Background(), "Sha-69 asdjkhk-fbdfhtdftrhhal_sdvkhaösu656zsk-ödjhtfb", "69", tags.Tags{"user:somebodyelse", "company:evilgoogle", "server-ci"})
34+
// test links
35+
_, _ = c.CreateLink(context.Background(), 1, "(user:jannes | user:toeirei) & !company:work", time.Now().Add(time.Hour))
36+
_, _ = c.CreateLink(context.Background(), 2, "!user:somebodyelse", time.Now().Add(time.Hour))
37+
_, _ = c.CreateLink(context.Background(), 3, "server-ci", time.Now().Add(time.Hour))
38+
_, _ = c.CreateLink(context.Background(), 4, "company:evilgoogle", time.Now().Add(time.Hour))
39+
_, _ = c.CreateLink(context.Background(), 5, "company:work", time.Now().Add(time.Hour))
40+
_, _ = c.CreateLink(context.Background(), 5, "company:big_money", time.Now())
41+
42+
// add delay "middleware"
43+
c = mock.NewClient(mock.WitchBaseClient(c), mock.WitchPre(func(method string, args map[string]any) error {
44+
time.Sleep(time.Millisecond * 100)
45+
if ctx, ok := args["ctx"].(context.Context); ok {
46+
return ctx.Err()
47+
}
48+
return nil
49+
}))
50+
51+
// create and run tea programm
52+
_, err := tea.NewProgram(root.New(c), tea.WithAltScreen()).Run()
1753
return err
1854
}

ui/tui/views/content/content.go

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ import (
1212
"github.com/charmbracelet/bubbles/help"
1313
tea "github.com/charmbracelet/bubbletea"
1414
"github.com/toeirei/keymaster/client"
15-
"github.com/toeirei/keymaster/client/mock"
16-
"github.com/toeirei/keymaster/client/testui"
17-
"github.com/toeirei/keymaster/tags"
1815
"github.com/toeirei/keymaster/ui/tui/components/menu"
1916
"github.com/toeirei/keymaster/ui/tui/components/router"
2017
"github.com/toeirei/keymaster/ui/tui/components/stack"
@@ -35,48 +32,16 @@ type Model struct {
3532
router *util.Model
3633
routerControll router.Controll
3734
client client.Client
38-
store interface{}
3935
}
4036

41-
func New(storeParam interface{}) *Model {
37+
func New(c client.Client) *Model {
4238
// stack {
4339
// menu
4440
// router {
4541
// dashboard
4642
// }
4743
// }
4844

49-
c := client.Client(testui.NewClient())
50-
51-
// test accounts
52-
_, _ = c.CreateAccount(context.Background(), "root", "1.2.3.4", 22, "ssh", "password123")
53-
_, _ = c.CreateAccount(context.Background(), "user", "1.2.3.4", 22, "ssh", "password123")
54-
_, _ = c.CreateAccount(context.Background(), "srv", "10.0.0.1", 22, "ssh", "password123")
55-
_, _ = c.CreateAccount(context.Background(), "mark", "1.2.3.4", 22, "ssh", "password123")
56-
_, _ = c.CreateAccount(context.Background(), "admin", "10.20.0.1", 222, "cisco", "password123")
57-
// test publicKeys
58-
_, _ = c.CreatePublicKey(context.Background(), "Sha-your-mom ashtdjhk-fbaskjdfhal_sdvkhaösdljhask-zdpjwb", "my-key", tags.Tags{"user:jannes", "company:work", "server-ci"})
59-
_, _ = c.CreatePublicKey(context.Background(), "Sha-your-mom ashtdjhk-fbaskjdfhal_sdvkhaösdljhask-öutyfb", "my-key", tags.Tags{"user:jannes", "company:none"})
60-
_, _ = c.CreatePublicKey(context.Background(), "Sha-420 asdjhk-fbaskdasral_jklkhathrösdljhask-fdjfb", "419", tags.Tags{"user:toeirei", "company:big_money"})
61-
_, _ = c.CreatePublicKey(context.Background(), "Sha-420 asdjhk-fbaskjdfhal_sdvtzuthrösdljhaha-ögjfb", "420", tags.Tags{"user:toeirei", "company:work", "server-ci"})
62-
_, _ = c.CreatePublicKey(context.Background(), "Sha-420 asdjhk-fbaskjterhl_sdvkhaghdjfdljhask-ödhfb", "421", tags.Tags{"user:toeirei", "company:none"})
63-
_, _ = c.CreatePublicKey(context.Background(), "Sha-69 asdjkhk-fbdfhtdftrhhal_sdvkhaösu656zsk-ödjhtfb", "69", tags.Tags{"user:somebodyelse", "company:evilgoogle", "server-ci"})
64-
// test links
65-
_, _ = c.CreateLink(context.Background(), 1, "(user:jannes | user:toeirei) & !company:work", time.Now().Add(time.Hour))
66-
_, _ = c.CreateLink(context.Background(), 2, "!user:somebodyelse", time.Now().Add(time.Hour))
67-
_, _ = c.CreateLink(context.Background(), 3, "server-ci", time.Now().Add(time.Hour))
68-
_, _ = c.CreateLink(context.Background(), 4, "company:evilgoogle", time.Now().Add(time.Hour))
69-
_, _ = c.CreateLink(context.Background(), 5, "company:work", time.Now().Add(time.Hour))
70-
_, _ = c.CreateLink(context.Background(), 5, "company:big_money", time.Now())
71-
72-
c = mock.NewClient(mock.WitchBaseClient(c), mock.WitchPre(func(method string, args map[string]any) error {
73-
time.Sleep(time.Millisecond * 100)
74-
if ctx, ok := args["ctx"].(context.Context); ok {
75-
return ctx.Err()
76-
}
77-
return nil
78-
}))
79-
8045
menuPtr := util.ModelPointer(menu.New(
8146
menu.WithItem("dashboard.show", "Dashboard"),
8247
menu.WithItem("publickey.list", "Public Keys"),
@@ -95,7 +60,7 @@ func New(storeParam interface{}) *Model {
9560
),
9661
),
9762
))
98-
dashboardPtr := util.ModelPointer(dashboard.New(storeParam))
63+
dashboardPtr := util.ModelPointer(dashboard.New(c))
9964
routerModel, routerControll := router.New(dashboardPtr)
10065
routerPtr := util.ModelPointer(routerModel)
10166
stackModel := stack.New(
@@ -110,7 +75,6 @@ func New(storeParam interface{}) *Model {
11075
router: routerPtr,
11176
routerControll: routerControll,
11277
client: c,
113-
store: storeParam,
11478
}
11579
}
11680

@@ -123,7 +87,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
12387
if msg, ok := msg.(menu.ItemSelected); ok {
12488
switch msg.Id {
12589
case "dashboard.show":
126-
return m.routerControll.Change(util.ModelPointer(dashboard.New(m.store)))
90+
return m.routerControll.Change(util.ModelPointer(dashboard.New(m.client)))
12791

12892
case "publickey.list":
12993
return publickey.NewCrud(m.client, m.routerControll).OpenList()

0 commit comments

Comments
 (0)