You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

org_test.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package org
  5. import (
  6. "path/filepath"
  7. "testing"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/models/unittest"
  10. user_model "code.gitea.io/gitea/models/user"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestMain(m *testing.M) {
  14. unittest.MainTest(m, filepath.Join("..", ".."))
  15. }
  16. func TestDeleteOrganization(t *testing.T) {
  17. assert.NoError(t, unittest.PrepareTestDatabase())
  18. org := unittest.AssertExistsAndLoadBean(t, &models.Organization{ID: 6}).(*models.Organization)
  19. assert.NoError(t, DeleteOrganization(org))
  20. unittest.AssertNotExistsBean(t, &models.Organization{ID: 6})
  21. unittest.AssertNotExistsBean(t, &models.OrgUser{OrgID: 6})
  22. unittest.AssertNotExistsBean(t, &models.Team{OrgID: 6})
  23. org = unittest.AssertExistsAndLoadBean(t, &models.Organization{ID: 3}).(*models.Organization)
  24. err := DeleteOrganization(org)
  25. assert.Error(t, err)
  26. assert.True(t, models.IsErrUserOwnRepos(err))
  27. user := unittest.AssertExistsAndLoadBean(t, &models.Organization{ID: 5}).(*models.Organization)
  28. assert.Error(t, DeleteOrganization(user))
  29. unittest.CheckConsistencyFor(t, &user_model.User{}, &models.Team{})
  30. }