<commit_before>package modelhelper

import (
	"koding/db/models"
	"math/rand"
	"strconv"
	"testing"
	"time"

	"labix.org/v2/mgo/bson"
)

func createWorkspace() (*models.Workspace, error) {
	ws := &models.Workspace{
		ObjectId:     bson.NewObjectId(),
		Name:         "My Workspace",
		Slug:         "my-workspace",
		ChannelId:    strconv.FormatInt(rand.Int63(), 10),
		MachineUID:   bson.NewObjectId().Hex(),
		MachineLabel: "koding-vm-0",
		Owner:        "cihangir",
		RootPath:     "/home/cihangir",
		IsDefault:    true,
	}

	return ws, CreateWorkspace(ws)
}

func TestGetWorkspaceByChannelId(t *testing.T) {
	initMongoConn()
	defer Close()
	rand.Seed(time.Now().UnixNano())

	w, err := createWorkspace()
	if err != nil {
		t.Fatalf(err.Error())
	}

	w2, err := GetWorkspaceByChannelId(w.ChannelId)
	if err != nil {
		t.Fatalf(err.Error())
	}

	if w2 == nil {
		t.Fatalf("couldnt fetch workspace by channel id got nil, expected: %+v", w)
	}

	if w2.ObjectId.Hex() != w.ObjectId.Hex() {
		t.Fatalf("workspaces are not same: expected: %+v, got: ", w)
	}

	_, err = GetWorkspaceByChannelId(strconv.FormatInt(rand.Int63(), 10))
	if err == nil {
		t.Fatalf("we should not be able to find the WS")
	}
}
<commit_msg>modelhelper: remove fatals from workspace tests<commit_after>package modelhelper

import (
	"koding/db/models"
	"math/rand"
	"strconv"
	"testing"
	"time"

	"labix.org/v2/mgo/bson"
)

func createWorkspace() (*models.Workspace, error) {
	ws := &models.Workspace{
		ObjectId:     bson.NewObjectId(),
		Name:         "My Workspace",
		Slug:         "my-workspace",
		ChannelId:    strconv.FormatInt(rand.Int63(), 10),
		MachineUID:   bson.NewObjectId().Hex(),
		MachineLabel: "koding-vm-0",
		Owner:        "cihangir",
		RootPath:     "/home/cihangir",
		IsDefault:    true,
	}

	return ws, CreateWorkspace(ws)
}

func TestGetWorkspaceByChannelId(t *testing.T) {
	initMongoConn()
	defer Close()
	rand.Seed(time.Now().UnixNano())

	w, err := createWorkspace()
	if err != nil {
		t.Fatalf(err.Error())
	}

	w2, err := GetWorkspaceByChannelId(w.ChannelId)
	if err != nil {
		t.Errorf(err.Error())
	}

	if w2 == nil {
		t.Errorf("couldnt fetch workspace by channel id got nil, expected: %+v", w)
	}

	if w2.ObjectId.Hex() != w.ObjectId.Hex() {
		t.Errorf("workspaces are not same: expected: %+v, got: ", w)
	}

	_, err = GetWorkspaceByChannelId(strconv.FormatInt(rand.Int63(), 10))
	if err == nil {
		t.Errorf("we should not be able to find the WS")
	}
}

{'fraction_non_alphanumeric': 0.16219512195121952, 'fraction_numerical': 0.01056910569105691, 'mean_word_length': 3.574349442379182, 'pattern_counts': {'":': 0, '<': 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': '1457754', 'n_tokens_mistral': 997, 'n_tokens_neox': 958, 'n_words': 203}