github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/core/api/endpoint/endpoint_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 endpoint 13 14 // TestEndpoint is the entrypoint for all testing unit testing of this package. 15 // The actual tests are in "github.com/documize/documize-sdk/exttest". 16 /* The tests require an environment specified by two environment variables: 17 "DOCUMIZEAPI" e.g. "http://localhost:5002" 18 "DOCUMIZEAUTH" e.g. "demo1:jim@davidson.com:demo123" 19 - the user for testing must have admin privilidges and a folder called 'TEST'. 20 */ 21 /* NOTE currently excluded from SDK and testing are endpoints requiring e-mail interaction: 22 InviteToFolder() 23 inviteNewUserToSharedFolder() 24 AcceptSharedFolder() 25 ForgotUserPassword() 26 ResetUserPassword() 27 ChangeUserPassword() 28 */ 29 30 /* TODO (Elliott) make tests work on an empty database 31 32 import ( 33 "os" 34 "strings" 35 "testing" 36 "time" 37 38 "github.com/documize/community/documize/api/plugins" 39 "github.com/documize/community/core/environment" 40 "github.com/documize/community/core/log" 41 42 "github.com/documize/community/sdk/exttest" 43 ) 44 45 func TestMain(m *testing.M) { 46 environment.Parse("db") // the database environment variables must be set 47 port = "5002" 48 testHost = "localhost" 49 testSetup() 50 x := m.Run() 51 testTeardown() 52 os.Exit(x) 53 } 54 55 func testSetup() { 56 path, err := os.Getwd() 57 if err != nil { 58 log.IfErr(err) 59 return 60 } 61 switch { 62 case strings.HasSuffix(path, "endpoint"): 63 err = os.Chdir("../../..") // everything needs to be run from the top level documize directory, as plugin paths are relative 64 if err != nil { 65 log.IfErr(err) 66 return 67 } 68 case strings.HasSuffix(path, "api"): 69 err = os.Chdir("../..") // everything needs to be run from the top level documize directory, as plugin paths are relative 70 if err != nil { 71 log.IfErr(err) 72 return 73 } 74 case strings.HasSuffix(path, "documize"): 75 err = os.Chdir("..") // everything needs to be run from the top level documize directory, as plugin paths are relative 76 if err != nil { 77 log.IfErr(err) 78 return 79 } 80 case strings.HasSuffix(path, "community"): 81 // in the right place 82 default: 83 log.Error("wrong directory? "+path, nil) 84 return 85 } 86 ready := make(chan struct{}, 1) 87 go Serve(ready) 88 <-ready 89 time.Sleep(time.Second) // just to let everything settle down 90 } 91 92 func testTeardown() { 93 log.IfErr(plugins.Lib.KillSubProcs()) 94 } 95 96 func TestEndpoint(t *testing.T) { 97 exttest.APItest(t) 98 } 99 100 func BenchmarkEndpoint(b *testing.B) { 101 for n := 0; n < b.N; n++ { 102 err := exttest.APIbenchmark() 103 if err != nil { 104 b.Error(err) 105 b.Fail() 106 } 107 } 108 } 109 110 */