<commit_before>package kv

import (
	"os"
	"os/exec"

	"github.com/cerana/cerana/acomm"
	"github.com/cerana/cerana/internal/tests/common"
	"github.com/cerana/cerana/provider"
	"github.com/spf13/pflag"
	"github.com/spf13/viper"
)

// Mock is a mock KV provider
type Mock struct {
	kv  *KV
	dir string
	cmd *exec.Cmd
}

// NewMock starts up a kv backend server and instantiates a new kv.KV provider.
// The kv backend is started on the port provided as part of config.Address().
// Mock.Stop() should be called when testing is done in order to clean up.
func NewMock(config *provider.Config, tracker *acomm.Tracker) (*Mock, error) {
	s := common.Suite{}
	s.KVPrefix = "mock-kv-provider"
	s.KVCmdMaker = common.ConsulMaker
	s.SetupSuite()

	v := viper.New()
	flagset := pflag.NewFlagSet("mock-kv-provider", pflag.PanicOnError)
	conf := NewConfig(flagset, v)
	s.Require().NoError(flagset.Parse(nil))
	v.Set("service_name", "mock-kv-provider")
	v.Set("socket_dir", config.SocketDir())
	v.Set("coordinator_url", config.CoordinatorURL())
	v.Set("log_level", "fatal")
	v.Set("address", s.KVURL)
	s.Require().NoError(config.LoadConfig())
	s.Require().NoError(config.SetupLogging())

	kv, err := New(conf, tracker)
	if err != nil {
		return nil, err
	}

	return &Mock{kv: kv, cmd: s.KVCmd, dir: s.KVDir}, nil
}

// Stop will stop the kv and remove the temporary directory used for it's data
func (m *Mock) Stop() {
	_ = m.cmd.Process.Kill()
	_ = m.cmd.Wait()
	_ = os.RemoveAll(m.dir)
}<commit_msg>Fix kv mock provider embedded struct<commit_after>package kv

import (
	"os"
	"os/exec"

	"github.com/cerana/cerana/acomm"
	"github.com/cerana/cerana/internal/tests/common"
	"github.com/cerana/cerana/provider"
	"github.com/spf13/pflag"
	"github.com/spf13/viper"
)

// Mock is a mock KV provider
type Mock struct {
	*KV
	dir string
	cmd *exec.Cmd
}

// NewMock starts up a kv backend server and instantiates a new kv.KV provider.
// The kv backend is started on the port provided as part of config.Address().
// Mock.Stop() should be called when testing is done in order to clean up.
func NewMock(config *provider.Config, tracker *acomm.Tracker) (*Mock, error) {
	s := common.Suite{}
	s.KVPrefix = "mock-kv-provider"
	s.KVCmdMaker = common.ConsulMaker
	s.SetupSuite()

	v := viper.New()
	flagset := pflag.NewFlagSet("mock-kv-provider", pflag.PanicOnError)
	conf := NewConfig(flagset, v)
	s.Require().NoError(flagset.Parse(nil))
	v.Set("service_name", "mock-kv-provider")
	v.Set("socket_dir", config.SocketDir())
	v.Set("coordinator_url", config.CoordinatorURL())
	v.Set("log_level", "fatal")
	v.Set("address", s.KVURL)
	s.Require().NoError(config.LoadConfig())
	s.Require().NoError(config.SetupLogging())

	kv, err := New(conf, tracker)
	if err != nil {
		return nil, err
	}

	return &Mock{KV: kv, cmd: s.KVCmd, dir: s.KVDir}, nil
}

// Stop will stop the kv and remove the temporary directory used for it's data
func (m *Mock) Stop() {
	_ = m.cmd.Process.Kill()
	_ = m.cmd.Wait()
	_ = os.RemoveAll(m.dir)
}
{'fraction_non_alphanumeric': 0.15502839959906448, 'fraction_numerical': 0.0026729034413631807, 'mean_word_length': 4.144329896907217, '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': '7180247', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1127, 'n_words': 280}