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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 appstate
  5. import (
  6. "path/filepath"
  7. "testing"
  8. "code.gitea.io/gitea/models/unittest"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestMain(m *testing.M) {
  12. unittest.MainTest(m, filepath.Join("..", ".."), "")
  13. }
  14. type testItem1 struct {
  15. Val1 string
  16. Val2 int
  17. }
  18. func (*testItem1) Name() string {
  19. return "test-item1"
  20. }
  21. type testItem2 struct {
  22. K string
  23. }
  24. func (*testItem2) Name() string {
  25. return "test-item2"
  26. }
  27. func TestAppStateDB(t *testing.T) {
  28. assert.NoError(t, unittest.PrepareTestDatabase())
  29. as := &DBStore{}
  30. item1 := new(testItem1)
  31. assert.NoError(t, as.Get(item1))
  32. assert.Equal(t, "", item1.Val1)
  33. assert.EqualValues(t, 0, item1.Val2)
  34. item1 = new(testItem1)
  35. item1.Val1 = "a"
  36. item1.Val2 = 2
  37. assert.NoError(t, as.Set(item1))
  38. item2 := new(testItem2)
  39. item2.K = "V"
  40. assert.NoError(t, as.Set(item2))
  41. item1 = new(testItem1)
  42. assert.NoError(t, as.Get(item1))
  43. assert.Equal(t, "a", item1.Val1)
  44. assert.EqualValues(t, 2, item1.Val2)
  45. item2 = new(testItem2)
  46. assert.NoError(t, as.Get(item2))
  47. assert.Equal(t, "V", item2.K)
  48. }