<commit_before>package places

import (
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"path/filepath"
	"testing"
)

func TestDetailsCallDo(t *testing.T) {
	ts := httptest.NewServer(http.HandlerFunc(handler))
	defer ts.Close()

	ts2 := httptest.NewServer(http.HandlerFunc(handler))
	ts2.Close()

	for _, test := range []struct {
		Name      string
		PlaceID   string
		Language  string
		Extension string
		URL       string
		Want      error
	}{
		{
			Name:      "OK Response",
			PlaceID:   "ChIJLU7jZClu5kcR4PcOOO6p3I0",
			Language:  "en",
			Extension: "review_summary",
			URL:       ts.URL,
			Want:      nil,
		},
		{
			Name:    "Invalid Request",
			PlaceID: "invalid_request",
			URL:     ts.URL,
			Want:    errors.New("INVALID_REQUEST"),
		},
		{
			Name:    "Non-OK Status",
			PlaceID: "notok",
			URL:     ts.URL,
			Want:    errors.New("bad resp 400: "),
		},
		{
			Name:    "Invalid JSON",
			PlaceID: "invalid_json",
			URL:     ts.URL,
			Want:    errors.New("json: cannot unmarshal string into Go value of type places.DetailsResponse"),
		},
		{
			Name:    "communication problem",
			PlaceID: "wrong",
			URL:     ts2.URL,
			Want: errors.New(
				"Get " + ts2.URL + "/details/json?key=testkey&placeid=wrong: dial tcp " + ts2.Listener.Addr().String() + ": getsockopt: connection refused",
			),<commit_msg>Rename the closed test server<commit_after>package places

import (
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"path/filepath"
	"testing"
)

func TestDetailsCallDo(t *testing.T) {
	// open a test server and immediatly close it
	// we do this to get a valid test URL later on in the communcation fault test
	cts := httptest.NewServer(http.HandlerFunc(handler))
	cts.Close()

	ts := httptest.NewServer(http.HandlerFunc(handler))
	defer ts.Close()

	for _, test := range []struct {
		Name      string
		PlaceID   string
		Language  string
		Extension string
		URL       string
		Want      error
	}{
		{
			Name:      "OK Response",
			PlaceID:   "ChIJLU7jZClu5kcR4PcOOO6p3I0",
			Language:  "en",
			Extension: "review_summary",
			URL:       ts.URL,
			Want:      nil,
		},
		{
			Name:    "Invalid Request",
			PlaceID: "invalid_request",
			URL:     ts.URL,
			Want:    errors.New("INVALID_REQUEST"),
		},
		{
			Name:    "Non-OK Status",
			PlaceID: "notok",
			URL:     ts.URL,
			Want:    errors.New("bad resp 400: "),
		},
		{
			Name:    "Invalid JSON",
			PlaceID: "invalid_json",
			URL:     ts.URL,
			Want:    errors.New("json: cannot unmarshal string into Go value of type places.DetailsResponse"),
		},
		{
			Name:    "communication problem",
			PlaceID: "wrong",
			URL:     cts.URL,
			Want: errors.New(
				"Get " + cts.URL + "/details/json?key=testkey&placeid=wrong: dial tcp " + cts.Listener.Addr().String() + ": getsockopt: connection refused",
			),
{'fraction_non_alphanumeric': 0.1389280677009873, 'fraction_numerical': 0.008110014104372355, 'mean_word_length': 2.7978580990629185, 'pattern_counts': {'":': 2, '<': 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': '7183784', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1032, 'n_words': 240}