<commit_before>package fritz

import (
	"io"
	"log"
	"net/http"
	"net/http/httptest"
	"net/url"
	"os"
	"reflect"
	"runtime"
	"testing"

	"fmt"

	"github.com/stretchr/testify/assert"
)

// TestFritzAPI test the FRITZ API.
func TestFritzAPI(t *testing.T) {

	serverAnswering := func(answers ...string) *httptest.Server {
		it := 0
		server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			ch, err := os.Open(answers[it%len(answers)])
			defer ch.Close()
			it++
			if err != nil {
				w.WriteHeader(500)
				w.Write([]byte(err.Error()))
			}
			io.Copy(w, ch)
		}))
		return server
	}

	client := func() *Client {
		cl, err := NewClient("testdata/config_localhost_test.json")
		if err != nil {
			panic(err)
		}
		return cl
	}

	testCases := []struct {
		client *Client
		server *httptest.Server
		dotest func(t *testing.T, fritz *fritzImpl, server *httptest.Server)
	}{
		{
			client: client(),
			server: serverAnswering("testdata/examplechallenge_test.xml", "testdata/examplechallenge_sid_test.xml"),
			dotest: testGetWithAin,
		},
		{
			client: client(),
			server: serverAnswering("testdata/examplechallenge_sid_test.xml", "testdata/examplechallenge_sid_test.xml", "testdata/devicelist_test.xml"),<commit_msg>fix race in test server<commit_after>package fritz

import (
	"io"
	"log"
	"net/http"
	"net/http/httptest"
	"net/url"
	"os"
	"reflect"
	"runtime"
	"sync/atomic"
	"testing"

	"fmt"

	"github.com/stretchr/testify/assert"
)

// TestFritzAPI test the FRITZ API.
func TestFritzAPI(t *testing.T) {

	serverAnswering := func(answers ...string) *httptest.Server {
		it := uint32(0)
		server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			ch, err := os.Open(answers[int(atomic.LoadUint32(&it))%len(answers)])
			defer ch.Close()
			atomic.AddUint32(&it, 1)
			if err != nil {
				w.WriteHeader(500)
				w.Write([]byte(err.Error()))
			}
			io.Copy(w, ch)
		}))
		return server
	}

	client := func() *Client {
		cl, err := NewClient("testdata/config_localhost_test.json")
		if err != nil {
			panic(err)
		}
		return cl
	}

	testCases := []struct {
		client *Client
		server *httptest.Server
		dotest func(t *testing.T, fritz *fritzImpl, server *httptest.Server)
	}{
		{
			client: client(),
			server: serverAnswering("testdata/examplechallenge_test.xml", "testdata/examplechallenge_sid_test.xml"),
			dotest: testGetWithAin,
		},
		{
			client: client(),
			server: serverAnswering("testdata/examplechallenge_sid_test.xml", "testdata/examplechallenge_sid_test.xml", "testdata/devicelist_test.xml"),
{'fraction_non_alphanumeric': 0.15514592933947774, 'fraction_numerical': 0.00576036866359447, 'mean_word_length': 4.097847358121331, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '883248', 'n_tokens_mistral': 1120, 'n_tokens_neox': 988, 'n_words': 177}