MCPcopy Create free account
hub / github.com/driangle/taskmd / TestInputResolver_ResolveInput

Function TestInputResolver_ResolveInput

apps/cli/internal/cli/input_test.go:10–65  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestInputResolver_ResolveInput(t *testing.T) {
11 // Create a temporary directory and file for testing
12 tmpDir := t.TempDir()
13 testFile := filepath.Join(tmpDir, "test.md")
14 testContent := "# Test Content\n"
15
16 if err := os.WriteFile(testFile, []byte(testContent), 0644); err != nil {
17 t.Fatalf("Failed to create test file: %v", err)
18 }
19
20 tests := []struct {
21 name string
22 useStdin bool
23 args []string
24 wantErr bool
25 }{
26 {
27 name: "explicit file",
28 useStdin: false,
29 args: []string{testFile},
30 wantErr: false,
31 },
32 {
33 name: "file not found",
34 useStdin: false,
35 args: []string{filepath.Join(tmpDir, "nonexistent.md")},
36 wantErr: true,
37 },
38 }
39
40 for _, tt := range tests {
41 t.Run(tt.name, func(t *testing.T) {
42 resolver := NewInputResolver(tt.useStdin, false)
43 reader, cleanup, err := resolver.ResolveInput(tt.args)
44
45 if (err != nil) != tt.wantErr {
46 t.Errorf("ResolveInput() error = %v, wantErr %v", err, tt.wantErr)
47 return
48 }
49
50 if err == nil {
51 defer cleanup()
52
53 // Try to read content
54 content, err := io.ReadAll(reader)
55 if err != nil {
56 t.Errorf("Failed to read from resolver: %v", err)
57 }
58
59 if !tt.useStdin && string(content) != testContent {
60 t.Errorf("Content mismatch: got %q, want %q", string(content), testContent)
61 }
62 }
63 })
64 }
65}
66
67func TestInputResolver_ReadAll(t *testing.T) {

Callers

nothing calls this directly

Calls 4

ResolveInputMethod · 0.95
NewInputResolverFunction · 0.85
cleanupFunction · 0.85
ReadAllMethod · 0.80

Tested by

no test coverage detected