Repository: googleapis/genai-toolbox
File: tests/dataform/dataform_integration_test.go (Go)

Code before:
		"tools": map[string]any{
			"my-dataform-compiler": map[string]any{
				"kind":        "dataform-compile-local",
				"description": "Tool to compile dataform projects",
			},
		},
	}

	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
	defer cancel()

	cmd, cleanupServer, err := tests.StartCmd(ctx, toolsFile)
	if err != nil {
		t.Fatalf("command initialization returned an error: %s", err)
	}
	defer cleanupServer()

	waitCtx, cancelWait := context.WithTimeout(ctx, 30*time.Second)
	defer cancelWait()
	out, err := testutils.WaitForString(waitCtx, regexp.MustCompile(`Server ready to serve`), cmd.Out)
	if err != nil {
		t.Logf("toolbox command logs: \n%s", out)
		t.Fatalf("toolbox didn't start successfully: %s", err)
	}

	nonExistentDir := filepath.Join(os.TempDir(), "non-existent-dir-for-test-12345")
	os.Remove(nonExistentDir)

	testCases := []struct {
		name       string
		reqBody    string
		wantStatus int
		wantBody   string // Substring to check for in the response
	}{
		{
			name:       "success case",
			reqBody:    fmt.Sprintf(`{"project_dir":"%s"}`, projectDir),
			wantStatus: http.StatusOK,
			wantBody:   "test_col",
		},
		{
			name:       "missing parameter",
			reqBody:    `{}`,
			wantStatus: http.StatusBadRequest,
			wantBody:   "parameter \\\"project_dir\\\" is required",
		},
		{
			name:       "non-existent directory",
			reqBody:    fmt.Sprintf(`{"project_dir":"%s"}`, nonExistentDir),
			wantStatus: http.StatusBadRequest,
			wantBody:   "error executing dataform compile",

Review comment (suggestion):
```suggestion
	nonExistentDir := filepath.Join(os.TempDir(), "non-existent-dir")
```

Code after:
		"tools": map[string]any{
			"my-dataform-compiler": map[string]any{
				"kind":        "dataform-compile-local",
				"description": "Tool to compile dataform projects",
			},
		},
	}

	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
	defer cancel()

	cmd, cleanupServer, err := tests.StartCmd(ctx, toolsFile)
	if err != nil {
		t.Fatalf("command initialization returned an error: %s", err)
	}
	defer cleanupServer()

	waitCtx, cancelWait := context.WithTimeout(ctx, 30*time.Second)
	defer cancelWait()
	out, err := testutils.WaitForString(waitCtx, regexp.MustCompile(`Server ready to serve`), cmd.Out)
	if err != nil {
		t.Logf("toolbox command logs: \n%s", out)
		t.Fatalf("toolbox didn't start successfully: %s", err)
	}

	nonExistentDir := filepath.Join(os.TempDir(), "non-existent-dir")

	testCases := []struct {
		name       string
		reqBody    string
		wantStatus int
		wantBody   string // Substring to check for in the response
	}{
		{
			name:       "success case",
			reqBody:    fmt.Sprintf(`{"project_dir":"%s"}`, projectDir),
			wantStatus: http.StatusOK,
			wantBody:   "test_col",
		},
		{
			name:       "missing parameter",
			reqBody:    `{}`,
			wantStatus: http.StatusBadRequest,
			wantBody:   `parameter \"project_dir\" is required`,
		},
		{
			name:       "non-existent directory",
			reqBody:    fmt.Sprintf(`{"project_dir":"%s"}`, nonExistentDir),
			wantStatus: http.StatusBadRequest,
			wantBody:   "error executing dataform compile",
		},