MCPcopy
hub / github.com/daptin/daptin / createServer

Function createServer

server_test.go:161–319  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

159 FileType: json`
160
161func createServer() (hostswitch.HostSwitch, *guerrilla.Daemon, task_scheduler.TaskScheduler, *resource.ConfigStore, *resource.CertificateManager, *server2.FtpServer, *ImapServer.Server, *olric.EmbeddedClient) {
162
163 log.SetOutput(ioutil.Discard)
164 dir := os.TempDir()
165 if dir[len(dir)-1] != os.PathSeparator {
166 dir = dir + string(os.PathSeparator)
167 }
168 tempDir := dir + "daptintest" + string(os.PathSeparator)
169 _ = os.Mkdir(tempDir, 0777)
170
171 schema := strings.Replace(testSchemas, "${imagePath}", tempDir, -1)
172 schema = strings.Replace(schema, "${rootPath}", tempDir, -1)
173
174 data := strings.Replace(testData, "${rootPath}", tempDir, -1)
175 fmt.Println(data)
176
177 m := make(map[string]interface{})
178 err := json.Unmarshal([]byte(data), &m)
179 log.Printf("Failed to unmarshal JSON data as map: %v, **%v**", err, data)
180
181 if err != nil {
182 fmt.Printf("Update path for windows")
183 tempDir = strings.ReplaceAll(tempDir, string(os.PathSeparator), string(os.PathSeparator)+string(os.PathSeparator))
184 data = strings.Replace(testData, "${rootPath}", tempDir, -1)
185 fmt.Println(data)
186 }
187
188 err = json.Unmarshal([]byte(data), &m)
189 log.Printf("Err: %v", err)
190
191 _ = os.Mkdir(tempDir+string(os.PathSeparator)+"gallery", 0777)
192 _ = os.Mkdir(tempDir+string(os.PathSeparator)+"gallery"+string(os.PathSeparator)+"images", 0777)
193
194 _ = ioutil.WriteFile(tempDir+string(os.PathSeparator)+"schema_test_daptin.yaml", []byte(schema), os.ModePerm)
195 _ = ioutil.WriteFile(tempDir+string(os.PathSeparator)+"initial_data.json", []byte(data), os.ModePerm)
196
197 _ = os.Setenv("DAPTIN_SCHEMA_FOLDER", tempDir)
198
199 _ = os.Remove("daptin_test.db")
200
201 var dbType = flag.String("db_type", "sqlite3", "Database to use: sqlite3/mysql/postgres")
202 var connectionString = flag.String("db_connection_string", "daptin_test.db", "\n\tSQLite: test.db\n"+
203 "\tMySql: <username>:<password>@tcp(<hostname>:<port>)/<db_name>\n"+
204 "\tPostgres: host=<hostname> port=<port> user=<username> password=<password> dbname=<db_name> sslmode=enable/disable")
205
206 var webDashboardSource = flag.String("dashboard", "daptinweb/dist/spa", "path to dist folder for daptin web dashboard")
207 //var assetsSource = flag.String("assets", "assets", "path to folder for assets")
208 var port = flag.String("port", ":6337", "Daptin port")
209 var runtimeMode = flag.String("runtime", "release", "Runtime for Gin: debug, test, release")
210
211 gin.SetMode(*runtimeMode)
212 gin.LoggerWithWriter(ioutil.Discard)
213
214 envy.Parse("DAPTIN") // looks for DAPTIN_PORT, DAPTIN_DASHBOARD, DAPTIN_DB_TYPE, DAPTIN_RUNTIME
215 flag.Parse()
216
217 stream.AddSink(&health.WriterSink{
218 Writer: os.Stdout,

Callers 1

ensureServerFunction · 0.85

Calls 15

SetConfigValueForMethod · 0.95
StopTasksMethod · 0.95
GetTLSConfigMethod · 0.95
GetDbConnectionFunction · 0.92
CheckErrFunction · 0.92
NewConfigStoreFunction · 0.92
MainFunction · 0.92
makeFunction · 0.85
MkdirMethod · 0.80
RemoveMethod · 0.80
ParseMethod · 0.80

Tested by

no test coverage detected