forked from knbr13/gitcs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_test.go
43 lines (39 loc) · 961 Bytes
/
input_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"bufio"
"strings"
"testing"
)
func TestGetPathFromUser(t *testing.T) {
testCases := []struct {
description string
input string
expectedPath string
expectedError bool
}{
{
description: "Valid folder path",
input: "./test_data",
expectedPath: "./test_data",
expectedError: false,
},
{
description: "Invalid folder path",
input: "./path/to/invalid/folder",
expectedPath: "./",
expectedError: true,
},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
reader := bufio.NewReader(strings.NewReader(tc.input + "\n"))
actualPath, err := getPathFromUser(reader)
if err != nil && !tc.expectedError {
t.Errorf("getPathFromUser() error = %v, want %v", err, tc.expectedError)
}
if !tc.expectedError && actualPath != tc.expectedPath {
t.Errorf("Expected path: %s, got: %s", tc.expectedPath, actualPath)
}
})
}
}