<commit_before>package exec

import (
	"github.com/stretchr/testify/assert"
	"github.com/viant/toolbox/url"
	"testing"
)

func TestNewExtractRequest(t *testing.T) {
	{
		request := NewExtractRequest(url.NewResource("scp://127.0.0.1"), DefaultOptions(), NewExtractCommand("ls -al", "", nil, nil))
		assert.NotNil(t, request)
		assert.EqualValues(t, "ls -al", request.Commands[0].Command)
		assert.EqualValues(t, "scp://127.0.0.1", request.Target.URL)
	}

}

func TestRunRequest_Init(t *testing.T) {
	{
		request := NewExtractRequest(url.NewResource("scp://127.0.0.1"), DefaultOptions())
		assert.NotNil(t, request.Validate())
	}
	{
		request := NewExtractRequest(nil, DefaultOptions(), NewExtractCommand("ls -al", "", nil, nil))
		assert.NotNil(t, request.Validate())
	}
	{
		request := NewExtractRequest(url.NewResource("scp://127.0.0.1"), DefaultOptions(), NewExtractCommand("ls -al", "", nil, nil))
		assert.Nil(t, request.Validate())

	}
}

func TestRunRequest_AsExtractRequest(t *testing.T) {
	request := NewRunRequest(url.NewResource("scp://127.0.0.1"), false, "whoami", "$stdout:/awitas/ ? echo 'hello'")
	extract := request.AsExtractRequest()
	if assert.NotNil(t, extract) {
		assert.NotNil(t, request)
		assert.EqualValues(t, "whoami", extract.Commands[0].Command)
		assert.EqualValues(t, " echo 'hello'", extract.Commands[1].Command)
		assert.EqualValues(t, "$stdout:/awitas/ ", extract.Commands[1].When)
		assert.EqualValues(t, "scp://127.0.0.1", extract.Target.URL)
	}
}

func TestNewExtractRequestFromURL(t *testing.T) {
	{
		request, err := NewExtractRequestFromURL("test/extract/req1.json")
		if assert.Nil(t, err) {
			assert.NotNil(t, request)
			assert.EqualValues(t, "ls -al", request.Commands[0].Command)
			assert.EqualValues(t, "ls -al /home/", request.Commands[1].Command)
			assert.EqualValues(t, "$stdout:/home/", request.Commands[1].When)
			assert.EqualValues(t, "scp://127.0.0.1", request.Target.URL)
			assert.EqualValues(t, 3200, request.TimeoutMs)
		}
	}
}

func TestCommand_WhenAndCommand(t *testing.T) {
<commit_msg>patched test<commit_after>package exec

import (
	"github.com/stretchr/testify/assert"
	"github.com/viant/toolbox/url"
	"testing"
)

func TestNewExtractRequest(t *testing.T) {
	{
		request := NewExtractRequest(url.NewResource("scp://127.0.0.1"), DefaultOptions(), NewExtractCommand("ls -al", "", nil, nil))
		assert.NotNil(t, request)
		assert.EqualValues(t, "ls -al", request.Commands[0].Command)
		assert.EqualValues(t, "scp://127.0.0.1", request.Target.URL)
	}

}

func TestRunRequest_Init(t *testing.T) {
	{
		request := NewExtractRequest(url.NewResource("scp://127.0.0.1"), DefaultOptions())
		assert.NotNil(t, request.Validate())
	}
	{
		request := NewExtractRequest(nil, DefaultOptions(), NewExtractCommand("ls -al", "", nil, nil))
		assert.NotNil(t, request.Validate())
	}
	{
		request := NewExtractRequest(url.NewResource("scp://1172.16.31.10"), DefaultOptions(), NewExtractCommand("ls -al", "", nil, nil))
		assert.Nil(t, request.Validate())

	}
}

func TestRunRequest_AsExtractRequest(t *testing.T) {
	request := NewRunRequest(url.NewResource("scp://127.0.0.1"), false, "whoami", "$stdout:/awitas/ ? echo 'hello'")
	extract := request.AsExtractRequest()
	if assert.NotNil(t, extract) {
		assert.NotNil(t, request)
		assert.EqualValues(t, "whoami", extract.Commands[0].Command)
		assert.EqualValues(t, "echo 'hello'", extract.Commands[1].Command)
		assert.EqualValues(t, "$stdout:/awitas/ ", extract.Commands[1].When)
		assert.EqualValues(t, "scp://127.0.0.1", extract.Target.URL)
	}
}

func TestNewExtractRequestFromURL(t *testing.T) {
	{
		request, err := NewExtractRequestFromURL("test/extract/req1.json")
		if assert.Nil(t, err) {
			assert.NotNil(t, request)
			assert.EqualValues(t, "ls -al", request.Commands[0].Command)
			assert.EqualValues(t, "ls -al /home/", request.Commands[1].Command)
			assert.EqualValues(t, "$stdout:/home/", request.Commands[1].When)
			assert.EqualValues(t, "scp://127.0.0.1", request.Target.URL)
			assert.EqualValues(t, 3200, request.TimeoutMs)
		}
	}
}

func TestCommand_WhenAndCommand(t *testing.T) {

{'fraction_non_alphanumeric': 0.18740849194729137, 'fraction_numerical': 0.027330405075646658, 'mean_word_length': 4.966521106259098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 14, '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': '2348313', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1529, 'n_words': 227}