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.

v287_test.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package v1_22 //nolint
  4. import (
  5. "fmt"
  6. "testing"
  7. "code.gitea.io/gitea/models/migrations/base"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func Test_UpdateBadgeColName(t *testing.T) {
  11. type Badge struct {
  12. ID int64 `xorm:"pk autoincr"`
  13. Description string
  14. ImageURL string
  15. }
  16. // Prepare and load the testing database
  17. x, deferable := base.PrepareTestEnv(t, 0, new(Badge))
  18. defer deferable()
  19. if x == nil || t.Failed() {
  20. return
  21. }
  22. oldBadges := []*Badge{
  23. {Description: "Test Badge 1", ImageURL: "https://example.com/badge1.png"},
  24. {Description: "Test Badge 2", ImageURL: "https://example.com/badge2.png"},
  25. {Description: "Test Badge 3", ImageURL: "https://example.com/badge3.png"},
  26. }
  27. for _, badge := range oldBadges {
  28. _, err := x.Insert(badge)
  29. assert.NoError(t, err)
  30. }
  31. if err := UseSlugInsteadOfIDForBadges(x); err != nil {
  32. assert.NoError(t, err)
  33. return
  34. }
  35. got := []BadgeUnique{}
  36. if err := x.Table("badge").Asc("id").Find(&got); !assert.NoError(t, err) {
  37. return
  38. }
  39. for i, e := range oldBadges {
  40. got := got[i+1] // 1 is in the badge.yml
  41. assert.Equal(t, e.ID, got.ID)
  42. assert.Equal(t, fmt.Sprintf("%d", e.ID), got.Slug)
  43. }
  44. // TODO: check if badges have been updated
  45. }