fixup! wip: refactor: API
This commit is contained in:
parent
7706bb363f
commit
aa6f50715d
@ -9,7 +9,6 @@ import (
|
||||
|
||||
"git.netflux.io/rob/octoplex/internal/client"
|
||||
"git.netflux.io/rob/octoplex/internal/domain"
|
||||
"git.netflux.io/rob/octoplex/internal/event"
|
||||
"golang.design/x/clipboard"
|
||||
)
|
||||
|
||||
@ -53,7 +52,6 @@ func run() error {
|
||||
}
|
||||
|
||||
app := client.NewApp(
|
||||
event.NewBus(logger),
|
||||
clipboardAvailable,
|
||||
domain.BuildInfo{
|
||||
GoVersion: buildInfo.GoVersion,
|
||||
@ -61,6 +59,7 @@ func run() error {
|
||||
Commit: commit,
|
||||
Date: date,
|
||||
},
|
||||
nil,
|
||||
logger,
|
||||
)
|
||||
|
||||
|
@ -43,7 +43,6 @@ type Params struct {
|
||||
ConfigService *config.Service
|
||||
DockerClient container.DockerClient
|
||||
ChanSize int
|
||||
Screen *terminal.Screen // Screen may be nil.
|
||||
ClipboardAvailable bool
|
||||
ConfigFilePath string
|
||||
BuildInfo domain.BuildInfo
|
||||
@ -61,7 +60,6 @@ func New(params Params) *App {
|
||||
eventBus: event.NewBus(params.Logger.With("component", "event_bus")),
|
||||
dispatchC: make(chan event.Command, cmp.Or(params.ChanSize, defaultChanSize)),
|
||||
dockerClient: params.DockerClient,
|
||||
screen: params.Screen,
|
||||
clipboardAvailable: params.ClipboardAvailable,
|
||||
configFilePath: params.ConfigFilePath,
|
||||
buildInfo: params.BuildInfo,
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.netflux.io/rob/octoplex/internal/app"
|
||||
"git.netflux.io/rob/octoplex/internal/client"
|
||||
"git.netflux.io/rob/octoplex/internal/config"
|
||||
"git.netflux.io/rob/octoplex/internal/container"
|
||||
"git.netflux.io/rob/octoplex/internal/domain"
|
||||
@ -35,14 +36,8 @@ func buildAppParams(
|
||||
t.Helper()
|
||||
|
||||
return app.Params{
|
||||
ConfigService: configService,
|
||||
DockerClient: dockerClient,
|
||||
Screen: &terminal.Screen{
|
||||
Screen: screen,
|
||||
Width: 180,
|
||||
Height: 25,
|
||||
CaptureC: screenCaptureC,
|
||||
},
|
||||
ConfigService: configService,
|
||||
DockerClient: dockerClient,
|
||||
ClipboardAvailable: false,
|
||||
BuildInfo: domain.BuildInfo{Version: "0.0.1", GoVersion: "go1.16.3"},
|
||||
Logger: logger,
|
||||
@ -50,9 +45,35 @@ func buildAppParams(
|
||||
}
|
||||
|
||||
func buildClientServer(
|
||||
t *testing.T,
|
||||
configService *config.Service,
|
||||
dockerClient container.DockerClient,
|
||||
screen tcell.SimulationScreen,
|
||||
screenCaptureC chan<- terminal.ScreenCapture,
|
||||
logger *slog.Logger,
|
||||
) (*client.App, *app.App) {
|
||||
buildInfo := domain.BuildInfo{Version: "0.0.1", GoVersion: "go1.16.3"}
|
||||
clientApp := client.NewApp(
|
||||
false,
|
||||
buildInfo,
|
||||
&terminal.Screen{
|
||||
Screen: screen,
|
||||
Width: 160,
|
||||
Height: 25,
|
||||
CaptureC: screenCaptureC,
|
||||
},
|
||||
logger,
|
||||
)
|
||||
|
||||
// TODO: use buildAppParams
|
||||
srvApp := app.New(app.Params{
|
||||
ConfigService: configService,
|
||||
DockerClient: dockerClient,
|
||||
ClipboardAvailable: false,
|
||||
BuildInfo: buildInfo,
|
||||
Logger: logger,
|
||||
})
|
||||
|
||||
return clientApp, srvApp
|
||||
}
|
||||
|
||||
func setupSimulationScreen(t *testing.T) (tcell.SimulationScreen, chan<- terminal.ScreenCapture, func() []string) {
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -20,7 +21,6 @@ import (
|
||||
"git.netflux.io/rob/octoplex/internal/container"
|
||||
"git.netflux.io/rob/octoplex/internal/container/mocks"
|
||||
"git.netflux.io/rob/octoplex/internal/domain"
|
||||
"git.netflux.io/rob/octoplex/internal/terminal"
|
||||
"git.netflux.io/rob/octoplex/internal/testhelpers"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
dockerclient "github.com/docker/docker/client"
|
||||
@ -126,25 +126,19 @@ func testIntegration(t *testing.T, mediaServerConfig config.MediaServerSource) {
|
||||
Destinations: []config.Destination{{Name: "Local server 1", URL: destURL1}},
|
||||
})
|
||||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer func() {
|
||||
done <- struct{}{}
|
||||
}()
|
||||
client, server := buildClientServer(configService, dockerClient, screen, screenCaptureC, logger)
|
||||
var wg sync.WaitGroup
|
||||
|
||||
require.Equal(t, context.Canceled, app.New(app.Params{
|
||||
ConfigService: configService,
|
||||
DockerClient: dockerClient,
|
||||
Screen: &terminal.Screen{
|
||||
Screen: screen,
|
||||
Width: 160,
|
||||
Height: 25,
|
||||
CaptureC: screenCaptureC,
|
||||
},
|
||||
ClipboardAvailable: false,
|
||||
BuildInfo: domain.BuildInfo{Version: "0.0.1", GoVersion: "go1.16.3"},
|
||||
Logger: logger,
|
||||
}).Run(ctx))
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
assert.NoError(t, client.Run(ctx))
|
||||
}()
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
assert.NoError(t, server.Run(ctx))
|
||||
}()
|
||||
|
||||
require.EventuallyWithT(
|
||||
@ -286,13 +280,9 @@ func testIntegration(t *testing.T, mediaServerConfig config.MediaServerSource) {
|
||||
|
||||
printScreen(t, getContents, "After stopping the first destination")
|
||||
|
||||
// TODO:
|
||||
// - Source error
|
||||
// - Additional features (copy URL, etc.)
|
||||
|
||||
cancel()
|
||||
|
||||
<-done
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestIntegrationCustomHost(t *testing.T) {
|
||||
|
@ -15,27 +15,33 @@ import (
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
// App is the client application.
|
||||
type App struct {
|
||||
bus *event.Bus
|
||||
clipboardAvailable bool
|
||||
buildInfo domain.BuildInfo
|
||||
screen *terminal.Screen
|
||||
logger *slog.Logger
|
||||
}
|
||||
|
||||
// NewApp creates a new App instance.
|
||||
//
|
||||
// TODO: params
|
||||
func NewApp(
|
||||
bus *event.Bus,
|
||||
clipboardAvailable bool,
|
||||
buildInfo domain.BuildInfo,
|
||||
screen *terminal.Screen,
|
||||
logger *slog.Logger,
|
||||
) *App {
|
||||
return &App{
|
||||
bus: bus,
|
||||
bus: event.NewBus(logger),
|
||||
clipboardAvailable: clipboardAvailable,
|
||||
buildInfo: buildInfo,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// Run starts the application, and blocks until it is closed.
|
||||
func (a *App) Run(ctx context.Context) error {
|
||||
g, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
@ -77,6 +83,7 @@ func (a *App) Run(ctx context.Context) error {
|
||||
},
|
||||
ClipboardAvailable: a.clipboardAvailable,
|
||||
BuildInfo: a.buildInfo,
|
||||
Screen: a.screen,
|
||||
Logger: a.logger.With("component", "ui"),
|
||||
})
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user