hst/dbus: move dbus config struct
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m11s
Test / Hakurei (push) Successful in 3m12s
Test / Hpkg (push) Successful in 4m0s
Test / Hakurei (race detector) (push) Successful in 5m20s
Test / Sandbox (race detector) (push) Successful in 2m11s
Test / Flake checks (push) Successful in 1m31s
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m11s
Test / Hakurei (push) Successful in 3m12s
Test / Hpkg (push) Successful in 4m0s
Test / Hakurei (race detector) (push) Successful in 5m20s
Test / Sandbox (race detector) (push) Successful in 2m11s
Test / Flake checks (push) Successful in 1m31s
This allows holding a xdg-dbus-proxy configuration without importing system/dbus. It also makes more sense in the project structure since the config struct is part of the hst API however the rest of the implementation is not. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -1,26 +1,24 @@
|
||||
package dbus_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/system/dbus"
|
||||
)
|
||||
|
||||
func TestConfig_Args(t *testing.T) {
|
||||
for _, tc := range makeTestCases() {
|
||||
for _, tc := range testCasesExt {
|
||||
if tc.wantErr {
|
||||
// args does not check for nulls
|
||||
continue
|
||||
}
|
||||
|
||||
t.Run("build arguments for "+tc.id, func(t *testing.T) {
|
||||
if got := tc.c.Args(tc.bus); !slices.Equal(got, tc.want) {
|
||||
if got := dbus.Args(tc.c, tc.bus); !slices.Equal(got, tc.want) {
|
||||
t.Errorf("Args(%q) = %v, want %v",
|
||||
tc.bus,
|
||||
got, tc.want)
|
||||
@@ -29,74 +27,36 @@ func TestConfig_Args(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewConfigFromFile(t *testing.T) {
|
||||
for _, tc := range makeTestCases() {
|
||||
name := new(strings.Builder)
|
||||
name.WriteString("parse configuration file for application ")
|
||||
name.WriteString(tc.id)
|
||||
if tc.wantErr {
|
||||
name.WriteString(" with unexpected results")
|
||||
}
|
||||
|
||||
samplePath := path.Join("testdata", tc.id+".json")
|
||||
|
||||
t.Run(name.String(), func(t *testing.T) {
|
||||
got, err := dbus.NewConfigFromFile(samplePath)
|
||||
if errors.Is(err, os.ErrNotExist) != tc.wantErrF {
|
||||
t.Errorf("NewConfigFromFile(%q) error = %v, wantErrF %v",
|
||||
samplePath,
|
||||
err, tc.wantErrF)
|
||||
return
|
||||
}
|
||||
|
||||
if tc.wantErrF {
|
||||
return
|
||||
}
|
||||
|
||||
if !tc.wantErr && !reflect.DeepEqual(got, tc.c) {
|
||||
t.Errorf("NewConfigFromFile(%q) got = %v, want %v",
|
||||
samplePath,
|
||||
got, tc.c)
|
||||
}
|
||||
if tc.wantErr && reflect.DeepEqual(got, tc.c) {
|
||||
t.Errorf("NewConfigFromFile(%q) got = %v, wantErr %v",
|
||||
samplePath,
|
||||
got, tc.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewConfig(t *testing.T) {
|
||||
ids := [...]string{"org.chromium.Chromium", "dev.vencord.Vesktop"}
|
||||
|
||||
type newTestCase struct {
|
||||
id string
|
||||
args [2]bool
|
||||
want *dbus.Config
|
||||
want *hst.BusConfig
|
||||
}
|
||||
|
||||
// populate tests from IDs in generic tests
|
||||
tcs := make([]newTestCase, 0, (len(ids)+1)*4)
|
||||
// tests for defaults without id
|
||||
tcs = append(tcs,
|
||||
newTestCase{"", [2]bool{false, false}, &dbus.Config{
|
||||
newTestCase{"", [2]bool{false, false}, &hst.BusConfig{
|
||||
Call: make(map[string]string),
|
||||
Broadcast: make(map[string]string),
|
||||
Filter: true,
|
||||
}},
|
||||
newTestCase{"", [2]bool{false, true}, &dbus.Config{
|
||||
newTestCase{"", [2]bool{false, true}, &hst.BusConfig{
|
||||
Call: make(map[string]string),
|
||||
Broadcast: make(map[string]string),
|
||||
Filter: true,
|
||||
}},
|
||||
newTestCase{"", [2]bool{true, false}, &dbus.Config{
|
||||
newTestCase{"", [2]bool{true, false}, &hst.BusConfig{
|
||||
Talk: []string{"org.freedesktop.DBus", "org.freedesktop.Notifications"},
|
||||
Call: map[string]string{"org.freedesktop.portal.*": "*"},
|
||||
Broadcast: map[string]string{"org.freedesktop.portal.*": "@/org/freedesktop/portal/*"},
|
||||
Filter: true,
|
||||
}},
|
||||
newTestCase{"", [2]bool{true, true}, &dbus.Config{
|
||||
newTestCase{"", [2]bool{true, true}, &hst.BusConfig{
|
||||
Talk: []string{"org.freedesktop.DBus", "org.freedesktop.Notifications"},
|
||||
Call: map[string]string{"org.freedesktop.portal.*": "*"},
|
||||
Broadcast: map[string]string{"org.freedesktop.portal.*": "@/org/freedesktop/portal/*"},
|
||||
@@ -105,24 +65,24 @@ func TestNewConfig(t *testing.T) {
|
||||
)
|
||||
for _, id := range ids {
|
||||
tcs = append(tcs,
|
||||
newTestCase{id, [2]bool{false, false}, &dbus.Config{
|
||||
newTestCase{id, [2]bool{false, false}, &hst.BusConfig{
|
||||
Call: make(map[string]string),
|
||||
Broadcast: make(map[string]string),
|
||||
Filter: true,
|
||||
}},
|
||||
newTestCase{id, [2]bool{false, true}, &dbus.Config{
|
||||
newTestCase{id, [2]bool{false, true}, &hst.BusConfig{
|
||||
Call: make(map[string]string),
|
||||
Broadcast: make(map[string]string),
|
||||
Filter: true,
|
||||
}},
|
||||
newTestCase{id, [2]bool{true, false}, &dbus.Config{
|
||||
newTestCase{id, [2]bool{true, false}, &hst.BusConfig{
|
||||
Talk: []string{"org.freedesktop.DBus", "org.freedesktop.Notifications"},
|
||||
Own: []string{id + ".*"},
|
||||
Call: map[string]string{"org.freedesktop.portal.*": "*"},
|
||||
Broadcast: map[string]string{"org.freedesktop.portal.*": "@/org/freedesktop/portal/*"},
|
||||
Filter: true,
|
||||
}},
|
||||
newTestCase{id, [2]bool{true, true}, &dbus.Config{
|
||||
newTestCase{id, [2]bool{true, true}, &hst.BusConfig{
|
||||
Talk: []string{"org.freedesktop.DBus", "org.freedesktop.Notifications"},
|
||||
Own: []string{id + ".*", "org.mpris.MediaPlayer2." + id + ".*"},
|
||||
Call: map[string]string{"org.freedesktop.portal.*": "*"},
|
||||
|
||||
Reference in New Issue
Block a user