2 * Copyright (C) 2017-2018 "IoT.bzh"
3 * Author Clément Bénier <clement.benier@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
26 common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib"
30 var HTTPCli *common.HTTPClient
34 cmd := exec.Command("killall", "-9", "xds-server")
35 if err := cmd.Start(); err != nil {
39 rootTestLog := "/tmp/xds-server-test"
40 if err := os.Setenv(envRootCfgDir, rootTestLog); err != nil {
43 os.RemoveAll(rootTestLog)
44 os.MkdirAll(rootTestLog, 0755)
45 logDir = rootTestLog + "/logs/"
46 os.MkdirAll(logDir, 0755)
49 func launchXdsServer(proc **os.Process) *os.File {
50 logFile := logDir + logFileXdsServer
51 file, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY, 0644)
55 tmpProc, err := os.StartProcess(argsProcess[0], argsProcess, &os.ProcAttr{
56 Files: []*os.File{os.Stdin, file, file},
65 func getHTTPClient(lvl int) (*common.HTTPClient, *os.File) {
66 logFile := logDir + logFileClient
67 file, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY, 0644)
71 conf := common.HTTPClientConfig{
73 HeaderClientKeyName: "Xds-Test-Sid",
76 LogPrefix: "XDSSERVERTEST: ",
79 cli, err := common.HTTPNewClient(prefixURL, conf)
86 func TestMain(m *testing.M) {
90 fileXdsServer := launchXdsServer(&proc)
91 go func(p *os.Process) {
92 if status, err := p.Wait(); err != nil {
93 log.Fatalf("status=%v\n err=%v\n", status, err)
96 time.Sleep(1 * time.Second)
98 lvl := common.HTTPLogLevelDebug
99 var fileHTTPClient *os.File
100 HTTPCli, fileHTTPClient = getHTTPClient(lvl)
103 log.Fatal("HTTPCLi is nil")
107 fileXdsServer.Close()
108 fileHTTPClient.Close()