<commit_before>package appbase

import (
	"testing"
)

const URL string = "https://scalr.api.appbase.io"
const username string = "QEVrcElba"
const password string = "<PASSWORD>"
const appname string = "es2test1"

const testtype string = "tweet2"
const tweet1 string = `{"user":"sacheendra","message":"I am a robot."}`
const tweet2 string = `{"user":"sacheendra","message":"I am not a robot."}`
const query1 string = `{"query":{"match_all":{}}}`

var client *Client

func TestAppbase(t *testing.T) {
	var err error
	client, err = NewClient(URL, username, password, appname)
	if err != nil {
		t.Error(err)
		return
	}

	_, err = client.Index().Type(testtype).Id("2").Body(tweet1).Do()
	if err != nil {
		t.Error(err)
		return
	}

	res, err := client.Delete().Type(testtype).Id("2").Do()
	if err != nil {
		t.Error(err)
		return
	}
	if !res.Found {
		t.Error("Document not found")
		return
	}

	// Test Pretty()
	_, err = client.Index().Type(testtype).Id("2").Body(tweet1).Pretty().Do()
	if err != nil {
		t.Error(err)
		return
	}

	_, err = client.Get().Type(testtype).Id("2").Pretty().Do()
	if err != nil {
		t.Error(err)
		return
	}

	_, err = client.Get().Type(testtype).Id("2").Do()
	if err != nil {
		t.Error(err)
		return
	}

	_, err = client.GetStream().Type(testtype).Id("2").Pretty().Do()
	if err != nil {
		t.Error(err)
		return
	}

	_, err = client.GetStream().Type(testtype).Id("2").Do()
	if err != nil {
		t.Error(err)
		return
	}

	_, err = client.Update().Type(testtype).Id("2").Body(tweet2).Do()
	if err != nil {
		t.Error(err)
		return
	}

	_, err = client.Update().Type(testtype).Id("2").Body(tweet1).Pretty().Do()
	if err != nil {
		t.Error(err)
		return
	}

	_, err = client.SearchStream().SearchService.Type(testtype).Body(query1).Do()
	if err != nil {
		t.Error(err)
		return
	}

	_, err = client.SearchStream().SearchService.Type(testtype).Body(query1).Pretty().Do()
	if err != nil {
		t.Error(err)
		return
	}

	resPretty, err := client.Delete().Type(testtype).Id("2").Pretty().Do()
	if err != nil {
		t.Error(err)
		return
	}
	if !resPretty.Found {
		t.Error("Document not found")
		return
	}

}<commit_msg>Added tests for Pretty printing.<commit_after>package appbase

import (
	"fmt"
	"testing"
)

const URL string = "https://scalr.api.appbase.io"
const username string = "HnnFbzaRq"
const password string = "<PASSWORD>"
const appname string = "go-appbase-tests"

const testtype string = "tweet"
const tweet1 string = `{"user":"sacheendra","message":"I am a robot."}`
const tweet2 string = `{"user":"sacheendra","message":"I am not a robot."}`
const query1 string = `{"query":{"match_all":{}}}`

var client *Client

func TestAppbase(t *testing.T) {
	var err error
	client, err = NewClient(URL, username, password, appname)
	if err != nil {
		t.Error(err)
		return
	}

	_, err = client.Index().Type(testtype).Id("2").Body(tweet1).Do()
	if err != nil {
		t.Error(err)
		return
	}

	res, err := client.Delete().Type(testtype).Id("2").Do()
	if err != nil {
		t.Error(err)
		return
	}
	if !res.Found {
		t.Error("Document not found")
		return
	}

	// Test Pretty()

	indexResponse, err := client.Index().Type(testtype).Id("1").Body(tweet1).Pretty().Do()
	if err != nil {
		t.Error(err)
		return
	}
	fmt.Println("Index() Response with Pretty():")
	fmt.Println(*indexResponse)

	/*
		No documents are returned, hence nothing gets pretty printed
		Output:
		{go-appbase-tests tweet 1 1 true}
	*/

	response, err := client.Get().Type(testtype).Id("1").Pretty().Do()
	if err != nil {
		t.Error(err)
		return
	}
	fmt.Println("Get() Response with Pretty()")
	fmt.Println(string(*response.Source))
	/* Output:
	{
		"user" : "sacheendra",
		"message" : "I am a robot."
	}
	*/

	responseGet, err := client.Get().Type(testtype).Id("1").Do()
	if err != nil {
		t.Error(err)
		return
	}
	fmt.Println("Get() Response without Pretty()")
	fmt.Println(string(*responseGet.Source))
	/*
		Output:
		{"user":"sacheendra","message":"I am a robot."}
	*/

	getStreamer, _ := client.GetStream().GetService.Type(testtype).Id("1").Pretty().Do()
	_, err = client.Index().Type(testtype).Id("2").Body(tweet2).Do()
	if err != nil {
		t.Error(err)
		return
	}
	getStreamResponse := *getStreamer.Source
	fmt.Println("GetStream() Response with Pretty()")
	fmt.Println(string(getStreamResponse))

	/*
		Output:
		{
			"user" : "sacheendra",
			"message" : "I am a robot"
		}
	*/

	searchResponse, err := client.Search().Type(testtype).Body(query1).Pretty().Do()
	if err != nil {
		t.Error(err)
		return
	}
	fmt.Println("Search() Response with Pretty()")
	fmt.Println(string(*searchResponse.Hits.Hits[0].Source))

	/*
		Output:
		{
			"user" : "sacheendra",
			"message" : "I am a robot"
		}
	*/

	searchResponse, err = client.Search().Type(testtype).Body(query1).Do()
	if err != nil {
		t.Error(err)
		return
	}
	fmt.Println("Search() Response without Pretty()")
	fmt.Println(string(*searchResponse.Hits.Hits[0].Source))

	/*
		Output:
		{"user" : "sacheendra","message" : "I am a robot"}
	*/

	searchStreamResponse, err := client.SearchStream().SearchService.Type(testtype).Body(query1).Pretty().Do()
	if err != nil {
		t.Error(err)
		return
	}
	_, err = client.Index().Type(testtype).Id("2").Body(tweet2).Do()
	if err != nil {
		t.Error(err)
		return
	}
	docResponse := *searchStreamResponse.Hits.Hits[0].Source
	fmt.Println("SearchStream() Response with Pretty()")
	fmt.Println(string(docResponse))

	/*
		Output:
		{
			"user" : "sacheendra",
			"message" : "I am not a robot"
		}
	*/

	deleteResponse, err := client.Delete().Type(testtype).Id("2").Pretty().Do()
	if err != nil {
		t.Error(err)
		return
	}
	if !deleteResponse.Found {
		t.Error("Document not found")
		return
	}
	fmt.Println("Delete() Response with Pretty()")
	fmt.Println(*deleteResponse)

	/*
		No Documents are returned hence nothing gets pretty printed.
		Output:
		{go-appbase-tests tweet 2 7 true}
	*/

}
{'fraction_non_alphanumeric': 0.19205862304021815, 'fraction_numerical': 0.0081799591002045, 'mean_word_length': 3.8665008291873963, 'pattern_counts': {'":': 14, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '6224128', 'n_tokens_mistral': 2334, 'n_tokens_neox': 2177, 'n_words': 451}