github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/sdk/exttest/loaddata.go (about)

     1  // Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
     2  //
     3  // This software (Documize Community Edition) is licensed under
     4  // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
     5  //
     6  // You can operate outside the AGPL restrictions by purchasing
     7  // Documize Enterprise Edition and obtaining a commercial license
     8  // by contacting <sales@documize.com>.
     9  //
    10  // https://documize.com
    11  
    12  package exttest
    13  
    14  import (
    15  	"testing"
    16  
    17  	api "github.com/documize/community/core/convapi"
    18  	"github.com/documize/community/sdk"
    19  )
    20  
    21  // loadData provides data-loading tests to be run locally or from the main Documize repo.
    22  func loadData(c *documize.Client, t *testing.T, testFolder string) string {
    23  	ret, err := c.LoadData(testFolder, "LoadDataTest", &api.DocumentConversionResponse{
    24  		//Err           error
    25  		PagesHTML: []byte{}, // If empty, use Pages
    26  		Pages: []api.Page{
    27  			{
    28  				Level: 1,                                    // uint64 // overall document is level 1, <H1> => level 2
    29  				Title: "Test Data Title top",                // string
    30  				Body:  []byte("This is the body of page 0"), // []byte
    31  			},
    32  			{
    33  				Level: 2,                                    // uint64 // overall document is level 1, <H1> => level 2
    34  				Title: "Test Data Title second",             // string
    35  				Body:  []byte("This is the body of page 1"), // []byte
    36  			},
    37  		},
    38  		EmbeddedFiles: []api.EmbeddedFile{
    39  			{
    40  				ID:   "TestID1",
    41  				Type: "txt",
    42  				Name: "test.txt",                            // do not change, used in exttest
    43  				Data: []byte("This is a test text file.\n"), // do not change, used in exttest
    44  			},
    45  			{
    46  				ID:   "TestID2",
    47  				Type: "go",
    48  				Name: "blob.go",
    49  				Data: []byte("// Package blob is a test go file.\npackage blob\n"),
    50  			},
    51  		},
    52  		Excerpt: "Ext Test Load Data - Excerpt",
    53  	})
    54  	if err != nil {
    55  		t.Error(err)
    56  	}
    57  
    58  	_, err = c.LoadData(testFolder, "LoadDataTest", &api.DocumentConversionResponse{
    59  		//Err           error
    60  		PagesHTML: []byte{}, // If empty, use Pages
    61  		Pages: []api.Page{
    62  			{
    63  				Level: 1, // overall document is level 1, <H1> => level 2
    64  				Title: "Test Data Title top",
    65  				Body:  []byte("This is the body of page 0"),
    66  			},
    67  		},
    68  		EmbeddedFiles: []api.EmbeddedFile{
    69  			{
    70  				ID:   "TestID1",
    71  				Type: "txt",
    72  				Name: "test", // wrong, does not have correct extension
    73  				Data: []byte("This is a test text file.\n"),
    74  			},
    75  		},
    76  		Excerpt: "Ext Test Load Data - Excerpt",
    77  	})
    78  	if err == nil {
    79  		t.Error("data load did not error on bad embedded file name")
    80  	} else {
    81  		t.Log("INFO: Bad embedded file name error:", err)
    82  	}
    83  
    84  	_, err = c.LoadData(testFolder, "LoadDataTest", &api.DocumentConversionResponse{})
    85  	if err == nil {
    86  		t.Error("data load did not error on no pages ")
    87  	} else {
    88  		t.Log("INFO: No pages error:", err)
    89  	}
    90  
    91  	return ret.BaseEntity.RefID
    92  }