github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/core/api/store/local_test.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 store
    13  
    14  import (
    15  	"github.com/documize/community/core/api/plugins"
    16  	"github.com/documize/community/core/api/util"
    17  	api "github.com/documize/community/core/convapi"
    18  	"github.com/documize/community/core/log"
    19  	"io/ioutil"
    20  	"os"
    21  	"strings"
    22  	"testing"
    23  )
    24  
    25  var lsp LocalStorageProvider
    26  
    27  func TestUpload(t *testing.T) {
    28  	jb := "job" + util.UniqueID()
    29  	fn := "file.txt"
    30  	cont := "content\n"
    31  	err := lsp.Upload(jb, fn, []byte(cont))
    32  	if err != nil {
    33  		t.Error(err)
    34  	}
    35  	b, e := ioutil.ReadFile(folderPath + jb + string(os.PathSeparator) + fn)
    36  	if e != nil {
    37  		t.Error(e)
    38  	}
    39  	if string(b) != cont {
    40  		t.Error("wrong content:" + string(b))
    41  	}
    42  }
    43  
    44  func TestConvert(t *testing.T) {
    45  	_, _, err :=
    46  		lsp.Convert(api.ConversionJobRequest{})
    47  	if err == nil {
    48  		t.Error("there should have been a convert error")
    49  	}
    50  
    51  	err = plugins.LibSetup()
    52  	if err == nil {
    53  		// t.Error("did not error with missing config.json")
    54  	}
    55  	defer log.IfErr(plugins.Lib.KillSubProcs())
    56  
    57  	jb := "job" + util.UniqueID()
    58  
    59  	_, _, err =
    60  		lsp.Convert(api.ConversionJobRequest{
    61  			Job:        jb,
    62  			IndexDepth: 9,
    63  			OrgID:      "Documize",
    64  		})
    65  	if err == nil {
    66  		t.Error("there should have been an error - directory not found")
    67  	}
    68  
    69  	fn := "content.html"
    70  	cont := "content\n"
    71  	err = lsp.Upload(jb, fn, []byte(cont))
    72  	if err != nil {
    73  		t.Error(err)
    74  	}
    75  	filename, fileResult, err :=
    76  		lsp.Convert(api.ConversionJobRequest{
    77  			Job:        jb,
    78  			IndexDepth: 9,
    79  			OrgID:      "Documize",
    80  		})
    81  	if err != nil {
    82  		t.Error(err)
    83  	}
    84  	if !strings.HasSuffix(filename, fn) {
    85  		t.Error("wrong filename:" + filename)
    86  	}
    87  	if fileResult.Excerpt != "content." {
    88  		t.Error("wrong excerpt:" + fileResult.Excerpt)
    89  	}
    90  }