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 "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
27 git "github.com/libgit2/git2go"
28 "github.com/stretchr/testify/assert"
31 func TestExec(t *testing.T) {
32 cloneRepo := "https://github.com/iotbzh/helloworld-service.git"
33 cloneDir := path.Join(os.Getenv(envRootCfgDir), "testExec")
34 t.Logf("Cloning repo %v in %v\n...\n", cloneRepo, cloneDir)
35 var cloneOptions git.CloneOptions
36 repository, err := git.Clone(cloneRepo, cloneDir, &cloneOptions)
41 repository.Submodules.Foreach(func(sub *git.Submodule, name string) int {
43 err := sub.Update(true, &git.SubmoduleUpdateOptions{
45 Strategy: git.CheckoutForce | git.CheckoutUpdateSubmodules,
56 t.Logf("repo cloned\n")
58 var cfgArray []xsapiv1.FolderConfig
59 assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
60 assert.Equal(t, len(cfgArray), 0)
62 fPrj := xsapiv1.FolderConfig{
65 Type: xsapiv1.TypePathMap,
66 ClientData: "clientdatatest",
67 DataPathMap: xsapiv1.PathMapConfig{
71 var cfg xsapiv1.FolderConfig
72 assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
74 _, err = NewIoSocketClient(prefixURL, HTTPCli.GetClientID())
79 cmd := "export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig/"
81 cmd = cmd + "cd " + fPrj.ClientPath
83 cmd = cmd + "mkdir -p build"
85 cmd = cmd + "cd build"
87 cmd = cmd + "cmake .."
89 exec := xsapiv1.ExecArgs{
93 var execRes xsapiv1.ExecArgs
94 assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
95 time.Sleep(3 * time.Second) //maybe waiting for an event would be better
97 cmd = "export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig/"
99 cmd = cmd + "cd " + fPrj.ClientPath
101 cmd = cmd + "cd build"
105 assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
106 time.Sleep(3 * time.Second) //maybe waiting for an event would be better
108 /*check afb-helloworld.so exists*/
109 _, err = os.Stat(path.Join(fPrj.ClientPath, "build/helloworld-afb/afb-helloworld.so"))
112 assert.Nil(t, HTTPCli.Delete("/folders/"+cfg.ID, &cfg))