MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestGetInputSource

Function TestGetInputSource

cmd/gosqlx/cmd/stdin_utils_test.go:250–301  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

248}
249
250func TestGetInputSource(t *testing.T) {
251 // Create a temporary SQL file for testing
252 tmpFile, err := os.CreateTemp("", "test_*.sql")
253 if err != nil {
254 t.Fatalf("Failed to create temp file: %v", err)
255 }
256 defer os.Remove(tmpFile.Name())
257
258 testSQL := "SELECT * FROM users WHERE id = 1"
259 if _, err := tmpFile.Write([]byte(testSQL)); err != nil {
260 t.Fatalf("Failed to write to temp file: %v", err)
261 }
262 tmpFile.Close()
263
264 tests := []struct {
265 name string
266 arg string
267 wantErr bool
268 wantSrc string
269 }{
270 {
271 name: "file path",
272 arg: tmpFile.Name(),
273 wantErr: false,
274 wantSrc: tmpFile.Name(),
275 },
276 {
277 name: "direct SQL",
278 arg: "SELECT * FROM users",
279 wantErr: false,
280 wantSrc: "direct input",
281 },
282 {
283 name: "empty input",
284 arg: "",
285 wantErr: true,
286 },
287 }
288
289 for _, tt := range tests {
290 t.Run(tt.name, func(t *testing.T) {
291 result, err := GetInputSource(tt.arg)
292 if (err != nil) != tt.wantErr {
293 t.Errorf("GetInputSource() error = %v, wantErr %v", err, tt.wantErr)
294 return
295 }
296 if !tt.wantErr && result.Source != tt.wantSrc {
297 t.Errorf("GetInputSource() source = %v, want %v", result.Source, tt.wantSrc)
298 }
299 })
300 }
301}
302
303// Benchmark tests
304func BenchmarkValidateStdinInput(b *testing.B) {

Callers

nothing calls this directly

Calls 7

WriteMethod · 0.80
RunMethod · 0.80
GetInputSourceFunction · 0.70
FatalfMethod · 0.65
NameMethod · 0.65
ErrorfMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected