<commit_before>package agent

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net"
	"net/http"
	"net/http/httptest"
	"os"
	"path/filepath"
	"runtime"
	"strconv"
	"strings"
	"testing"
	"time"

	"github.com/hashicorp/consul/consul/structs"
	"github.com/hashicorp/consul/logger"
	"github.com/hashicorp/consul/testutil"
	"github.com/hashicorp/go-cleanhttp"
)

func makeHTTPServer(t *testing.T) (string, *HTTPServer) {
	return makeHTTPServerWithConfig(t, nil)
}

func makeHTTPServerWithConfig(t *testing.T, cb func(c *Config)) (string, *HTTPServer) {
	return makeHTTPServerWithConfigLog(t, cb, nil, nil)
}

func makeHTTPServerWithACLs(t *testing.T) (string, *HTTPServer) {
	return makeHTTPServerWithConfig(t, func(c *Config) {
		c.ACLDatacenter = c.Datacenter
		c.ACLDefaultPolicy = "deny"
		c.ACLMasterToken = "root"
		c.ACLAgentToken = "root"
		c.ACLAgentMasterToken = "<PASSWORD>"
		c.ACLEnforceVersion8 = Bool(true)
	})
}

func makeHTTPServerWithConfigLog(t *testing.T, cb func(c *Config), l io.Writer, logWriter *logger.LogWriter) (string, *HTTPServer) {
	configTry := 0
RECONF:
	configTry += 1
	conf := nextConfig()
	if cb != nil {
		cb(conf)
	}

	dir, agent := makeAgentLog(t, conf, l, logWriter)
	servers, err := NewHTTPServers(agent, conf, agent.logOutput)
	if err != nil {
		if configTry < 3 {
			goto RECONF
		}<commit_msg>Adds a leader wait when testing with ACLs.<commit_after>package agent

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net"
	"net/http"
	"net/http/httptest"
	"os"
	"path/filepath"
	"runtime"
	"strconv"
	"strings"
	"testing"
	"time"

	"github.com/hashicorp/consul/consul/structs"
	"github.com/hashicorp/consul/logger"
	"github.com/hashicorp/consul/testutil"
	"github.com/hashicorp/go-cleanhttp"
)

func makeHTTPServer(t *testing.T) (string, *HTTPServer) {
	return makeHTTPServerWithConfig(t, nil)
}

func makeHTTPServerWithConfig(t *testing.T, cb func(c *Config)) (string, *HTTPServer) {
	return makeHTTPServerWithConfigLog(t, cb, nil, nil)
}

func makeHTTPServerWithACLs(t *testing.T) (string, *HTTPServer) {
	dir, srv := makeHTTPServerWithConfig(t, func(c *Config) {
		c.ACLDatacenter = c.Datacenter
		c.ACLDefaultPolicy = "deny"
		c.ACLMasterToken = "root"
		c.ACLAgentToken = "root"
		c.ACLAgentMasterToken = "<PASSWORD>"
		c.ACLEnforceVersion8 = Bool(true)
	})

	// Need a leader to look up ACLs, so wait here so we don't need to
	// repeat this in each test.
	testutil.WaitForLeader(t, srv.agent.RPC, "dc1")
	return dir, srv
}

func makeHTTPServerWithConfigLog(t *testing.T, cb func(c *Config), l io.Writer, logWriter *logger.LogWriter) (string, *HTTPServer) {
	configTry := 0
RECONF:
	configTry += 1
	conf := nextConfig()
	if cb != nil {
		cb(conf)
	}

	dir, agent := makeAgentLog(t, conf, l, logWriter)
	servers, err := NewHTTPServers(agent, conf, agent.logOutput)
	if err != nil {
		if configTry < 3 {
			goto RECONF
		}
{'fraction_non_alphanumeric': 0.1437435367114788, 'fraction_numerical': 0.0031023784901758012, 'mean_word_length': 4.602316602316602, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '2069698', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1186, 'n_words': 248}