(t *testing.T)
| 1068 | } |
| 1069 | |
| 1070 | func TestValidatePath(t *testing.T) { |
| 1071 | tests := []struct { |
| 1072 | name string |
| 1073 | setup func(afs afero.Fs) |
| 1074 | path string |
| 1075 | mockPathExists func(fs afero.Fs, path string) (bool, error) |
| 1076 | mockIsDirectory func(fs afero.Fs, path string) (bool, error) |
| 1077 | mockIsEmpty func(fs afero.Fs, path string) (bool, error) |
| 1078 | expected [3]bool // exists, isDir, isEmpty |
| 1079 | expectedError error |
| 1080 | }{ |
| 1081 | { |
| 1082 | name: "Path is Valid Non-Empty File", |
| 1083 | setup: func(afs afero.Fs) { |
| 1084 | require.NoError(t, afero.WriteFile(afs, "/file.txt", []byte("content"), 0644)) |
| 1085 | }, |
| 1086 | path: "/file.txt", |
| 1087 | expected: [3]bool{true, false, false}, |
| 1088 | expectedError: nil, |
| 1089 | }, |
| 1090 | { |
| 1091 | name: "Path is Valid Empty File", |
| 1092 | setup: func(afs afero.Fs) { |
| 1093 | require.NoError(t, afero.WriteFile(afs, "/file.txt", []byte(""), 0644)) |
| 1094 | }, |
| 1095 | path: "/file.txt", |
| 1096 | expected: [3]bool{true, false, true}, |
| 1097 | expectedError: nil, |
| 1098 | }, |
| 1099 | { |
| 1100 | name: "Path is Valid Non-Empty Directory", |
| 1101 | setup: func(afs afero.Fs) { |
| 1102 | require.NoError(t, afs.Mkdir("/nonemptydir", 0755)) |
| 1103 | require.NoError(t, afero.WriteFile(afs, "/nonemptydir/file.txt", []byte("content"), 0644)) |
| 1104 | }, |
| 1105 | path: "/nonemptydir", |
| 1106 | expected: [3]bool{true, true, false}, |
| 1107 | expectedError: nil, |
| 1108 | }, |
| 1109 | { |
| 1110 | name: "Path is Valid Empty Directory", |
| 1111 | setup: func(afs afero.Fs) { |
| 1112 | require.NoError(t, afs.Mkdir("/emptydir", 0755)) |
| 1113 | }, |
| 1114 | path: "/emptydir", |
| 1115 | expected: [3]bool{true, true, true}, |
| 1116 | expectedError: nil, |
| 1117 | }, |
| 1118 | { |
| 1119 | name: "Non-Existent Path", |
| 1120 | setup: func(_ afero.Fs) {}, |
| 1121 | path: "/nonexistent", |
| 1122 | expected: [3]bool{false, false, false}, |
| 1123 | expectedError: nil, // no error, just not found |
| 1124 | }, |
| 1125 | { |
| 1126 | name: "Empty Path", |
| 1127 | setup: func(_ afero.Fs) {}, |
nothing calls this directly
no test coverage detected