Exemplo n.º 1
0
func TestDistributeScores(t *testing.T) {
	// Does not test if stored correctly, only the point calculation.
	var user *entities.User
	var ok bool

	repo, err := entities.NewRepo("testorg", "testrepo")
	if err != nil {
		t.Error("Failed to open new repo:", err)
		return
	}
	org, err := entities.NewOrganization("testorg")
	if err != nil {
		t.Error("Failed to open new org:", err)
		return
	}

	for _, dst := range distributeScoresTest {
		if user, ok = userList[dst.inUser]; !ok {
			user, err = entities.NewUser(dst.inUser)
			if err != nil {
				t.Error("Failed to open new user:"******"Want score %d for %s, but got %d.", dst.wantScore, dst.inUser, user.TotalScore)
		}

		if repo.GetUserScore(dst.inUser) != dst.wantScore {
			t.Errorf("Want score %d for %s in testrepo, but got %d.", dst.wantScore, dst.inUser, repo.GetUserScore(dst.inUser))
		}

		if org.GetUserScore(dst.inUser) != dst.wantScore {
			t.Errorf("Want score %d for %s in testorg, but got %d.", dst.wantScore, dst.inUser, org.GetUserScore(dst.inUser))
		}
	}

	// // Cleans up the saved obj
	// entities.GetUserStore().Erase("user1")
	// entities.GetRepoStore("testorg").Erase("testrepo")
	// entities.GetOrganizationStore().Erase("testorg")

	// checks panic on nil user value
	defer PanicHandler(false)

	DistributeScores(0, nil, nil, nil)
}
Exemplo n.º 2
0
// NewOrganization tries to fetch a organization from storage on disk or memory.
// If non exists with given name, it creates a new organization.
func NewOrganization(name string, readonly bool) (org *Organization, err error) {
	InMemoryOrgsLock.Lock()
	defer InMemoryOrgsLock.Unlock()

	if _, ok := InMemoryOrgs[name]; ok {
		org = InMemoryOrgs[name]
		if !readonly {
			org.Lock()
		}
		return org, nil
	}

	o, err := entities.NewOrganization(name)
	if err != nil {
		return nil, err
	}

	org = &Organization{
		Organization:         *o,
		IndividualLabFolders: make(map[int]string),
		GroupLabFolders:      make(map[int]string),
		PendingGroup:         make(map[int]interface{}),
		PendingRandomGroup:   make(map[string]interface{}),
		Groups:               make(map[string]interface{}),
		PendingUser:          make(map[string]interface{}),
		Members:              make(map[string]interface{}),
		Teachers:             make(map[string]interface{}),
		IndividualDeadlines:  make(map[int]time.Time),
		GroupDeadlines:       make(map[int]time.Time),
		IndividualLanguages:  make(map[int]int32),
		GroupLanguages:       make(map[int]int32),
		CodeReviewlist:       make([]int, 0),
		CI: CIOptions{
			Basepath: "/testground/src/github.com/" + name + "/",
			Secret:   fmt.Sprintf("%x", md5.Sum([]byte(name+time.Now().String()))),
		},
	}

	err = org.LoadStoredData(!readonly)
	if err != nil {
		if err.Error() != "No data in database" {
			return nil, err
		}
	}

	// Add the org to in memory mapper.
	InMemoryOrgs[org.Name] = org

	return org, nil
}