<commit_before>package heroku

import (
	"encoding/json"
	"github.com/bgentry/testnet"
	"testing"
	"time"
)

//
// AppInfo()
//

const appMarshaled = `{
	"archived_at": "2012-01-01T12:00:00Z",
	"buildpack_provided_description": "Ruby/Rack",
	"created_at": "2012-01-01T12:00:00Z",
	"git_url": "<EMAIL>/example.git",
	"id": "01234567-89ab-cdef-0123-456789abcdef",
	"maintenance": true,
	"name": "example",
	"owner": {
		"email": "<EMAIL>",
		"id": "01234567-89ab-cdef-0123-456789abcdef"
	},
	"region": {
		"id": "01234567-89ab-cdef-0123-456789abcdef",
		"name": "us"
	},
	"released_at": "2012-01-01T12:00:00Z",
	"repo_size": 1,
	"slug_size": 1,
	"stack": {
		"id": "01234567-89ab-cdef-0123-456789abcdef",
		"name": "cedar"
	},
	"updated_at": "2012-01-01T12:00:00Z",
	"web_url": "http://example.herokuapp.com"
}`

func TestAppUnmarshal(t *testing.T) {
	var app App
	err := json.Unmarshal([]byte(appMarshaled), &app)
	if err != nil {
		t.Fatal(err)
	}

	if app.ArchivedAt == nil {
		t.Error("expected ArchivedAt to be set, was nil")
	} else if *app.ArchivedAt != time.Unix(int64(1325419200), int64(0)).UTC() {
		t.Errorf("expected ArchivedAt to be 2012-01-01T12:00:00Z, was %s", *app.ArchivedAt)
	}
	testStringsEqual(t, "app.Id", "01234567-89ab-cdef-0123-456789abcdef", app.Id)
	testStringsEqual(t, "app.Name", "example", app.Name)
	testStringsEqual(t, "app.Owner.Email", "<EMAIL>", app.Owner.Email)
	testStringsEqual(t, "app.Region.Name", "us", app.Region.Name)
	testStringsEqual(t, "app.Stack.Name", "cedar", app.Stack.Name)
}

var appInfoResponse = testnet.TestResponse{
	Status: 200,
	Body:   appMarshaled,
}
var appInfoRequest = newTestRequest("GET", "/apps/example", "", appInfoResponse)

func TestAppInfoSuccess(t *testing.T) {
	ts, handler, c := newTestServerAndClient(t, appInfoRequest)
	defer ts.Close()

	app, err := c.AppInfo("example")
	if err != nil {
		t.Fatal(err)
	}
	if !handler.AllRequestsCalled() {
		t.Errorf("not all expected requests were called")
	}
	if app == nil {
		t.Fatal("no app object returned")
	}
	var emptyapp App
	if *app == emptyapp {
		t.Errorf("returned app is empty")<commit_msg>fix test for new App stack schema<commit_after>package heroku

import (
	"encoding/json"
	"github.com/bgentry/testnet"
	"testing"
	"time"
)

//
// AppInfo()
//

const appMarshaled = `{
	"archived_at": "2012-01-01T12:00:00Z",
	"buildpack_provided_description": "Ruby/Rack",
	"created_at": "2012-01-01T12:00:00Z",
	"git_url": "<EMAIL>/example.git",
	"id": "01234567-89ab-cdef-0123-456789abcdef",
	"maintenance": true,
	"name": "example",
	"owner": {
		"email": "<EMAIL>",
		"id": "01234567-89ab-cdef-0123-456789abcdef"
	},
	"region": {
		"id": "01234567-89ab-cdef-0123-456789abcdef",
		"name": "us"
	},
	"released_at": "2012-01-01T12:00:00Z",
	"repo_size": 1,
	"slug_size": 1,
	"stack": "cedar",
	"updated_at": "2012-01-01T12:00:00Z",
	"web_url": "http://example.herokuapp.com"
}`

func TestAppUnmarshal(t *testing.T) {
	var app App
	err := json.Unmarshal([]byte(appMarshaled), &app)
	if err != nil {
		t.Fatal(err)
	}

	if app.ArchivedAt == nil {
		t.Error("expected ArchivedAt to be set, was nil")
	} else if *app.ArchivedAt != time.Unix(int64(1325419200), int64(0)).UTC() {
		t.Errorf("expected ArchivedAt to be 2012-01-01T12:00:00Z, was %s", *app.ArchivedAt)
	}
	testStringsEqual(t, "app.Id", "01234567-89ab-cdef-0123-456789abcdef", app.Id)
	testStringsEqual(t, "app.Name", "example", app.Name)
	testStringsEqual(t, "app.Owner.Email", "<EMAIL>", app.Owner.Email)
	testStringsEqual(t, "app.Region.Name", "us", app.Region.Name)
	testStringsEqual(t, "app.Stack", "cedar", app.Stack)
}

var appInfoResponse = testnet.TestResponse{
	Status: 200,
	Body:   appMarshaled,
}
var appInfoRequest = newTestRequest("GET", "/apps/example", "", appInfoResponse)

func TestAppInfoSuccess(t *testing.T) {
	ts, handler, c := newTestServerAndClient(t, appInfoRequest)
	defer ts.Close()

	app, err := c.AppInfo("example")
	if err != nil {
		t.Fatal(err)
	}
	if !handler.AllRequestsCalled() {
		t.Errorf("not all expected requests were called")
	}
	if app == nil {
		t.Fatal("no app object returned")
	}
	var emptyapp App
	if *app == emptyapp {
		t.Errorf("returned app is empty")
{'fraction_non_alphanumeric': 0.18946107784431138, 'fraction_numerical': 0.08622754491017964, 'mean_word_length': 4.744154057771665, 'pattern_counts': {'":': 40, '<': 9, '<?xml version=': 0, '>': 9, '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': '2672614', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1718, 'n_words': 320}