aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/dbus/config_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-07 19:01:18 +0900
committerOphestra <cat@gensokyo.uk>2025-10-07 19:03:51 +0900
commitd23b4dc9e64d3f00e746c65f3038a1a6de44b8f5 (patch)
tree46e7f73bc2b06047561588294759ddb8a71184f2 /system/dbus/config_test.go
parent3ce63e95d7691450f7b368e639d984a223a764b1 (diff)
hst/dbus: move dbus config struct
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>
Diffstat (limited to 'system/dbus/config_test.go')
-rw-r--r--system/dbus/config_test.go64
1 files changed, 12 insertions, 52 deletions
diff --git a/system/dbus/config_test.go b/system/dbus/config_test.go
index 0fe93303..9a0e570e 100644
--- a/system/dbus/config_test.go
+++ b/system/dbus/config_test.go
@@ -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.*": "*"},