gitea源码

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