code.gitea.io/gitea@v1.21.7/services/org/org_test.go (about)

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package org
     5  
     6  import (
     7  	"path/filepath"
     8  	"testing"
     9  
    10  	"code.gitea.io/gitea/models"
    11  	"code.gitea.io/gitea/models/db"
    12  	"code.gitea.io/gitea/models/organization"
    13  	"code.gitea.io/gitea/models/unittest"
    14  	user_model "code.gitea.io/gitea/models/user"
    15  
    16  	"github.com/stretchr/testify/assert"
    17  )
    18  
    19  func TestMain(m *testing.M) {
    20  	unittest.MainTest(m, &unittest.TestOptions{
    21  		GiteaRootPath: filepath.Join("..", ".."),
    22  	})
    23  }
    24  
    25  func TestDeleteOrganization(t *testing.T) {
    26  	assert.NoError(t, unittest.PrepareTestDatabase())
    27  	org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 6})
    28  	assert.NoError(t, DeleteOrganization(db.DefaultContext, org, false))
    29  	unittest.AssertNotExistsBean(t, &organization.Organization{ID: 6})
    30  	unittest.AssertNotExistsBean(t, &organization.OrgUser{OrgID: 6})
    31  	unittest.AssertNotExistsBean(t, &organization.Team{OrgID: 6})
    32  
    33  	org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
    34  	err := DeleteOrganization(db.DefaultContext, org, false)
    35  	assert.Error(t, err)
    36  	assert.True(t, models.IsErrUserOwnRepos(err))
    37  
    38  	user := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 5})
    39  	assert.Error(t, DeleteOrganization(db.DefaultContext, user, false))
    40  	unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{})
    41  }