<commit_before>package main

import (
	"net/http"
	"os"
	"testing"
	"time"

	"github.com/NebulousLabs/Sia/build"
)

// TestMain tries running the main executable using a few different commands.
func TestMain(t *testing.T) {
	if testing.Short() {
		t.SkipNow()
	}

	testDir := build.TempDir("siad", "TestMain")

	// Try running and closing an instance of siad.
	os.Args = []string{
		"siad",
		"-n",
		"-a",
		"localhost:45150",
		"-r",
		"localhost:45151",
		"-H",
		"localhost:45152",
		"-d",
		testDir,
	}
	go main()

	// Wait until the daemon has started and then send a kill signal to the
	// daemon.
	<-started
	time.Sleep(250 * time.Millisecond)
	resp, err := http.Get("http://localhost:45150/daemon/stop")
	if err != nil {
		t.Fatal(err)
	}
	if resp.StatusCode != http.StatusOK {
		t.Fatal(resp.StatusCode)
	}
	resp.Body.Close()

	// Try to run the siad version command.
	os.Args = []string{
		"siad",
		"version",
	}<commit_msg>use random ports in siad test<commit_after>package main

import (
	"net/http"
	"os"
	"testing"
	"time"

	"github.com/NebulousLabs/Sia/build"
)

// TestMain tries running the main executable using a few different commands.
func TestMain(t *testing.T) {
	if testing.Short() {
		t.SkipNow()
	}

	testDir := build.TempDir("siad", "TestMain")

	// Try running and closing an instance of siad.
	os.Args = []string{
		"siad",
		"-n",
		"-a",
		"localhost:45150",
		"-r",
		"localhost:0",
		"-H",
		"localhost:0",
		"-d",
		testDir,
	}
	go main()

	// Wait until the daemon has started and then send a kill signal to the
	// daemon.
	<-started
	time.Sleep(250 * time.Millisecond)
	resp, err := http.Get("http://localhost:45150/daemon/stop")
	if err != nil {
		t.Fatal(err)
	}
	if resp.StatusCode != http.StatusOK {
		t.Fatal(resp.StatusCode)
	}
	resp.Body.Close()

	// Try to run the siad version command.
	os.Args = []string{
		"siad",
		"version",
	}
{'fraction_non_alphanumeric': 0.16489361702127658, 'fraction_numerical': 0.02021276595744681, 'mean_word_length': 3.217488789237668, 'pattern_counts': {'":': 0, '<': 5, '<?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': '303671', 'n_tokens_mistral': 805, 'n_tokens_neox': 723, 'n_words': 187}