| 177 | } |
| 178 | |
| 179 | func TestOpenOtherErrors(t *testing.T) { |
| 180 | tempName := filepath.Join(t.TempDir(), "test.log") |
| 181 | |
| 182 | tests := []struct { |
| 183 | msg string |
| 184 | paths []string |
| 185 | wantErr string |
| 186 | }{ |
| 187 | { |
| 188 | msg: "file with unexpected host", |
| 189 | paths: []string{"file://host01.test.com" + tempName}, |
| 190 | wantErr: "empty or use localhost", |
| 191 | }, |
| 192 | { |
| 193 | msg: "file with user on localhost", |
| 194 | paths: []string{"file://rms@localhost" + tempName}, |
| 195 | wantErr: "user and password not allowed", |
| 196 | }, |
| 197 | { |
| 198 | msg: "file url with fragment", |
| 199 | paths: []string{"file://localhost" + tempName + "#foo"}, |
| 200 | wantErr: "fragments not allowed", |
| 201 | }, |
| 202 | { |
| 203 | msg: "file url with query", |
| 204 | paths: []string{"file://localhost" + tempName + "?foo=bar"}, |
| 205 | wantErr: "query parameters not allowed", |
| 206 | }, |
| 207 | { |
| 208 | msg: "file with port", |
| 209 | paths: []string{"file://localhost:8080" + tempName}, |
| 210 | wantErr: "ports not allowed", |
| 211 | }, |
| 212 | } |
| 213 | |
| 214 | for _, tt := range tests { |
| 215 | t.Run(tt.msg, func(t *testing.T) { |
| 216 | _, cleanup, err := Open(tt.paths...) |
| 217 | if !assert.Error(t, err, "Open must fail.") { |
| 218 | cleanup() |
| 219 | return |
| 220 | } |
| 221 | |
| 222 | assert.ErrorContains(t, err, tt.wantErr, "Unexpected error opening paths %v.", tt.paths) |
| 223 | }) |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | type testWriter struct { |
| 228 | expected string |