<commit_before>package github

import (
	"fmt"
	"testing"
)

func TestCreateDestroyRepo(t *testing.T) {
	t.Parallel()
	if Login == "" {
		TestGetUser(t)
	}

	repo := TestPrefix + Faker.UserName()
	req := Client.NewRequest(t, "POST", "/user/repos")
	req.SetBodyString(fmt.Sprintf(`{"name": %q}`, repo))
	resp := Client.Do(t, req, 201)

	req = Client.NewRequest(t, "DELETE", "/repos/"+Login+"/"+repo)
	resp = Client.Do(t, req, 204)
	_ = resp
}
<commit_msg>Add JSON test.<commit_after>package github

import (
	"fmt"
	"testing"

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

func TestCreateDestroyRepo(t *testing.T) {
	t.Parallel()
	if Login == "" {
		TestGetUser(t)
	}

	// create repo
	repo := TestPrefix + Faker.UserName()
	req := Client.NewRequest(t, "POST", "/user/repos")
	req.SetBodyString(fmt.Sprintf(`{"name": %q}`, repo))
	resp := Client.Do(t, req, 201)

	// check created repo
	o, err := jason.NewObjectFromReader(resp.Body)
	assert.Nil(t, err)
	login, err := o.GetString("owner", "login")
	assert.Nil(t, err)
	assert.Equal(t, Login, login)
	name, err := o.GetString("name")
	assert.Nil(t, err)
	assert.Equal(t, repo, name)
	name, err = o.GetString("full_name")
	assert.Nil(t, err)
	assert.Equal(t, Login+"/"+repo, name)

	// try to create repo with the same name again
	req = Client.NewRequest(t, "POST", "/user/repos")
	req.SetBodyString(fmt.Sprintf(`{"name": %q}`, repo))
	resp = Client.Do(t, req, 422)

	// check response
	o, err = jason.NewObjectFromReader(resp.Body)
	assert.Nil(t, err)
	message, err := o.GetString("message")
	assert.Nil(t, err)
	assert.Equal(t, "Validation Failed", message)
	errors, err := o.GetObjectArray("errors")
	assert.Nil(t, err)
	assert.Len(t, errors, 1)
	expected := `{
		"resource": "Repository",
		"code": "custom",
		"field": "name",
		"message": "name already exists on this account"
	}`
	assert.JSONEq(t, expected, errors[0].String())

	// destroy repo
	req = Client.NewRequest(t, "DELETE", "/repos/"+Login+"/"+repo)
	Client.Do(t, req, 204)
}

{'fraction_non_alphanumeric': 0.1934685799109352, 'fraction_numerical': 0.008411677387431964, 'mean_word_length': 4.435483870967742, 'pattern_counts': {'":': 7, '<': 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': '2208813', 'n_tokens_mistral': 809, 'n_tokens_neox': 779, 'n_words': 170}