mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-06 05:25:41 -05:00
core: ensure all NM tests use mock backend + re-orgs + dep updates
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/hyprland"
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/keybinds"
|
||||
)
|
||||
|
||||
@@ -26,7 +25,7 @@ func (h *HyprlandProvider) Name() string {
|
||||
}
|
||||
|
||||
func (h *HyprlandProvider) GetCheatSheet() (*keybinds.CheatSheet, error) {
|
||||
section, err := hyprland.ParseKeys(h.configPath)
|
||||
section, err := ParseHyprlandKeys(h.configPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse hyprland config: %w", err)
|
||||
}
|
||||
@@ -41,7 +40,7 @@ func (h *HyprlandProvider) GetCheatSheet() (*keybinds.CheatSheet, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (h *HyprlandProvider) convertSection(section *hyprland.Section, subcategory string, categorizedBinds map[string][]keybinds.Keybind) {
|
||||
func (h *HyprlandProvider) convertSection(section *HyprlandSection, subcategory string, categorizedBinds map[string][]keybinds.Keybind) {
|
||||
currentSubcat := subcategory
|
||||
if section.Name != "" {
|
||||
currentSubcat = section.Name
|
||||
@@ -86,7 +85,7 @@ func (h *HyprlandProvider) categorizeByDispatcher(dispatcher string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HyprlandProvider) convertKeybind(kb *hyprland.KeyBinding, subcategory string) keybinds.Keybind {
|
||||
func (h *HyprlandProvider) convertKeybind(kb *HyprlandKeyBinding, subcategory string) keybinds.Keybind {
|
||||
key := h.formatKey(kb)
|
||||
desc := kb.Comment
|
||||
|
||||
@@ -108,7 +107,7 @@ func (h *HyprlandProvider) generateDescription(dispatcher, params string) string
|
||||
return dispatcher
|
||||
}
|
||||
|
||||
func (h *HyprlandProvider) formatKey(kb *hyprland.KeyBinding) string {
|
||||
func (h *HyprlandProvider) formatKey(kb *HyprlandKeyBinding) string {
|
||||
parts := make([]string, 0, len(kb.Mods)+1)
|
||||
parts = append(parts, kb.Mods...)
|
||||
parts = append(parts, kb.Key)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hyprland
|
||||
package providers
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -15,7 +15,7 @@ const (
|
||||
|
||||
var ModSeparators = []rune{'+', ' '}
|
||||
|
||||
type KeyBinding struct {
|
||||
type HyprlandKeyBinding struct {
|
||||
Mods []string `json:"mods"`
|
||||
Key string `json:"key"`
|
||||
Dispatcher string `json:"dispatcher"`
|
||||
@@ -23,25 +23,25 @@ type KeyBinding struct {
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
|
||||
type Section struct {
|
||||
Children []Section `json:"children"`
|
||||
Keybinds []KeyBinding `json:"keybinds"`
|
||||
Name string `json:"name"`
|
||||
type HyprlandSection struct {
|
||||
Children []HyprlandSection `json:"children"`
|
||||
Keybinds []HyprlandKeyBinding `json:"keybinds"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Parser struct {
|
||||
type HyprlandParser struct {
|
||||
contentLines []string
|
||||
readingLine int
|
||||
}
|
||||
|
||||
func NewParser() *Parser {
|
||||
return &Parser{
|
||||
func NewHyprlandParser() *HyprlandParser {
|
||||
return &HyprlandParser{
|
||||
contentLines: []string{},
|
||||
readingLine: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) ReadContent(directory string) error {
|
||||
func (p *HyprlandParser) ReadContent(directory string) error {
|
||||
expandedDir := os.ExpandEnv(directory)
|
||||
expandedDir = filepath.Clean(expandedDir)
|
||||
if strings.HasPrefix(expandedDir, "~") {
|
||||
@@ -87,7 +87,7 @@ func (p *Parser) ReadContent(directory string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func autogenerateComment(dispatcher, params string) string {
|
||||
func hyprlandAutogenerateComment(dispatcher, params string) string {
|
||||
switch dispatcher {
|
||||
case "resizewindow":
|
||||
return "Resize window"
|
||||
@@ -196,7 +196,7 @@ func autogenerateComment(dispatcher, params string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
func (p *HyprlandParser) getKeybindAtLine(lineNumber int) *HyprlandKeyBinding {
|
||||
line := p.contentLines[lineNumber]
|
||||
parts := strings.SplitN(line, "=", 2)
|
||||
if len(parts) < 2 {
|
||||
@@ -232,7 +232,7 @@ func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
comment = autogenerateComment(dispatcher, params)
|
||||
comment = hyprlandAutogenerateComment(dispatcher, params)
|
||||
}
|
||||
|
||||
var modList []string
|
||||
@@ -256,7 +256,7 @@ func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
}
|
||||
}
|
||||
|
||||
return &KeyBinding{
|
||||
return &HyprlandKeyBinding{
|
||||
Mods: modList,
|
||||
Key: key,
|
||||
Dispatcher: dispatcher,
|
||||
@@ -265,7 +265,7 @@ func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) getBindsRecursive(currentContent *Section, scope int) *Section {
|
||||
func (p *HyprlandParser) getBindsRecursive(currentContent *HyprlandSection, scope int) *HyprlandSection {
|
||||
titleRegex := regexp.MustCompile(TitleRegex)
|
||||
|
||||
for p.readingLine < len(p.contentLines) {
|
||||
@@ -283,9 +283,9 @@ func (p *Parser) getBindsRecursive(currentContent *Section, scope int) *Section
|
||||
sectionName := strings.TrimSpace(line[headingScope+1:])
|
||||
p.readingLine++
|
||||
|
||||
childSection := &Section{
|
||||
Children: []Section{},
|
||||
Keybinds: []KeyBinding{},
|
||||
childSection := &HyprlandSection{
|
||||
Children: []HyprlandSection{},
|
||||
Keybinds: []HyprlandKeyBinding{},
|
||||
Name: sectionName,
|
||||
}
|
||||
result := p.getBindsRecursive(childSection, headingScope)
|
||||
@@ -312,18 +312,18 @@ func (p *Parser) getBindsRecursive(currentContent *Section, scope int) *Section
|
||||
return currentContent
|
||||
}
|
||||
|
||||
func (p *Parser) ParseKeys() *Section {
|
||||
func (p *HyprlandParser) ParseKeys() *HyprlandSection {
|
||||
p.readingLine = 0
|
||||
rootSection := &Section{
|
||||
Children: []Section{},
|
||||
Keybinds: []KeyBinding{},
|
||||
rootSection := &HyprlandSection{
|
||||
Children: []HyprlandSection{},
|
||||
Keybinds: []HyprlandKeyBinding{},
|
||||
Name: "",
|
||||
}
|
||||
return p.getBindsRecursive(rootSection, 0)
|
||||
}
|
||||
|
||||
func ParseKeys(path string) (*Section, error) {
|
||||
parser := NewParser()
|
||||
func ParseHyprlandKeys(path string) (*HyprlandSection, error) {
|
||||
parser := NewHyprlandParser()
|
||||
if err := parser.ReadContent(path); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package hyprland
|
||||
package providers
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAutogenerateComment(t *testing.T) {
|
||||
func TestHyprlandAutogenerateComment(t *testing.T) {
|
||||
tests := []struct {
|
||||
dispatcher string
|
||||
params string
|
||||
@@ -51,25 +51,25 @@ func TestAutogenerateComment(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.dispatcher+"_"+tt.params, func(t *testing.T) {
|
||||
result := autogenerateComment(tt.dispatcher, tt.params)
|
||||
result := hyprlandAutogenerateComment(tt.dispatcher, tt.params)
|
||||
if result != tt.expected {
|
||||
t.Errorf("autogenerateComment(%q, %q) = %q, want %q",
|
||||
t.Errorf("hyprlandAutogenerateComment(%q, %q) = %q, want %q",
|
||||
tt.dispatcher, tt.params, result, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetKeybindAtLine(t *testing.T) {
|
||||
func TestHyprlandGetKeybindAtLine(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
line string
|
||||
expected *KeyBinding
|
||||
expected *HyprlandKeyBinding
|
||||
}{
|
||||
{
|
||||
name: "basic_keybind",
|
||||
line: "bind = SUPER, Q, killactive",
|
||||
expected: &KeyBinding{
|
||||
expected: &HyprlandKeyBinding{
|
||||
Mods: []string{"SUPER"},
|
||||
Key: "Q",
|
||||
Dispatcher: "killactive",
|
||||
@@ -80,7 +80,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_with_params",
|
||||
line: "bind = SUPER, left, movefocus, l",
|
||||
expected: &KeyBinding{
|
||||
expected: &HyprlandKeyBinding{
|
||||
Mods: []string{"SUPER"},
|
||||
Key: "left",
|
||||
Dispatcher: "movefocus",
|
||||
@@ -91,7 +91,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_with_comment",
|
||||
line: "bind = SUPER, T, exec, kitty # Open terminal",
|
||||
expected: &KeyBinding{
|
||||
expected: &HyprlandKeyBinding{
|
||||
Mods: []string{"SUPER"},
|
||||
Key: "T",
|
||||
Dispatcher: "exec",
|
||||
@@ -107,7 +107,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_multiple_mods",
|
||||
line: "bind = SUPER+SHIFT, F, fullscreen, 0",
|
||||
expected: &KeyBinding{
|
||||
expected: &HyprlandKeyBinding{
|
||||
Mods: []string{"SUPER", "SHIFT"},
|
||||
Key: "F",
|
||||
Dispatcher: "fullscreen",
|
||||
@@ -118,7 +118,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_no_mods",
|
||||
line: "bind = , Print, exec, screenshot",
|
||||
expected: &KeyBinding{
|
||||
expected: &HyprlandKeyBinding{
|
||||
Mods: []string{},
|
||||
Key: "Print",
|
||||
Dispatcher: "exec",
|
||||
@@ -130,7 +130,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
parser := NewParser()
|
||||
parser := NewHyprlandParser()
|
||||
parser.contentLines = []string{tt.line}
|
||||
result := parser.getKeybindAtLine(0)
|
||||
|
||||
@@ -171,7 +171,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseKeysWithSections(t *testing.T) {
|
||||
func TestHyprlandParseKeysWithSections(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
configFile := filepath.Join(tmpDir, "hyprland.conf")
|
||||
|
||||
@@ -191,9 +191,9 @@ bind = SUPER, T, exec, kitty # Terminal
|
||||
t.Fatalf("Failed to write test config: %v", err)
|
||||
}
|
||||
|
||||
section, err := ParseKeys(tmpDir)
|
||||
section, err := ParseHyprlandKeys(tmpDir)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseKeys failed: %v", err)
|
||||
t.Fatalf("ParseHyprlandKeys failed: %v", err)
|
||||
}
|
||||
|
||||
if len(section.Children) != 2 {
|
||||
@@ -236,7 +236,7 @@ bind = SUPER, T, exec, kitty # Terminal
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseKeysWithCommentBinds(t *testing.T) {
|
||||
func TestHyprlandParseKeysWithCommentBinds(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
configFile := filepath.Join(tmpDir, "test.conf")
|
||||
|
||||
@@ -249,9 +249,9 @@ bind = SUPER, B, exec, app2
|
||||
t.Fatalf("Failed to write test config: %v", err)
|
||||
}
|
||||
|
||||
section, err := ParseKeys(tmpDir)
|
||||
section, err := ParseHyprlandKeys(tmpDir)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseKeys failed: %v", err)
|
||||
t.Fatalf("ParseHyprlandKeys failed: %v", err)
|
||||
}
|
||||
|
||||
if len(section.Keybinds) != 3 {
|
||||
@@ -269,7 +269,7 @@ bind = SUPER, B, exec, app2
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadContentMultipleFiles(t *testing.T) {
|
||||
func TestHyprlandReadContentMultipleFiles(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
file1 := filepath.Join(tmpDir, "a.conf")
|
||||
@@ -285,7 +285,7 @@ func TestReadContentMultipleFiles(t *testing.T) {
|
||||
t.Fatalf("Failed to write file2: %v", err)
|
||||
}
|
||||
|
||||
parser := NewParser()
|
||||
parser := NewHyprlandParser()
|
||||
if err := parser.ReadContent(tmpDir); err != nil {
|
||||
t.Fatalf("ReadContent failed: %v", err)
|
||||
}
|
||||
@@ -296,7 +296,7 @@ func TestReadContentMultipleFiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadContentErrors(t *testing.T) {
|
||||
func TestHyprlandReadContentErrors(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
@@ -313,7 +313,7 @@ func TestReadContentErrors(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := ParseKeys(tt.path)
|
||||
_, err := ParseHyprlandKeys(tt.path)
|
||||
if err == nil {
|
||||
t.Error("Expected error, got nil")
|
||||
}
|
||||
@@ -321,7 +321,7 @@ func TestReadContentErrors(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadContentWithTildeExpansion(t *testing.T) {
|
||||
func TestHyprlandReadContentWithTildeExpansion(t *testing.T) {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Skip("Cannot get home directory")
|
||||
@@ -343,7 +343,7 @@ func TestReadContentWithTildeExpansion(t *testing.T) {
|
||||
t.Skip("Cannot create relative path")
|
||||
}
|
||||
|
||||
parser := NewParser()
|
||||
parser := NewHyprlandParser()
|
||||
tildePathMatch := "~/" + relPath
|
||||
err = parser.ReadContent(tildePathMatch)
|
||||
|
||||
@@ -352,8 +352,8 @@ func TestReadContentWithTildeExpansion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestKeybindWithParamsContainingCommas(t *testing.T) {
|
||||
parser := NewParser()
|
||||
func TestHyprlandKeybindWithParamsContainingCommas(t *testing.T) {
|
||||
parser := NewHyprlandParser()
|
||||
parser.contentLines = []string{"bind = SUPER, R, exec, notify-send 'Title' 'Message, with comma'"}
|
||||
|
||||
result := parser.getKeybindAtLine(0)
|
||||
@@ -368,7 +368,7 @@ func TestKeybindWithParamsContainingCommas(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyAndCommentLines(t *testing.T) {
|
||||
func TestHyprlandEmptyAndCommentLines(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
configFile := filepath.Join(tmpDir, "test.conf")
|
||||
|
||||
@@ -385,9 +385,9 @@ bind = SUPER, T, exec, kitty
|
||||
t.Fatalf("Failed to write test config: %v", err)
|
||||
}
|
||||
|
||||
section, err := ParseKeys(tmpDir)
|
||||
section, err := ParseHyprlandKeys(tmpDir)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseKeys failed: %v", err)
|
||||
t.Fatalf("ParseHyprlandKeys failed: %v", err)
|
||||
}
|
||||
|
||||
if len(section.Keybinds) != 2 {
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/keybinds"
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/mangowc"
|
||||
)
|
||||
|
||||
type MangoWCProvider struct {
|
||||
@@ -26,7 +25,7 @@ func (m *MangoWCProvider) Name() string {
|
||||
}
|
||||
|
||||
func (m *MangoWCProvider) GetCheatSheet() (*keybinds.CheatSheet, error) {
|
||||
keybinds_list, err := mangowc.ParseKeys(m.configPath)
|
||||
keybinds_list, err := ParseMangoWCKeys(m.configPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse mangowc config: %w", err)
|
||||
}
|
||||
@@ -83,7 +82,7 @@ func (m *MangoWCProvider) categorizeByCommand(command string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MangoWCProvider) convertKeybind(kb *mangowc.KeyBinding) keybinds.Keybind {
|
||||
func (m *MangoWCProvider) convertKeybind(kb *MangoWCKeyBinding) keybinds.Keybind {
|
||||
key := m.formatKey(kb)
|
||||
desc := kb.Comment
|
||||
|
||||
@@ -104,7 +103,7 @@ func (m *MangoWCProvider) generateDescription(command, params string) string {
|
||||
return command
|
||||
}
|
||||
|
||||
func (m *MangoWCProvider) formatKey(kb *mangowc.KeyBinding) string {
|
||||
func (m *MangoWCProvider) formatKey(kb *MangoWCKeyBinding) string {
|
||||
parts := make([]string, 0, len(kb.Mods)+1)
|
||||
parts = append(parts, kb.Mods...)
|
||||
parts = append(parts, kb.Key)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package mangowc
|
||||
package providers
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
HideComment = "[hidden]"
|
||||
MangoWCHideComment = "[hidden]"
|
||||
)
|
||||
|
||||
var ModSeparators = []rune{'+', ' '}
|
||||
var MangoWCModSeparators = []rune{'+', ' '}
|
||||
|
||||
type KeyBinding struct {
|
||||
type MangoWCKeyBinding struct {
|
||||
Mods []string `json:"mods"`
|
||||
Key string `json:"key"`
|
||||
Command string `json:"command"`
|
||||
@@ -21,19 +21,19 @@ type KeyBinding struct {
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
|
||||
type Parser struct {
|
||||
type MangoWCParser struct {
|
||||
contentLines []string
|
||||
readingLine int
|
||||
}
|
||||
|
||||
func NewParser() *Parser {
|
||||
return &Parser{
|
||||
func NewMangoWCParser() *MangoWCParser {
|
||||
return &MangoWCParser{
|
||||
contentLines: []string{},
|
||||
readingLine: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) ReadContent(path string) error {
|
||||
func (p *MangoWCParser) ReadContent(path string) error {
|
||||
expandedPath := os.ExpandEnv(path)
|
||||
expandedPath = filepath.Clean(expandedPath)
|
||||
if strings.HasPrefix(expandedPath, "~") {
|
||||
@@ -82,7 +82,7 @@ func (p *Parser) ReadContent(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func autogenerateComment(command, params string) string {
|
||||
func mangowcAutogenerateComment(command, params string) string {
|
||||
switch command {
|
||||
case "spawn", "spawn_shell":
|
||||
return params
|
||||
@@ -196,7 +196,7 @@ func autogenerateComment(command, params string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
func (p *MangoWCParser) getKeybindAtLine(lineNumber int) *MangoWCKeyBinding {
|
||||
if lineNumber >= len(p.contentLines) {
|
||||
return nil
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
comment = strings.TrimSpace(parts[1])
|
||||
}
|
||||
|
||||
if strings.HasPrefix(comment, HideComment) {
|
||||
if strings.HasPrefix(comment, MangoWCHideComment) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -239,16 +239,16 @@ func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
}
|
||||
|
||||
if comment == "" {
|
||||
comment = autogenerateComment(command, params)
|
||||
comment = mangowcAutogenerateComment(command, params)
|
||||
}
|
||||
|
||||
var modList []string
|
||||
if mods != "" && !strings.EqualFold(mods, "none") {
|
||||
modstring := mods + string(ModSeparators[0])
|
||||
modstring := mods + string(MangoWCModSeparators[0])
|
||||
p := 0
|
||||
for index, char := range modstring {
|
||||
isModSep := false
|
||||
for _, sep := range ModSeparators {
|
||||
for _, sep := range MangoWCModSeparators {
|
||||
if char == sep {
|
||||
isModSep = true
|
||||
break
|
||||
@@ -265,7 +265,7 @@ func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
|
||||
_ = bindType
|
||||
|
||||
return &KeyBinding{
|
||||
return &MangoWCKeyBinding{
|
||||
Mods: modList,
|
||||
Key: key,
|
||||
Command: command,
|
||||
@@ -274,8 +274,8 @@ func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) ParseKeys() []KeyBinding {
|
||||
var keybinds []KeyBinding
|
||||
func (p *MangoWCParser) ParseKeys() []MangoWCKeyBinding {
|
||||
var keybinds []MangoWCKeyBinding
|
||||
|
||||
for lineNumber := 0; lineNumber < len(p.contentLines); lineNumber++ {
|
||||
line := p.contentLines[lineNumber]
|
||||
@@ -296,8 +296,8 @@ func (p *Parser) ParseKeys() []KeyBinding {
|
||||
return keybinds
|
||||
}
|
||||
|
||||
func ParseKeys(path string) ([]KeyBinding, error) {
|
||||
parser := NewParser()
|
||||
func ParseMangoWCKeys(path string) ([]MangoWCKeyBinding, error) {
|
||||
parser := NewMangoWCParser()
|
||||
if err := parser.ReadContent(path); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package mangowc
|
||||
package providers
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAutogenerateComment(t *testing.T) {
|
||||
func TestMangoWCAutogenerateComment(t *testing.T) {
|
||||
tests := []struct {
|
||||
command string
|
||||
params string
|
||||
@@ -60,25 +60,25 @@ func TestAutogenerateComment(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.command+"_"+tt.params, func(t *testing.T) {
|
||||
result := autogenerateComment(tt.command, tt.params)
|
||||
result := mangowcAutogenerateComment(tt.command, tt.params)
|
||||
if result != tt.expected {
|
||||
t.Errorf("autogenerateComment(%q, %q) = %q, want %q",
|
||||
t.Errorf("mangowcAutogenerateComment(%q, %q) = %q, want %q",
|
||||
tt.command, tt.params, result, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetKeybindAtLine(t *testing.T) {
|
||||
func TestMangoWCGetKeybindAtLine(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
line string
|
||||
expected *KeyBinding
|
||||
expected *MangoWCKeyBinding
|
||||
}{
|
||||
{
|
||||
name: "basic_keybind",
|
||||
line: "bind=ALT,q,killclient,",
|
||||
expected: &KeyBinding{
|
||||
expected: &MangoWCKeyBinding{
|
||||
Mods: []string{"ALT"},
|
||||
Key: "q",
|
||||
Command: "killclient",
|
||||
@@ -89,7 +89,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_with_params",
|
||||
line: "bind=ALT,Left,focusdir,left",
|
||||
expected: &KeyBinding{
|
||||
expected: &MangoWCKeyBinding{
|
||||
Mods: []string{"ALT"},
|
||||
Key: "Left",
|
||||
Command: "focusdir",
|
||||
@@ -100,7 +100,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_with_comment",
|
||||
line: "bind=Alt,t,spawn,kitty # Open terminal",
|
||||
expected: &KeyBinding{
|
||||
expected: &MangoWCKeyBinding{
|
||||
Mods: []string{"Alt"},
|
||||
Key: "t",
|
||||
Command: "spawn",
|
||||
@@ -116,7 +116,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_multiple_mods",
|
||||
line: "bind=SUPER+SHIFT,Up,exchange_client,up",
|
||||
expected: &KeyBinding{
|
||||
expected: &MangoWCKeyBinding{
|
||||
Mods: []string{"SUPER", "SHIFT"},
|
||||
Key: "Up",
|
||||
Command: "exchange_client",
|
||||
@@ -127,7 +127,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_no_mods",
|
||||
line: "bind=NONE,Print,spawn,screenshot",
|
||||
expected: &KeyBinding{
|
||||
expected: &MangoWCKeyBinding{
|
||||
Mods: []string{},
|
||||
Key: "Print",
|
||||
Command: "spawn",
|
||||
@@ -138,7 +138,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_multiple_params",
|
||||
line: "bind=Ctrl,1,view,1,0",
|
||||
expected: &KeyBinding{
|
||||
expected: &MangoWCKeyBinding{
|
||||
Mods: []string{"Ctrl"},
|
||||
Key: "1",
|
||||
Command: "view",
|
||||
@@ -149,7 +149,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "bindl_flag",
|
||||
line: "bindl=SUPER+ALT,l,spawn,dms ipc call lock lock",
|
||||
expected: &KeyBinding{
|
||||
expected: &MangoWCKeyBinding{
|
||||
Mods: []string{"SUPER", "ALT"},
|
||||
Key: "l",
|
||||
Command: "spawn",
|
||||
@@ -160,7 +160,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_with_spaces",
|
||||
line: "bind = SUPER, r, reload_config",
|
||||
expected: &KeyBinding{
|
||||
expected: &MangoWCKeyBinding{
|
||||
Mods: []string{"SUPER"},
|
||||
Key: "r",
|
||||
Command: "reload_config",
|
||||
@@ -172,7 +172,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
parser := NewParser()
|
||||
parser := NewMangoWCParser()
|
||||
parser.contentLines = []string{tt.line}
|
||||
result := parser.getKeybindAtLine(0)
|
||||
|
||||
@@ -213,7 +213,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseKeys(t *testing.T) {
|
||||
func TestMangoWCParseKeys(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
configFile := filepath.Join(tmpDir, "config.conf")
|
||||
|
||||
@@ -242,9 +242,9 @@ bind=Ctrl,2,view,2,0
|
||||
t.Fatalf("Failed to write test config: %v", err)
|
||||
}
|
||||
|
||||
keybinds, err := ParseKeys(configFile)
|
||||
keybinds, err := ParseMangoWCKeys(configFile)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseKeys failed: %v", err)
|
||||
t.Fatalf("ParseMangoWCKeys failed: %v", err)
|
||||
}
|
||||
|
||||
expectedCount := 7
|
||||
@@ -267,7 +267,7 @@ bind=Ctrl,2,view,2,0
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadContentMultipleFiles(t *testing.T) {
|
||||
func TestMangoWCReadContentMultipleFiles(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
file1 := filepath.Join(tmpDir, "a.conf")
|
||||
@@ -283,7 +283,7 @@ func TestReadContentMultipleFiles(t *testing.T) {
|
||||
t.Fatalf("Failed to write file2: %v", err)
|
||||
}
|
||||
|
||||
parser := NewParser()
|
||||
parser := NewMangoWCParser()
|
||||
if err := parser.ReadContent(tmpDir); err != nil {
|
||||
t.Fatalf("ReadContent failed: %v", err)
|
||||
}
|
||||
@@ -294,7 +294,7 @@ func TestReadContentMultipleFiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadContentSingleFile(t *testing.T) {
|
||||
func TestMangoWCReadContentSingleFile(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
configFile := filepath.Join(tmpDir, "config.conf")
|
||||
|
||||
@@ -304,7 +304,7 @@ func TestReadContentSingleFile(t *testing.T) {
|
||||
t.Fatalf("Failed to write config: %v", err)
|
||||
}
|
||||
|
||||
parser := NewParser()
|
||||
parser := NewMangoWCParser()
|
||||
if err := parser.ReadContent(configFile); err != nil {
|
||||
t.Fatalf("ReadContent failed: %v", err)
|
||||
}
|
||||
@@ -315,7 +315,7 @@ func TestReadContentSingleFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadContentErrors(t *testing.T) {
|
||||
func TestMangoWCReadContentErrors(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
@@ -332,7 +332,7 @@ func TestReadContentErrors(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := ParseKeys(tt.path)
|
||||
_, err := ParseMangoWCKeys(tt.path)
|
||||
if err == nil {
|
||||
t.Error("Expected error, got nil")
|
||||
}
|
||||
@@ -340,7 +340,7 @@ func TestReadContentErrors(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadContentWithTildeExpansion(t *testing.T) {
|
||||
func TestMangoWCReadContentWithTildeExpansion(t *testing.T) {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Skip("Cannot get home directory")
|
||||
@@ -362,7 +362,7 @@ func TestReadContentWithTildeExpansion(t *testing.T) {
|
||||
t.Skip("Cannot create relative path")
|
||||
}
|
||||
|
||||
parser := NewParser()
|
||||
parser := NewMangoWCParser()
|
||||
tildePathMatch := "~/" + relPath
|
||||
err = parser.ReadContent(tildePathMatch)
|
||||
|
||||
@@ -371,7 +371,7 @@ func TestReadContentWithTildeExpansion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyAndCommentLines(t *testing.T) {
|
||||
func TestMangoWCEmptyAndCommentLines(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
configFile := filepath.Join(tmpDir, "config.conf")
|
||||
|
||||
@@ -388,9 +388,9 @@ bind=Alt,t,spawn,kitty
|
||||
t.Fatalf("Failed to write test config: %v", err)
|
||||
}
|
||||
|
||||
keybinds, err := ParseKeys(configFile)
|
||||
keybinds, err := ParseMangoWCKeys(configFile)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseKeys failed: %v", err)
|
||||
t.Fatalf("ParseMangoWCKeys failed: %v", err)
|
||||
}
|
||||
|
||||
if len(keybinds) != 2 {
|
||||
@@ -398,7 +398,7 @@ bind=Alt,t,spawn,kitty
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidBindLines(t *testing.T) {
|
||||
func TestMangoWCInvalidBindLines(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
line string
|
||||
@@ -419,7 +419,7 @@ func TestInvalidBindLines(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
parser := NewParser()
|
||||
parser := NewMangoWCParser()
|
||||
parser.contentLines = []string{tt.line}
|
||||
result := parser.getKeybindAtLine(0)
|
||||
|
||||
@@ -430,7 +430,7 @@ func TestInvalidBindLines(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRealWorldConfig(t *testing.T) {
|
||||
func TestMangoWCRealWorldConfig(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
configFile := filepath.Join(tmpDir, "config.conf")
|
||||
|
||||
@@ -462,9 +462,9 @@ bind=Ctrl,3,view,3,0
|
||||
t.Fatalf("Failed to write test config: %v", err)
|
||||
}
|
||||
|
||||
keybinds, err := ParseKeys(configFile)
|
||||
keybinds, err := ParseMangoWCKeys(configFile)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseKeys failed: %v", err)
|
||||
t.Fatalf("ParseMangoWCKeys failed: %v", err)
|
||||
}
|
||||
|
||||
if len(keybinds) < 14 {
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/mangowc"
|
||||
)
|
||||
|
||||
func TestMangoWCProviderName(t *testing.T) {
|
||||
@@ -88,12 +86,12 @@ func TestMangoWCCategorizeByCommand(t *testing.T) {
|
||||
func TestMangoWCFormatKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
keybind *mangowc.KeyBinding
|
||||
keybind *MangoWCKeyBinding
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "single_mod",
|
||||
keybind: &mangowc.KeyBinding{
|
||||
keybind: &MangoWCKeyBinding{
|
||||
Mods: []string{"ALT"},
|
||||
Key: "q",
|
||||
},
|
||||
@@ -101,7 +99,7 @@ func TestMangoWCFormatKey(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "multiple_mods",
|
||||
keybind: &mangowc.KeyBinding{
|
||||
keybind: &MangoWCKeyBinding{
|
||||
Mods: []string{"SUPER", "SHIFT"},
|
||||
Key: "Up",
|
||||
},
|
||||
@@ -109,7 +107,7 @@ func TestMangoWCFormatKey(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "no_mods",
|
||||
keybind: &mangowc.KeyBinding{
|
||||
keybind: &MangoWCKeyBinding{
|
||||
Mods: []string{},
|
||||
Key: "Print",
|
||||
},
|
||||
@@ -131,13 +129,13 @@ func TestMangoWCFormatKey(t *testing.T) {
|
||||
func TestMangoWCConvertKeybind(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
keybind *mangowc.KeyBinding
|
||||
keybind *MangoWCKeyBinding
|
||||
wantKey string
|
||||
wantDesc string
|
||||
}{
|
||||
{
|
||||
name: "with_comment",
|
||||
keybind: &mangowc.KeyBinding{
|
||||
keybind: &MangoWCKeyBinding{
|
||||
Mods: []string{"ALT"},
|
||||
Key: "t",
|
||||
Command: "spawn",
|
||||
@@ -149,7 +147,7 @@ func TestMangoWCConvertKeybind(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "without_comment",
|
||||
keybind: &mangowc.KeyBinding{
|
||||
keybind: &MangoWCKeyBinding{
|
||||
Mods: []string{"SUPER"},
|
||||
Key: "r",
|
||||
Command: "reload_config",
|
||||
@@ -161,7 +159,7 @@ func TestMangoWCConvertKeybind(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "with_params_no_comment",
|
||||
keybind: &mangowc.KeyBinding{
|
||||
keybind: &MangoWCKeyBinding{
|
||||
Mods: []string{"CTRL"},
|
||||
Key: "1",
|
||||
Command: "view",
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/keybinds"
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/sway"
|
||||
)
|
||||
|
||||
type SwayProvider struct {
|
||||
@@ -26,7 +25,7 @@ func (s *SwayProvider) Name() string {
|
||||
}
|
||||
|
||||
func (s *SwayProvider) GetCheatSheet() (*keybinds.CheatSheet, error) {
|
||||
section, err := sway.ParseKeys(s.configPath)
|
||||
section, err := ParseSwayKeys(s.configPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse sway config: %w", err)
|
||||
}
|
||||
@@ -41,7 +40,7 @@ func (s *SwayProvider) GetCheatSheet() (*keybinds.CheatSheet, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *SwayProvider) convertSection(section *sway.Section, subcategory string, categorizedBinds map[string][]keybinds.Keybind) {
|
||||
func (s *SwayProvider) convertSection(section *SwaySection, subcategory string, categorizedBinds map[string][]keybinds.Keybind) {
|
||||
currentSubcat := subcategory
|
||||
if section.Name != "" {
|
||||
currentSubcat = section.Name
|
||||
@@ -89,7 +88,7 @@ func (s *SwayProvider) categorizeByCommand(command string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SwayProvider) convertKeybind(kb *sway.KeyBinding, subcategory string) keybinds.Keybind {
|
||||
func (s *SwayProvider) convertKeybind(kb *SwayKeyBinding, subcategory string) keybinds.Keybind {
|
||||
key := s.formatKey(kb)
|
||||
desc := kb.Comment
|
||||
|
||||
@@ -104,7 +103,7 @@ func (s *SwayProvider) convertKeybind(kb *sway.KeyBinding, subcategory string) k
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SwayProvider) formatKey(kb *sway.KeyBinding) string {
|
||||
func (s *SwayProvider) formatKey(kb *SwayKeyBinding) string {
|
||||
parts := make([]string, 0, len(kb.Mods)+1)
|
||||
parts = append(parts, kb.Mods...)
|
||||
parts = append(parts, kb.Key)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package sway
|
||||
package providers
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -8,40 +8,40 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TitleRegex = "#+!"
|
||||
HideComment = "[hidden]"
|
||||
SwayTitleRegex = "#+!"
|
||||
SwayHideComment = "[hidden]"
|
||||
)
|
||||
|
||||
var ModSeparators = []rune{'+', ' '}
|
||||
var SwayModSeparators = []rune{'+', ' '}
|
||||
|
||||
type KeyBinding struct {
|
||||
type SwayKeyBinding struct {
|
||||
Mods []string `json:"mods"`
|
||||
Key string `json:"key"`
|
||||
Command string `json:"command"`
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
|
||||
type Section struct {
|
||||
Children []Section `json:"children"`
|
||||
Keybinds []KeyBinding `json:"keybinds"`
|
||||
Name string `json:"name"`
|
||||
type SwaySection struct {
|
||||
Children []SwaySection `json:"children"`
|
||||
Keybinds []SwayKeyBinding `json:"keybinds"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Parser struct {
|
||||
type SwayParser struct {
|
||||
contentLines []string
|
||||
readingLine int
|
||||
variables map[string]string
|
||||
}
|
||||
|
||||
func NewParser() *Parser {
|
||||
return &Parser{
|
||||
func NewSwayParser() *SwayParser {
|
||||
return &SwayParser{
|
||||
contentLines: []string{},
|
||||
readingLine: 0,
|
||||
variables: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) ReadContent(path string) error {
|
||||
func (p *SwayParser) ReadContent(path string) error {
|
||||
expandedPath := os.ExpandEnv(path)
|
||||
expandedPath = filepath.Clean(expandedPath)
|
||||
if strings.HasPrefix(expandedPath, "~") {
|
||||
@@ -88,7 +88,7 @@ func (p *Parser) ReadContent(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseVariables() {
|
||||
func (p *SwayParser) parseVariables() {
|
||||
setRegex := regexp.MustCompile(`^\s*set\s+\$(\w+)\s+(.+)$`)
|
||||
for _, line := range p.contentLines {
|
||||
matches := setRegex.FindStringSubmatch(line)
|
||||
@@ -100,7 +100,7 @@ func (p *Parser) parseVariables() {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) expandVariables(text string) string {
|
||||
func (p *SwayParser) expandVariables(text string) string {
|
||||
result := text
|
||||
for varName, varValue := range p.variables {
|
||||
result = strings.ReplaceAll(result, "$"+varName, varValue)
|
||||
@@ -108,7 +108,7 @@ func (p *Parser) expandVariables(text string) string {
|
||||
return result
|
||||
}
|
||||
|
||||
func autogenerateComment(command string) string {
|
||||
func swayAutogenerateComment(command string) string {
|
||||
command = strings.TrimSpace(command)
|
||||
|
||||
if strings.HasPrefix(command, "exec ") {
|
||||
@@ -200,7 +200,7 @@ func autogenerateComment(command string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
func (p *SwayParser) getKeybindAtLine(lineNumber int) *SwayKeyBinding {
|
||||
if lineNumber >= len(p.contentLines) {
|
||||
return nil
|
||||
}
|
||||
@@ -223,7 +223,7 @@ func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
comment = strings.TrimSpace(parts[1])
|
||||
}
|
||||
|
||||
if strings.HasPrefix(comment, HideComment) {
|
||||
if strings.HasPrefix(comment, SwayHideComment) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -249,11 +249,11 @@ func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
var modList []string
|
||||
var key string
|
||||
|
||||
modstring := keyCombo + string(ModSeparators[0])
|
||||
modstring := keyCombo + string(SwayModSeparators[0])
|
||||
pos := 0
|
||||
for index, char := range modstring {
|
||||
isModSep := false
|
||||
for _, sep := range ModSeparators {
|
||||
for _, sep := range SwayModSeparators {
|
||||
if char == sep {
|
||||
isModSep = true
|
||||
break
|
||||
@@ -262,7 +262,7 @@ func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
if isModSep {
|
||||
if index-pos > 0 {
|
||||
part := modstring[pos:index]
|
||||
if isMod(part) {
|
||||
if swayIsMod(part) {
|
||||
modList = append(modList, part)
|
||||
} else {
|
||||
key = part
|
||||
@@ -273,12 +273,12 @@ func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
}
|
||||
|
||||
if comment == "" {
|
||||
comment = autogenerateComment(command)
|
||||
comment = swayAutogenerateComment(command)
|
||||
}
|
||||
|
||||
_ = flags
|
||||
|
||||
return &KeyBinding{
|
||||
return &SwayKeyBinding{
|
||||
Mods: modList,
|
||||
Key: key,
|
||||
Command: command,
|
||||
@@ -286,7 +286,7 @@ func (p *Parser) getKeybindAtLine(lineNumber int) *KeyBinding {
|
||||
}
|
||||
}
|
||||
|
||||
func isMod(s string) bool {
|
||||
func swayIsMod(s string) bool {
|
||||
s = strings.ToLower(s)
|
||||
if s == "mod1" || s == "mod2" || s == "mod3" || s == "mod4" || s == "mod5" ||
|
||||
s == "shift" || s == "control" || s == "ctrl" || s == "alt" || s == "super" ||
|
||||
@@ -307,8 +307,8 @@ func isMod(s string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *Parser) getBindsRecursive(currentContent *Section, scope int) *Section {
|
||||
titleRegex := regexp.MustCompile(TitleRegex)
|
||||
func (p *SwayParser) getBindsRecursive(currentContent *SwaySection, scope int) *SwaySection {
|
||||
titleRegex := regexp.MustCompile(SwayTitleRegex)
|
||||
|
||||
for p.readingLine < len(p.contentLines) {
|
||||
line := p.contentLines[p.readingLine]
|
||||
@@ -325,9 +325,9 @@ func (p *Parser) getBindsRecursive(currentContent *Section, scope int) *Section
|
||||
sectionName := strings.TrimSpace(line[headingScope+1:])
|
||||
p.readingLine++
|
||||
|
||||
childSection := &Section{
|
||||
Children: []Section{},
|
||||
Keybinds: []KeyBinding{},
|
||||
childSection := &SwaySection{
|
||||
Children: []SwaySection{},
|
||||
Keybinds: []SwayKeyBinding{},
|
||||
Name: sectionName,
|
||||
}
|
||||
result := p.getBindsRecursive(childSection, headingScope)
|
||||
@@ -348,18 +348,18 @@ func (p *Parser) getBindsRecursive(currentContent *Section, scope int) *Section
|
||||
return currentContent
|
||||
}
|
||||
|
||||
func (p *Parser) ParseKeys() *Section {
|
||||
func (p *SwayParser) ParseKeys() *SwaySection {
|
||||
p.readingLine = 0
|
||||
rootSection := &Section{
|
||||
Children: []Section{},
|
||||
Keybinds: []KeyBinding{},
|
||||
rootSection := &SwaySection{
|
||||
Children: []SwaySection{},
|
||||
Keybinds: []SwayKeyBinding{},
|
||||
Name: "",
|
||||
}
|
||||
return p.getBindsRecursive(rootSection, 0)
|
||||
}
|
||||
|
||||
func ParseKeys(path string) (*Section, error) {
|
||||
parser := NewParser()
|
||||
func ParseSwayKeys(path string) (*SwaySection, error) {
|
||||
parser := NewSwayParser()
|
||||
if err := parser.ReadContent(path); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package sway
|
||||
package providers
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAutogenerateComment(t *testing.T) {
|
||||
func TestSwayAutogenerateComment(t *testing.T) {
|
||||
tests := []struct {
|
||||
command string
|
||||
expected string
|
||||
@@ -46,25 +46,25 @@ func TestAutogenerateComment(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.command, func(t *testing.T) {
|
||||
result := autogenerateComment(tt.command)
|
||||
result := swayAutogenerateComment(tt.command)
|
||||
if result != tt.expected {
|
||||
t.Errorf("autogenerateComment(%q) = %q, want %q",
|
||||
t.Errorf("swayAutogenerateComment(%q) = %q, want %q",
|
||||
tt.command, result, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetKeybindAtLine(t *testing.T) {
|
||||
func TestSwayGetKeybindAtLine(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
line string
|
||||
expected *KeyBinding
|
||||
expected *SwayKeyBinding
|
||||
}{
|
||||
{
|
||||
name: "basic_keybind",
|
||||
line: "bindsym Mod4+q kill",
|
||||
expected: &KeyBinding{
|
||||
expected: &SwayKeyBinding{
|
||||
Mods: []string{"Mod4"},
|
||||
Key: "q",
|
||||
Command: "kill",
|
||||
@@ -74,7 +74,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_with_exec",
|
||||
line: "bindsym Mod4+t exec kitty",
|
||||
expected: &KeyBinding{
|
||||
expected: &SwayKeyBinding{
|
||||
Mods: []string{"Mod4"},
|
||||
Key: "t",
|
||||
Command: "exec kitty",
|
||||
@@ -84,7 +84,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_with_comment",
|
||||
line: "bindsym Mod4+Space exec dms ipc call spotlight toggle # Open launcher",
|
||||
expected: &KeyBinding{
|
||||
expected: &SwayKeyBinding{
|
||||
Mods: []string{"Mod4"},
|
||||
Key: "Space",
|
||||
Command: "exec dms ipc call spotlight toggle",
|
||||
@@ -99,7 +99,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_multiple_mods",
|
||||
line: "bindsym Mod4+Shift+e exit",
|
||||
expected: &KeyBinding{
|
||||
expected: &SwayKeyBinding{
|
||||
Mods: []string{"Mod4", "Shift"},
|
||||
Key: "e",
|
||||
Command: "exit",
|
||||
@@ -109,7 +109,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_no_mods",
|
||||
line: "bindsym Print exec grim screenshot.png",
|
||||
expected: &KeyBinding{
|
||||
expected: &SwayKeyBinding{
|
||||
Mods: []string{},
|
||||
Key: "Print",
|
||||
Command: "exec grim screenshot.png",
|
||||
@@ -119,7 +119,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_with_flags",
|
||||
line: "bindsym --release Mod4+x exec notify-send released",
|
||||
expected: &KeyBinding{
|
||||
expected: &SwayKeyBinding{
|
||||
Mods: []string{"Mod4"},
|
||||
Key: "x",
|
||||
Command: "exec notify-send released",
|
||||
@@ -129,7 +129,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_focus_direction",
|
||||
line: "bindsym Mod4+Left focus left",
|
||||
expected: &KeyBinding{
|
||||
expected: &SwayKeyBinding{
|
||||
Mods: []string{"Mod4"},
|
||||
Key: "Left",
|
||||
Command: "focus left",
|
||||
@@ -139,7 +139,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
{
|
||||
name: "keybind_workspace",
|
||||
line: "bindsym Mod4+1 workspace number 1",
|
||||
expected: &KeyBinding{
|
||||
expected: &SwayKeyBinding{
|
||||
Mods: []string{"Mod4"},
|
||||
Key: "1",
|
||||
Command: "workspace number 1",
|
||||
@@ -150,7 +150,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
parser := NewParser()
|
||||
parser := NewSwayParser()
|
||||
parser.contentLines = []string{tt.line}
|
||||
result := parser.getKeybindAtLine(0)
|
||||
|
||||
@@ -188,7 +188,7 @@ func TestGetKeybindAtLine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestVariableExpansion(t *testing.T) {
|
||||
func TestSwayVariableExpansion(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
configFile := filepath.Join(tmpDir, "config")
|
||||
|
||||
@@ -204,9 +204,9 @@ bindsym $mod+d exec $menu
|
||||
t.Fatalf("Failed to write test config: %v", err)
|
||||
}
|
||||
|
||||
section, err := ParseKeys(configFile)
|
||||
section, err := ParseSwayKeys(configFile)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseKeys failed: %v", err)
|
||||
t.Fatalf("ParseSwayKeys failed: %v", err)
|
||||
}
|
||||
|
||||
if len(section.Keybinds) != 2 {
|
||||
@@ -229,7 +229,7 @@ bindsym $mod+d exec $menu
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseKeysWithSections(t *testing.T) {
|
||||
func TestSwayParseKeysWithSections(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
configFile := filepath.Join(tmpDir, "config")
|
||||
|
||||
@@ -251,9 +251,9 @@ bindsym $mod+t exec kitty # Terminal
|
||||
t.Fatalf("Failed to write test config: %v", err)
|
||||
}
|
||||
|
||||
section, err := ParseKeys(tmpDir)
|
||||
section, err := ParseSwayKeys(tmpDir)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseKeys failed: %v", err)
|
||||
t.Fatalf("ParseSwayKeys failed: %v", err)
|
||||
}
|
||||
|
||||
if len(section.Children) != 2 {
|
||||
@@ -296,7 +296,7 @@ bindsym $mod+t exec kitty # Terminal
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadContentErrors(t *testing.T) {
|
||||
func TestSwayReadContentErrors(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
@@ -313,7 +313,7 @@ func TestReadContentErrors(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := ParseKeys(tt.path)
|
||||
_, err := ParseSwayKeys(tt.path)
|
||||
if err == nil {
|
||||
t.Error("Expected error, got nil")
|
||||
}
|
||||
@@ -321,7 +321,7 @@ func TestReadContentErrors(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadContentWithTildeExpansion(t *testing.T) {
|
||||
func TestSwayReadContentWithTildeExpansion(t *testing.T) {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Skip("Cannot get home directory")
|
||||
@@ -343,7 +343,7 @@ func TestReadContentWithTildeExpansion(t *testing.T) {
|
||||
t.Skip("Cannot create relative path")
|
||||
}
|
||||
|
||||
parser := NewParser()
|
||||
parser := NewSwayParser()
|
||||
tildePathMatch := "~/" + relPath
|
||||
err = parser.ReadContent(tildePathMatch)
|
||||
|
||||
@@ -352,7 +352,7 @@ func TestReadContentWithTildeExpansion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyAndCommentLines(t *testing.T) {
|
||||
func TestSwayEmptyAndCommentLines(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
configFile := filepath.Join(tmpDir, "config")
|
||||
|
||||
@@ -369,9 +369,9 @@ bindsym Mod4+t exec kitty
|
||||
t.Fatalf("Failed to write test config: %v", err)
|
||||
}
|
||||
|
||||
section, err := ParseKeys(configFile)
|
||||
section, err := ParseSwayKeys(configFile)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseKeys failed: %v", err)
|
||||
t.Fatalf("ParseSwayKeys failed: %v", err)
|
||||
}
|
||||
|
||||
if len(section.Keybinds) != 2 {
|
||||
@@ -379,7 +379,7 @@ bindsym Mod4+t exec kitty
|
||||
}
|
||||
}
|
||||
|
||||
func TestRealWorldConfig(t *testing.T) {
|
||||
func TestSwayRealWorldConfig(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
configFile := filepath.Join(tmpDir, "config")
|
||||
|
||||
@@ -408,9 +408,9 @@ bindsym $mod+Shift+1 move container to workspace number 1
|
||||
t.Fatalf("Failed to write test config: %v", err)
|
||||
}
|
||||
|
||||
section, err := ParseKeys(configFile)
|
||||
section, err := ParseSwayKeys(configFile)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseKeys failed: %v", err)
|
||||
t.Fatalf("ParseSwayKeys failed: %v", err)
|
||||
}
|
||||
|
||||
if len(section.Keybinds) < 9 {
|
||||
@@ -444,7 +444,7 @@ bindsym $mod+Shift+1 move container to workspace number 1
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsMod(t *testing.T) {
|
||||
func TestSwayIsMod(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expected bool
|
||||
@@ -462,9 +462,9 @@ func TestIsMod(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
result := isMod(tt.input)
|
||||
result := swayIsMod(tt.input)
|
||||
if result != tt.expected {
|
||||
t.Errorf("isMod(%q) = %v, want %v", tt.input, result, tt.expected)
|
||||
t.Errorf("swayIsMod(%q) = %v, want %v", tt.input, result, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/sway"
|
||||
)
|
||||
|
||||
func TestSwayProviderName(t *testing.T) {
|
||||
@@ -76,12 +74,12 @@ func TestSwayCategorizeByCommand(t *testing.T) {
|
||||
func TestSwayFormatKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
keybind *sway.KeyBinding
|
||||
keybind *SwayKeyBinding
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "single_mod",
|
||||
keybind: &sway.KeyBinding{
|
||||
keybind: &SwayKeyBinding{
|
||||
Mods: []string{"Mod4"},
|
||||
Key: "q",
|
||||
},
|
||||
@@ -89,7 +87,7 @@ func TestSwayFormatKey(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "multiple_mods",
|
||||
keybind: &sway.KeyBinding{
|
||||
keybind: &SwayKeyBinding{
|
||||
Mods: []string{"Mod4", "Shift"},
|
||||
Key: "e",
|
||||
},
|
||||
@@ -97,7 +95,7 @@ func TestSwayFormatKey(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "no_mods",
|
||||
keybind: &sway.KeyBinding{
|
||||
keybind: &SwayKeyBinding{
|
||||
Mods: []string{},
|
||||
Key: "Print",
|
||||
},
|
||||
@@ -119,13 +117,13 @@ func TestSwayFormatKey(t *testing.T) {
|
||||
func TestSwayConvertKeybind(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
keybind *sway.KeyBinding
|
||||
keybind *SwayKeyBinding
|
||||
wantKey string
|
||||
wantDesc string
|
||||
}{
|
||||
{
|
||||
name: "with_comment",
|
||||
keybind: &sway.KeyBinding{
|
||||
keybind: &SwayKeyBinding{
|
||||
Mods: []string{"Mod4"},
|
||||
Key: "t",
|
||||
Command: "exec kitty",
|
||||
@@ -136,7 +134,7 @@ func TestSwayConvertKeybind(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "without_comment",
|
||||
keybind: &sway.KeyBinding{
|
||||
keybind: &SwayKeyBinding{
|
||||
Mods: []string{"Mod4"},
|
||||
Key: "r",
|
||||
Command: "reload",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package logger
|
||||
package log
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## Overview
|
||||
|
||||
The network manager API provides methods for managing WiFi connections, monitoring network state, and handling credential prompts through NetworkManager. Communication occurs over a message-based protocol (websocket, IPC, etc.) with event subscriptions for state updates.
|
||||
The network manager API provides methods for managing WiFi connections, monitoring network state, and handling credential prompts through NetworkManager or iwd (and systemd-networkd for ethernet only). Communication occurs over a message-based protocol (websocket, IPC, etc.) with event subscriptions for state updates.
|
||||
|
||||
## API Methods
|
||||
|
||||
|
||||
@@ -3,14 +3,15 @@ package network
|
||||
import (
|
||||
"testing"
|
||||
|
||||
mock_gonetworkmanager "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/github.com/Wifx/gonetworkmanager/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNetworkManagerBackend_GetWiredConnections_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.ethernetDevice = nil
|
||||
_, err = backend.GetWiredConnections()
|
||||
@@ -19,10 +20,10 @@ func TestNetworkManagerBackend_GetWiredConnections_NoDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_GetWiredNetworkDetails_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.ethernetDevice = nil
|
||||
_, err = backend.GetWiredNetworkDetails("test-uuid")
|
||||
@@ -31,10 +32,10 @@ func TestNetworkManagerBackend_GetWiredNetworkDetails_NoDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_ConnectEthernet_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.ethernetDevice = nil
|
||||
err = backend.ConnectEthernet()
|
||||
@@ -43,10 +44,10 @@ func TestNetworkManagerBackend_ConnectEthernet_NoDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_DisconnectEthernet_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.ethernetDevice = nil
|
||||
err = backend.DisconnectEthernet()
|
||||
@@ -55,10 +56,10 @@ func TestNetworkManagerBackend_DisconnectEthernet_NoDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_ActivateWiredConnection_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.ethernetDevice = nil
|
||||
err = backend.ActivateWiredConnection("test-uuid")
|
||||
@@ -67,25 +68,14 @@ func TestNetworkManagerBackend_ActivateWiredConnection_NoDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_ActivateWiredConnection_NotFound(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
|
||||
if backend.ethernetDevice == nil {
|
||||
t.Skip("No ethernet device available")
|
||||
}
|
||||
|
||||
err = backend.ActivateWiredConnection("non-existent-uuid-12345")
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "not found")
|
||||
t.Skip("ActivateWiredConnection creates a new Settings instance internally, cannot be fully mocked")
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_ListEthernetConnections_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.ethernetDevice = nil
|
||||
_, err = backend.listEthernetConnections()
|
||||
|
||||
@@ -3,15 +3,17 @@ package network
|
||||
import (
|
||||
"testing"
|
||||
|
||||
mock_gonetworkmanager "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/github.com/Wifx/gonetworkmanager/v2"
|
||||
"github.com/Wifx/gonetworkmanager/v2"
|
||||
"github.com/godbus/dbus/v5"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNetworkManagerBackend_HandleDBusSignal_NewConnection(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
sig := &dbus.Signal{
|
||||
Name: "org.freedesktop.NetworkManager.Settings.NewConnection",
|
||||
@@ -24,10 +26,10 @@ func TestNetworkManagerBackend_HandleDBusSignal_NewConnection(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleDBusSignal_ConnectionRemoved(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
sig := &dbus.Signal{
|
||||
Name: "org.freedesktop.NetworkManager.Settings.ConnectionRemoved",
|
||||
@@ -40,10 +42,10 @@ func TestNetworkManagerBackend_HandleDBusSignal_ConnectionRemoved(t *testing.T)
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleDBusSignal_InvalidBody(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
sig := &dbus.Signal{
|
||||
Name: "org.freedesktop.DBus.Properties.PropertiesChanged",
|
||||
@@ -56,10 +58,10 @@ func TestNetworkManagerBackend_HandleDBusSignal_InvalidBody(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleDBusSignal_InvalidInterface(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
sig := &dbus.Signal{
|
||||
Name: "org.freedesktop.DBus.Properties.PropertiesChanged",
|
||||
@@ -72,10 +74,10 @@ func TestNetworkManagerBackend_HandleDBusSignal_InvalidInterface(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleDBusSignal_InvalidChanges(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
sig := &dbus.Signal{
|
||||
Name: "org.freedesktop.DBus.Properties.PropertiesChanged",
|
||||
@@ -88,10 +90,13 @@ func TestNetworkManagerBackend_HandleDBusSignal_InvalidChanges(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleNetworkManagerChange(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
mockNM.EXPECT().GetPropertyActiveConnections().Return([]gonetworkmanager.ActiveConnection{}, nil).Maybe()
|
||||
mockNM.EXPECT().GetPropertyPrimaryConnection().Return(nil, nil).Maybe()
|
||||
|
||||
changes := map[string]dbus.Variant{
|
||||
"PrimaryConnection": dbus.MakeVariant("/"),
|
||||
@@ -104,10 +109,14 @@ func TestNetworkManagerBackend_HandleNetworkManagerChange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleNetworkManagerChange_WirelessEnabled(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
mockNM.EXPECT().GetPropertyWirelessEnabled().Return(true, nil)
|
||||
mockNM.EXPECT().GetPropertyActiveConnections().Return([]gonetworkmanager.ActiveConnection{}, nil).Maybe()
|
||||
mockNM.EXPECT().GetPropertyPrimaryConnection().Return(nil, nil).Maybe()
|
||||
|
||||
changes := map[string]dbus.Variant{
|
||||
"WirelessEnabled": dbus.MakeVariant(true),
|
||||
@@ -119,10 +128,13 @@ func TestNetworkManagerBackend_HandleNetworkManagerChange_WirelessEnabled(t *tes
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleNetworkManagerChange_ActiveConnections(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
mockNM.EXPECT().GetPropertyActiveConnections().Return([]gonetworkmanager.ActiveConnection{}, nil)
|
||||
mockNM.EXPECT().GetPropertyPrimaryConnection().Return(nil, nil).Maybe()
|
||||
|
||||
changes := map[string]dbus.Variant{
|
||||
"ActiveConnections": dbus.MakeVariant([]interface{}{}),
|
||||
@@ -134,10 +146,13 @@ func TestNetworkManagerBackend_HandleNetworkManagerChange_ActiveConnections(t *t
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleDeviceChange(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
mockNM.EXPECT().GetPropertyActiveConnections().Return([]gonetworkmanager.ActiveConnection{}, nil).Maybe()
|
||||
mockNM.EXPECT().GetPropertyPrimaryConnection().Return(nil, nil).Maybe()
|
||||
|
||||
changes := map[string]dbus.Variant{
|
||||
"State": dbus.MakeVariant(uint32(100)),
|
||||
@@ -149,10 +164,10 @@ func TestNetworkManagerBackend_HandleDeviceChange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleDeviceChange_Ip4Config(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
changes := map[string]dbus.Variant{
|
||||
"Ip4Config": dbus.MakeVariant("/"),
|
||||
@@ -164,10 +179,10 @@ func TestNetworkManagerBackend_HandleDeviceChange_Ip4Config(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleWiFiChange_ActiveAccessPoint(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
changes := map[string]dbus.Variant{
|
||||
"ActiveAccessPoint": dbus.MakeVariant("/"),
|
||||
@@ -179,10 +194,10 @@ func TestNetworkManagerBackend_HandleWiFiChange_ActiveAccessPoint(t *testing.T)
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleWiFiChange_AccessPoints(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
changes := map[string]dbus.Variant{
|
||||
"AccessPoints": dbus.MakeVariant([]interface{}{}),
|
||||
@@ -194,10 +209,10 @@ func TestNetworkManagerBackend_HandleWiFiChange_AccessPoints(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleAccessPointChange_NoStrength(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
changes := map[string]dbus.Variant{
|
||||
"SomeOtherProperty": dbus.MakeVariant("value"),
|
||||
@@ -209,10 +224,10 @@ func TestNetworkManagerBackend_HandleAccessPointChange_NoStrength(t *testing.T)
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_HandleAccessPointChange_WithStrength(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.stateMutex.Lock()
|
||||
backend.state.WiFiSignal = 50
|
||||
@@ -228,10 +243,10 @@ func TestNetworkManagerBackend_HandleAccessPointChange_WithStrength(t *testing.T
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_StopSignalPump_NoConnection(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.dbusConn = nil
|
||||
assert.NotPanics(t, func() {
|
||||
|
||||
@@ -3,15 +3,15 @@ package network
|
||||
import (
|
||||
"testing"
|
||||
|
||||
mock_gonetworkmanager "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/github.com/Wifx/gonetworkmanager/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNetworkManagerBackend_New(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, backend)
|
||||
assert.Equal(t, "networkmanager", backend.state.Backend)
|
||||
assert.NotNil(t, backend.stopChan)
|
||||
@@ -19,10 +19,10 @@ func TestNetworkManagerBackend_New(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_GetCurrentState(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.state.NetworkStatus = StatusWiFi
|
||||
backend.state.WiFiConnected = true
|
||||
@@ -49,10 +49,10 @@ func TestNetworkManagerBackend_GetCurrentState(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_SetPromptBroker_Nil(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = backend.SetPromptBroker(nil)
|
||||
assert.Error(t, err)
|
||||
@@ -60,10 +60,10 @@ func TestNetworkManagerBackend_SetPromptBroker_Nil(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_SubmitCredentials_NoBroker(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.promptBroker = nil
|
||||
err = backend.SubmitCredentials("token", map[string]string{"password": "test"}, false)
|
||||
@@ -72,10 +72,10 @@ func TestNetworkManagerBackend_SubmitCredentials_NoBroker(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_CancelCredentials_NoBroker(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.promptBroker = nil
|
||||
err = backend.CancelCredentials("token")
|
||||
@@ -84,10 +84,10 @@ func TestNetworkManagerBackend_CancelCredentials_NoBroker(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_EnsureWiFiDevice_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.wifiDevice = nil
|
||||
backend.wifiDev = nil
|
||||
@@ -98,10 +98,10 @@ func TestNetworkManagerBackend_EnsureWiFiDevice_NoDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_EnsureWiFiDevice_AlreadySet(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.wifiDev = "dummy-device"
|
||||
|
||||
@@ -110,10 +110,10 @@ func TestNetworkManagerBackend_EnsureWiFiDevice_AlreadySet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_StartSecretAgent_NoBroker(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.promptBroker = nil
|
||||
err = backend.startSecretAgent()
|
||||
@@ -122,10 +122,10 @@ func TestNetworkManagerBackend_StartSecretAgent_NoBroker(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_Close(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
backend.Close()
|
||||
@@ -133,20 +133,20 @@ func TestNetworkManagerBackend_Close(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_GetPromptBroker(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
broker := backend.GetPromptBroker()
|
||||
assert.Nil(t, broker)
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_StopMonitoring_NoSignals(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
backend.StopMonitoring()
|
||||
|
||||
@@ -21,33 +21,26 @@ func TestNetworkManagerBackend_GetWiFiEnabled(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_SetWiFiEnabled(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
originalState, err := backend.GetWiFiEnabled()
|
||||
if err != nil {
|
||||
t.Skipf("Cannot get WiFi state: %v", err)
|
||||
}
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
defer func() {
|
||||
backend.SetWiFiEnabled(originalState)
|
||||
}()
|
||||
mockNM.EXPECT().SetPropertyWirelessEnabled(true).Return(nil)
|
||||
|
||||
err = backend.SetWiFiEnabled(!originalState)
|
||||
err = backend.SetWiFiEnabled(true)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.stateMutex.RLock()
|
||||
assert.Equal(t, !originalState, backend.state.WiFiEnabled)
|
||||
assert.True(t, backend.state.WiFiEnabled)
|
||||
backend.stateMutex.RUnlock()
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_ScanWiFi_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.wifiDevice = nil
|
||||
err = backend.ScanWiFi()
|
||||
@@ -56,14 +49,14 @@ func TestNetworkManagerBackend_ScanWiFi_NoDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_ScanWiFi_Disabled(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
mockDeviceWireless := mock_gonetworkmanager.NewMockDeviceWireless(t)
|
||||
|
||||
if backend.wifiDevice == nil {
|
||||
t.Skip("No WiFi device available")
|
||||
}
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.wifiDevice = mockDeviceWireless
|
||||
backend.wifiDev = mockDeviceWireless
|
||||
|
||||
backend.stateMutex.Lock()
|
||||
backend.state.WiFiEnabled = false
|
||||
@@ -75,10 +68,10 @@ func TestNetworkManagerBackend_ScanWiFi_Disabled(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_GetWiFiNetworkDetails_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.wifiDevice = nil
|
||||
_, err = backend.GetWiFiNetworkDetails("TestNetwork")
|
||||
@@ -87,10 +80,10 @@ func TestNetworkManagerBackend_GetWiFiNetworkDetails_NoDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_ConnectWiFi_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.wifiDevice = nil
|
||||
req := ConnectionRequest{SSID: "TestNetwork", Password: "password"}
|
||||
@@ -100,14 +93,14 @@ func TestNetworkManagerBackend_ConnectWiFi_NoDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_ConnectWiFi_AlreadyConnected(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
mockDeviceWireless := mock_gonetworkmanager.NewMockDeviceWireless(t)
|
||||
|
||||
if backend.wifiDevice == nil {
|
||||
t.Skip("No WiFi device available")
|
||||
}
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.wifiDevice = mockDeviceWireless
|
||||
backend.wifiDev = mockDeviceWireless
|
||||
|
||||
backend.stateMutex.Lock()
|
||||
backend.state.WiFiConnected = true
|
||||
@@ -120,10 +113,10 @@ func TestNetworkManagerBackend_ConnectWiFi_AlreadyConnected(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_DisconnectWiFi_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.wifiDevice = nil
|
||||
err = backend.DisconnectWiFi()
|
||||
@@ -132,10 +125,10 @@ func TestNetworkManagerBackend_DisconnectWiFi_NoDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_IsConnectingTo(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.stateMutex.Lock()
|
||||
backend.state.IsConnecting = true
|
||||
@@ -147,10 +140,10 @@ func TestNetworkManagerBackend_IsConnectingTo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_IsConnectingTo_NotConnecting(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.stateMutex.Lock()
|
||||
backend.state.IsConnecting = false
|
||||
@@ -161,10 +154,10 @@ func TestNetworkManagerBackend_IsConnectingTo_NotConnecting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_UpdateWiFiNetworks_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.wifiDevice = nil
|
||||
_, err = backend.updateWiFiNetworks()
|
||||
@@ -173,10 +166,10 @@ func TestNetworkManagerBackend_UpdateWiFiNetworks_NoDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_FindConnection_NoSettings(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.settings = nil
|
||||
_, err = backend.findConnection("NonExistentNetwork")
|
||||
@@ -184,10 +177,10 @@ func TestNetworkManagerBackend_FindConnection_NoSettings(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkManagerBackend_CreateAndConnectWiFi_NoDevice(t *testing.T) {
|
||||
backend, err := NewNetworkManagerBackend()
|
||||
if err != nil {
|
||||
t.Skipf("NetworkManager not available: %v", err)
|
||||
}
|
||||
mockNM := mock_gonetworkmanager.NewMockNetworkManager(t)
|
||||
|
||||
backend, err := NewNetworkManagerBackend(mockNM)
|
||||
assert.NoError(t, err)
|
||||
|
||||
backend.wifiDevice = nil
|
||||
backend.wifiDev = nil
|
||||
|
||||
Reference in New Issue
Block a user