-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ADD WSL route in auto open feature (#48)
- Loading branch information
1 parent
23d1a24
commit efb2fef
Showing
2 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
) | ||
|
||
type MockFileReader struct { | ||
content string | ||
err error | ||
} | ||
|
||
func (m MockFileReader) ReadFile(path string) (string, error) { | ||
return m.content, m.err | ||
} | ||
|
||
func TestIsContainWSL(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
data string | ||
expected bool | ||
}{ | ||
{ | ||
name: "WSL Data", | ||
data: "Linux version 4.19.128-microsoft-standard (WSL2)", | ||
expected: true, | ||
}, | ||
{ | ||
name: "Non-WSL Data", | ||
data: "Linux version 4.15.0-72-generic", | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := isContainWSL(tt.data) | ||
if result != tt.expected { | ||
t.Errorf("expected %v, got %v", tt.expected, result) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIsWSL(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
reader FileReader | ||
expected bool | ||
}{ | ||
{ | ||
name: "WSL Data", | ||
reader: MockFileReader{content: "Linux version 4.19.128-microsoft-standard (WSL2)"}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "Non-WSL Data", | ||
reader: MockFileReader{content: "Linux version 4.15.0-72-generic"}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "Read error", | ||
reader: MockFileReader{err: errors.New("read error")}, | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := isWSLWithReader(tt.reader) | ||
if result != tt.expected { | ||
t.Errorf("expected %v, got %v", tt.expected, result) | ||
} | ||
}) | ||
} | ||
} |