summaryrefslogtreecommitdiffstats
path: root/test/xdsserver_test.go
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-07-25 16:02:30 +0200
committerClément Bénier <clement.benier@iot.bzh>2018-08-21 11:08:36 +0200
commitdb0df685e9dc40fdd53113caaac976d12fd73435 (patch)
treeaa6afac29dc79b23e087535b32574983aead237d /test/xdsserver_test.go
parentd3a41ad067e7752a835c71d9f91ddd7230cd648a (diff)
sdk_test: draft in progress
add tests for testing sdk - draft Change-Id: I81f2f4ff75d6256fd092afd5213ea4f3370fcc68 Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'test/xdsserver_test.go')
-rw-r--r--test/xdsserver_test.go67
1 files changed, 49 insertions, 18 deletions
diff --git a/test/xdsserver_test.go b/test/xdsserver_test.go
index f2b4d9d..5722d31 100644
--- a/test/xdsserver_test.go
+++ b/test/xdsserver_test.go
@@ -24,26 +24,44 @@ import (
"time"
common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib"
+ "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
)
//global client
var HTTPCli *common.HTTPClient
var logDir string
+var sdkDir string
-func initEnv() {
- cmd := exec.Command("killall", "-9", "xds-server")
- if err := cmd.Start(); err != nil {
- log.Fatal(err)
+func initEnv(launchProcess bool) {
+ if launchProcess {
+ cmd := exec.Command("killall", "-9", "xds-server")
+ if err := cmd.Start(); err != nil {
+ log.Fatal(err)
+ }
+ cmd.Wait()
}
- cmd.Wait()
rootTestLog := "/tmp/xds-server-test"
if err := os.Setenv(envRootCfgDir, rootTestLog); err != nil {
log.Fatal(err)
}
+ sdkDir = rootTestLog + "/sdks/"
+ if err := os.Setenv(envXdtSdk, sdkDir); err != nil {
+ log.Fatal(err)
+ }
+ if err := os.Setenv(envXdsServerWorkspaceDir, rootTestLog); err != nil {
+ log.Fatal(err)
+ }
+ if err := os.Setenv(envXdsServerRootCfgDir, rootTestLog); err != nil {
+ log.Fatal(err)
+ }
+ if err := os.Setenv("XDS_LOG_SILLY", "1"); err != nil {
+ log.Fatal(err)
+ }
os.RemoveAll(rootTestLog)
os.MkdirAll(rootTestLog, 0755)
logDir = rootTestLog + "/logs/"
os.MkdirAll(logDir, 0755)
+ os.MkdirAll(sdkDir, 0755)
}
func launchXdsServer(proc **os.Process) *os.File {
@@ -70,7 +88,7 @@ func getHTTPClient(lvl int) (*common.HTTPClient, *os.File) {
}
conf := common.HTTPClientConfig{
URLPrefix: "/api/v1",
- HeaderClientKeyName: "Xds-Test-Sid",
+ HeaderClientKeyName: "Xds-Sid",
CsrfDisable: true,
LogOut: file,
LogPrefix: "XDSSERVERTEST: ",
@@ -78,35 +96,48 @@ func getHTTPClient(lvl int) (*common.HTTPClient, *os.File) {
}
cli, err := common.HTTPNewClient(prefixURL, conf)
if err != nil {
- log.Print(err)
+ log.Fatal(err)
+ }
+ log.Printf("HTTP session ID : %v", cli.GetClientID())
+ var ver xsapiv1.Version
+ err = cli.Get("/version", &ver)
+ if err != nil {
+ log.Fatal(err)
}
return cli, file
}
func TestMain(m *testing.M) {
- initEnv()
+ launchProcess := true
+ log.Printf("TestMain: launchProcess is %v", launchProcess)
+ initEnv(launchProcess)
var proc *os.Process
- fileXdsServer := launchXdsServer(&proc)
- go func(p *os.Process) {
- if status, err := p.Wait(); err != nil {
- log.Fatalf("status=%v\n err=%v\n", status, err)
- }
- }(proc)
+ var fileXdsServer *os.File
+ if launchProcess {
+ fileXdsServer = launchXdsServer(&proc)
+ go func(p *os.Process) {
+ if status, err := p.Wait(); err != nil {
+ log.Fatalf("status=%v\n err=%v\n", status, err)
+ }
+ }(proc)
+ defer proc.Kill()
+ defer fileXdsServer.Close()
+ }
time.Sleep(1 * time.Second)
lvl := common.HTTPLogLevelDebug
var fileHTTPClient *os.File
HTTPCli, fileHTTPClient = getHTTPClient(lvl)
+ defer fileHTTPClient.Close()
+
+ log.Printf("HTTPCli id is %v", HTTPCli.GetClientID())
if HTTPCli == nil {
log.Fatal("HTTPCLi is nil")
}
res := m.Run()
- proc.Kill()
- fileXdsServer.Close()
- fileHTTPClient.Close()
- os.Exit(res)
+ defer os.Exit(res)
}
func init() {