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.
27 "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
28 "github.com/stretchr/testify/assert"
31 func InitExec(t *testing.T) string {
32 helloworldDir := path.Join(os.Getenv(envRootCfgDir), "helloworld")
33 cmd := exec.Command("cp", "-r", helloworldFixturesDir, helloworldDir)
36 assert.Nil(t, cmd.Run())
37 subHelloworldAppTemplateDir := path.Join(helloworldDir, "conf.d", "app-templates")
38 cmd = exec.Command("git", "clone", "https://gerrit.automotivelinux.org/gerrit/p/apps/app-templates.git", subHelloworldAppTemplateDir)
39 assert.Nil(t, cmd.Run())
43 /*flush channel with timeout*/
44 func flushChannelExec(channel chan xsapiv1.ExecOutMsg, ms time.Duration) {
49 case <-time.After(ms * time.Millisecond):
54 func TestExec(t *testing.T) {
55 helloworldDir := InitExec(t)
57 var cfgArray []xsapiv1.FolderConfig
58 assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
59 assert.Equal(t, len(cfgArray), 0)
61 fPrj := xsapiv1.FolderConfig{
63 ClientPath: helloworldDir,
64 Type: xsapiv1.TypePathMap,
65 ClientData: "clientdatatest",
66 DataPathMap: xsapiv1.PathMapConfig{
67 ServerPath: helloworldDir,
70 var cfg xsapiv1.FolderConfig
71 assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
74 chExec := make(chan xsapiv1.ExecOutMsg)
76 sCli.Conn.On(xsapiv1.ExecOutEvent, func(ev xsapiv1.ExecOutMsg) {
80 cmd := "cd " + fPrj.ClientPath
82 cmd = cmd + "mkdir -p build"
84 cmd = cmd + "cd build"
86 cmd = cmd + "cmake .."
88 exec := xsapiv1.ExecArgs{
92 var execRes xsapiv1.ExecArgs
93 assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
94 flushChannelExec(chExec, 1000)
96 cmd = "cd " + fPrj.ClientPath
98 cmd = cmd + "cd build"
102 assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
103 flushChannelExec(chExec, 1000)
105 /*check afb-helloworld.so exists*/
106 _, err := os.Stat(path.Join(fPrj.ClientPath, "build/helloworld/helloworld.so"))
109 assert.Nil(t, HTTPCli.Delete("/folders/"+cfg.ID, &cfg))