code.gitea.io/gitea@v1.19.3/modules/migration/file_format_test.go (about)

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