<commit_before>package mock

import (
	"bytes"
	"database/sql"
	"net/http"
	"net/url"
	"sync"
	"testing"

	"github.com/prest/adapters"
	"github.com/prest/adapters/scanner"
	"github.com/prest/config"
)

// Item mock
type Item struct {
	Body    []byte
	Error   error
	IsCount bool
}

// Mock adapter
type Mock struct {
	mtx   *sync.RWMutex
	t     *testing.T
	Items []Item
}

// New mock
func New(t *testing.T) (m *Mock) {
	m = &Mock{
		mtx: &sync.RWMutex{},
		t:   t,
	}
	return
}

func (m *Mock) validate() {
	m.t.Helper()
	if len(m.Items) == 0 {
		m.t.Fatal("do not have any operations to perform")
	}
}

func (m *Mock) perform(query bool) (sc adapters.Scanner) {
	m.t.Helper()
	m.validate()
	m.mtx.Lock()
	item := m.Items[0]
	sc = &scanner.PrestScanner{
		Error:   item.Error,
		Buff:    bytes.NewBuffer(item.Body),
		IsQuery: query,
	}
	m.Items = m.Items[1:]
	m.mtx.Unlock()
	return
}

// TablePermissions mock
func (m *Mock) TablePermissions(table string, op string) (ok bool) {
	m.t.Helper()
	restrict := config.PrestConf.AccessConf.Restrict
	if !restrict {
		return true
	}

	tables := config.PrestConf.AccessConf.Tables
	for _, t := range tables {
		if t.Name == table {
			for _, p := range t.Permissions {
				if p == op {
					return true
				}
			}
		}
	}
	return false
}

// GetScript mock
func (m *Mock) GetScript(verb string, folder string, scriptName string) (script string, err error) {
	return
}

// ParseScript mock
func (m *Mock) ParseScript(scriptPath string, queryURL url.Values) (sqlQuery string, values []interface{}, err error) {
	return
}

// ExecuteScripts mock
func (m *Mock) ExecuteScripts(method string, sql string, values []interface{}) (sc adapters.Scanner) {
	return
}

// WhereByRequest mock
func (m *Mock) WhereByRequest(r *http.Request, initialPlaceholderID int) (whereSyntax string, values []interface{}, err error) {
	return
}

// ReturningByRequest mock
func (m *Mock) ReturningByRequest(r *http.Request) (ReturningSyntax string, err error) {
	return
}

// DatabaseClause mock
func (m *Mock) DatabaseClause(req *http.Request) (query string, hasCount bool) {
	m.t.Helper()
	m.validate()
	m.mtx.Lock()
	hasCount = m.Items[0].IsCount
	m.mtx.Unlock()
	return
}

// OrderByRequest mock
func (m *Mock) OrderByRequest(r *http.Request) (values string, err error) {
	return
}

// PaginateIfPossible mock
func (m *Mock) PaginateIfPossible(r *http.Request) (paginatedQuery string, err error) {
	return
}
<commit_msg>added missing GetTransaction on mock<commit_after>package mock

import (
	"bytes"
	"database/sql"
	"net/http"
	"net/url"
	"sync"
	"testing"

	"github.com/prest/adapters"
	"github.com/prest/adapters/scanner"
	"github.com/prest/config"
)

// Item mock
type Item struct {
	Body    []byte
	Error   error
	IsCount bool
}

// Mock adapter
type Mock struct {
	mtx   *sync.RWMutex
	t     *testing.T
	Items []Item
}

// New mock
func New(t *testing.T) (m *Mock) {
	m = &Mock{
		mtx: &sync.RWMutex{},
		t:   t,
	}
	return
}

func (m *Mock) validate() {
	m.t.Helper()
	if len(m.Items) == 0 {
		m.t.Fatal("do not have any operations to perform")
	}
}

func (m *Mock) perform(query bool) (sc adapters.Scanner) {
	m.t.Helper()
	m.validate()
	m.mtx.Lock()
	item := m.Items[0]
	sc = &scanner.PrestScanner{
		Error:   item.Error,
		Buff:    bytes.NewBuffer(item.Body),
		IsQuery: query,
	}
	m.Items = m.Items[1:]
	m.mtx.Unlock()
	return
}

// TablePermissions mock
func (m *Mock) TablePermissions(table string, op string) (ok bool) {
	m.t.Helper()
	restrict := config.PrestConf.AccessConf.Restrict
	if !restrict {
		return true
	}

	tables := config.PrestConf.AccessConf.Tables
	for _, t := range tables {
		if t.Name == table {
			for _, p := range t.Permissions {
				if p == op {
					return true
				}
			}
		}
	}
	return false
}

// GetScript mock
func (m *Mock) GetScript(verb string, folder string, scriptName string) (script string, err error) {
	return
}

// ParseScript mock
func (m *Mock) ParseScript(scriptPath string, queryURL url.Values) (sqlQuery string, values []interface{}, err error) {
	return
}

// ExecuteScripts mock
func (m *Mock) ExecuteScripts(method string, sql string, values []interface{}) (sc adapters.Scanner) {
	return
}

// WhereByRequest mock
func (m *Mock) WhereByRequest(r *http.Request, initialPlaceholderID int) (whereSyntax string, values []interface{}, err error) {
	return
}

// ReturningByRequest mock
func (m *Mock) ReturningByRequest(r *http.Request) (ReturningSyntax string, err error) {
	return
}

// DatabaseClause mock
func (m *Mock) DatabaseClause(req *http.Request) (query string, hasCount bool) {
	m.t.Helper()
	m.validate()
	m.mtx.Lock()
	hasCount = m.Items[0].IsCount
	m.mtx.Unlock()
	return
}

// OrderByRequest mock
func (m *Mock) OrderByRequest(r *http.Request) (values string, err error) {
	return
}

// PaginateIfPossible mock
func (m *Mock) PaginateIfPossible(r *http.Request) (paginatedQuery string, err error) {
	return
}

// GetTransaction mock
func (m *Mock) GetTransaction() (tx *sql.Tx, err error) {
	return
}

{'fraction_non_alphanumeric': 0.14162832566513303, 'fraction_numerical': 0.0016003200640128026, 'mean_word_length': 3.6904315196998123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3892380', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1863, 'n_words': 497}