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.

file_format_test.go 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package migration
  4. import (
  5. "strings"
  6. "testing"
  7. "github.com/santhosh-tekuri/jsonschema/v5"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestMigrationJSON_IssueOK(t *testing.T) {
  11. issues := make([]*Issue, 0, 10)
  12. err := Load("file_format_testdata/issue_a.json", &issues, true)
  13. assert.NoError(t, err)
  14. err = Load("file_format_testdata/issue_a.yml", &issues, true)
  15. assert.NoError(t, err)
  16. }
  17. func TestMigrationJSON_IssueFail(t *testing.T) {
  18. issues := make([]*Issue, 0, 10)
  19. err := Load("file_format_testdata/issue_b.json", &issues, true)
  20. if _, ok := err.(*jsonschema.ValidationError); ok {
  21. errors := strings.Split(err.(*jsonschema.ValidationError).GoString(), "\n")
  22. assert.Contains(t, errors[1], "missing properties")
  23. assert.Contains(t, errors[1], "poster_id")
  24. } else {
  25. t.Fatalf("got: type %T with value %s, want: *jsonschema.ValidationError", err, err)
  26. }
  27. }
  28. func TestMigrationJSON_MilestoneOK(t *testing.T) {
  29. milestones := make([]*Milestone, 0, 10)
  30. err := Load("file_format_testdata/milestones.json", &milestones, true)
  31. assert.NoError(t, err)
  32. }