MCPcopy
hub / github.com/SurgeDM/Surge / TestOpenFile_Validation

Function TestOpenFile_Validation

internal/utils/open_test.go:8–45  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestOpenFile_Validation(t *testing.T) {
9 tempDir := t.TempDir()
10
11 tests := []struct {
12 name string
13 path string
14 errorHints []string
15 }{
16 {
17 name: "empty path",
18 path: "",
19 errorHints: []string{"empty"},
20 },
21 {
22 name: "directory path",
23 path: tempDir,
24 errorHints: []string{"directory", "is a directory"},
25 },
26 }
27
28 for _, tc := range tests {
29 t.Run(tc.name, func(t *testing.T) {
30 err := OpenFile(tc.path)
31 if err == nil {
32 t.Fatalf("expected validation error for %q", tc.path)
33 }
34
35 lower := strings.ToLower(err.Error())
36 for _, hint := range tc.errorHints {
37 if strings.Contains(lower, strings.ToLower(hint)) {
38 return
39 }
40 }
41
42 t.Fatalf("expected error containing one of %v, got: %v", tc.errorHints, err)
43 })
44 }
45}
46
47func TestOpenContainingFolder_Validation(t *testing.T) {
48 tests := []struct {

Callers

nothing calls this directly

Calls 2

OpenFileFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected