<commit_before>// Copyright 2014 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package collector

import (
	"github.com/tsuru/tsuru/app"
	"github.com/tsuru/tsuru/db"
	"github.com/tsuru/tsuru/provision"
	"labix.org/v2/mgo/bson"
	"launchpad.net/gocheck"
	"time"
)

var buildingApps = []string{"as_i_rise", "the_infanta"}
var runningApps = []string{"caravan", "bu2b", "carnies"}

func createApp(conn *db.Storage, name, state string) {
	a := app.App{
		Name:  name,
		Units: []app.Unit{{State: state}},
	}
	err := conn.Apps().Insert(&a)
	if err != nil {
		panic(err)
	}
}

func createApps(conn *db.Storage) {
	for _, name := range buildingApps {
		createApp(conn, name, provision.StatusBuilding.String())
	}
	for _, name := range runningApps {
		createApp(conn, name, provision.StatusStarted.String())
	}
}

func destroyApps(conn *db.Storage) {
	allApps := append(buildingApps, runningApps...)
	conn.Apps().Remove(bson.M{"name": bson.M{"$in": allApps}})
}

func (s *S) TestCollect(c *gocheck.C) {
	app1 := app.App{Name: "as_i_rise", Platform: "python"}
	app2 := app.App{Name: "the_infanta", Platform: "python"}
	s.provisioner.Provision(&app1)
	defer s.provisioner.Destroy(&app1)
	s.provisioner.Provision(&app2)<commit_msg>collector: fixed tests.<commit_after>// Copyright 2014 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package collector

import (
	"github.com/tsuru/tsuru/app"
	"github.com/tsuru/tsuru/db"
	"github.com/tsuru/tsuru/provision"
	"labix.org/v2/mgo/bson"
	"launchpad.net/gocheck"
	"time"
)

var buildingApps = []string{"as_i_rise", "the_infanta"}
var runningApps = []string{"caravan", "bu2b", "carnies"}

func createApp(conn *db.Storage, name, state string) {
	a := app.App{
		Name: name,
	}
	err := conn.Apps().Insert(&a)
	if err != nil {
		panic(err)
	}
}

func createApps(conn *db.Storage) {
	for _, name := range buildingApps {
		createApp(conn, name, provision.StatusBuilding.String())
	}
	for _, name := range runningApps {
		createApp(conn, name, provision.StatusStarted.String())
	}
}

func destroyApps(conn *db.Storage) {
	allApps := append(buildingApps, runningApps...)
	conn.Apps().Remove(bson.M{"name": bson.M{"$in": allApps}})
}

func (s *S) TestCollect(c *gocheck.C) {
	app1 := app.App{Name: "as_i_rise", Platform: "python"}
	app2 := app.App{Name: "the_infanta", Platform: "python"}
	s.provisioner.Provision(&app1)
	defer s.provisioner.Destroy(&app1)
	s.provisioner.Provision(&app2)
{'fraction_non_alphanumeric': 0.16628175519630484, 'fraction_numerical': 0.008468052347959968, 'mean_word_length': 4.613390928725702, 'pattern_counts': {'":': 4, '<': 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': '5361351', 'n_tokens_mistral': 1022, 'n_tokens_neox': 996, 'n_words': 216}