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.

appstate_test.go 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package system
  4. import (
  5. "path/filepath"
  6. "testing"
  7. "code.gitea.io/gitea/models/unittest"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestMain(m *testing.M) {
  11. unittest.MainTest(m, &unittest.TestOptions{
  12. GiteaRootPath: filepath.Join("..", ".."),
  13. FixtureFiles: []string{""}, // load nothing
  14. })
  15. }
  16. type testItem1 struct {
  17. Val1 string
  18. Val2 int
  19. }
  20. func (*testItem1) Name() string {
  21. return "test-item1"
  22. }
  23. type testItem2 struct {
  24. K string
  25. }
  26. func (*testItem2) Name() string {
  27. return "test-item2"
  28. }
  29. func TestAppStateDB(t *testing.T) {
  30. assert.NoError(t, unittest.PrepareTestDatabase())
  31. as := &DBStore{}
  32. item1 := new(testItem1)
  33. assert.NoError(t, as.Get(item1))
  34. assert.Equal(t, "", item1.Val1)
  35. assert.EqualValues(t, 0, item1.Val2)
  36. item1 = new(testItem1)
  37. item1.Val1 = "a"
  38. item1.Val2 = 2
  39. assert.NoError(t, as.Set(item1))
  40. item2 := new(testItem2)
  41. item2.K = "V"
  42. assert.NoError(t, as.Set(item2))
  43. item1 = new(testItem1)
  44. assert.NoError(t, as.Get(item1))
  45. assert.Equal(t, "a", item1.Val1)
  46. assert.EqualValues(t, 2, item1.Val2)
  47. item2 = new(testItem2)
  48. assert.NoError(t, as.Get(item2))
  49. assert.Equal(t, "V", item2.K)
  50. }