github.com/AiRISTAFlowInc/fs-cli@v0.2.6/api/install_test.go (about) 1 package api 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 8 "github.com/AiRISTAFlowInc/fs-cli/common" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 var newJsonString = `{ 13 "name": "temp", 14 "type": "flogo:app", 15 "version": "0.0.1", 16 "description": "My flogo application description", 17 "appModel": "1.0.0", 18 "imports": [ 19 "github.com/AiRISTAFlowInc/fs-flow", 20 "github.com/skothari-tibco/flogoaztrigger", 21 "github.com/AiRISTAFlowInc/fs-contrib/activity/actreturn", 22 "github.com/AiRISTAFlowInc/fs-contrib/activity/log", 23 "github.com/TIBCOSoftware/flogo-contrib/activity/rest" 24 ], 25 "triggers": [ 26 { 27 "id": "my_rest_trigger", 28 "ref": "github.com/skothari-tibco/flogoaztrigger", 29 "handlers": [ 30 { 31 "action": { 32 "ref": "github.com/AiRISTAFlowInc/fs-flow", 33 "settings": { 34 "flowURI": "res://flow:simple_flow" 35 }, 36 "input": { 37 "in": "inputA" 38 }, 39 "output" :{ 40 "out": "=$.out" 41 } 42 } 43 } 44 ] 45 } 46 ], 47 "resources": [ 48 { 49 "id": "flow:simple_flow", 50 "data": { 51 "name": "simple_flow", 52 "metadata": { 53 "input": [ 54 { "name": "in", "type": "string", "value": "test" } 55 ], 56 "output": [ 57 { "name": "out", "type": "string" } 58 ] 59 }, 60 "tasks": [ 61 { 62 "id": "log", 63 "name": "Log Message", 64 "activity": { 65 "ref": "github.com/AiRISTAFlowInc/fs-contrib/activity/log", 66 "input": { 67 "message": "=$flow.in", 68 "flowInfo": "false", 69 "addToFlow": "false" 70 } 71 } 72 }, 73 { 74 "id" :"return", 75 "name" : "Activity Return", 76 "activity":{ 77 "ref" : "github.com/AiRISTAFlowInc/fs-contrib/activity/actreturn", 78 "settings":{ 79 "mappings":{ 80 "out": "nameA" 81 } 82 } 83 } 84 } 85 ], 86 "links": [ 87 { 88 "from":"log", 89 "to":"return" 90 } 91 ] 92 } 93 } 94 ] 95 } 96 ` 97 98 func TestInstallLegacyPkg(t *testing.T) { 99 t.Log("Testing installation of package") 100 101 tempDir, _ := GetTempDir() 102 103 testEnv := &TestEnv{currentDir: tempDir} 104 105 defer testEnv.cleanup() 106 107 t.Logf("Current dir '%s'", testEnv.currentDir) 108 _ = os.Chdir(testEnv.currentDir) 109 110 _, err := CreateProject(testEnv.currentDir, "myApp", "", "v0.9.2") 111 112 assert.Nil(t, err) 113 114 err = InstallPackage(NewAppProject(filepath.Join(testEnv.currentDir, "myApp")), "github.com/TIBCOSoftware/flogo-contrib/activity/log") 115 assert.Nil(t, err) 116 117 appProject := NewAppProject(filepath.Join(testEnv.currentDir, "myApp")) 118 119 err = appProject.Validate() 120 assert.Nil(t, err) 121 122 common.SetCurrentProject(appProject) 123 124 err = BuildProject(common.CurrentProject(), common.BuildOptions{}) 125 assert.Nil(t, err) 126 127 } 128 129 func TestInstallPkg(t *testing.T) { 130 t.Log("Testing installation of package") 131 132 tempDir, _ := GetTempDir() 133 134 testEnv := &TestEnv{currentDir: tempDir} 135 136 defer testEnv.cleanup() 137 138 t.Logf("Current dir '%s'", testEnv.currentDir) 139 _ = os.Chdir(testEnv.currentDir) 140 141 _, err := CreateProject(testEnv.currentDir, "myApp", "", "") 142 143 assert.Nil(t, err) 144 145 err = InstallPackage(NewAppProject(filepath.Join(testEnv.currentDir, "myApp")), "github.com/AiRISTAFlowInc/fs-contrib/activity/noop") 146 assert.Nil(t, err) 147 148 appProject := NewAppProject(filepath.Join(testEnv.currentDir, "myApp")) 149 150 err = appProject.Validate() 151 assert.Nil(t, err) 152 153 common.SetCurrentProject(appProject) 154 155 err = BuildProject(common.CurrentProject(), common.BuildOptions{}) 156 assert.Nil(t, err) 157 } 158 159 func TestInstallPkgWithVersion(t *testing.T) { 160 t.Log("Testing installation of package") 161 162 tempDir, _ := GetTempDir() 163 164 testEnv := &TestEnv{currentDir: tempDir} 165 166 defer testEnv.cleanup() 167 168 t.Logf("Current dir '%s'", testEnv.currentDir) 169 _ = os.Chdir(testEnv.currentDir) 170 171 _, err := CreateProject(testEnv.currentDir, "myApp", "", "") 172 173 assert.Nil(t, err) 174 175 err = InstallPackage(NewAppProject(filepath.Join(testEnv.currentDir, "myApp")), "github.com/AiRISTAFlowInc/fs-contrib/activity/log@v0.9.0") 176 assert.Nil(t, err) 177 178 appProject := NewAppProject(filepath.Join(testEnv.currentDir, "myApp")) 179 180 err = appProject.Validate() 181 assert.Nil(t, err) 182 183 common.SetCurrentProject(appProject) 184 185 err = BuildProject(common.CurrentProject(), common.BuildOptions{}) 186 assert.Nil(t, err) 187 } 188 189 func TestListPkg(t *testing.T) { 190 t.Log("Testing listing of packages") 191 192 tempDir, _ := GetTempDir() 193 194 testEnv := &TestEnv{currentDir: tempDir} 195 196 defer testEnv.cleanup() 197 198 t.Logf("Current dir '%s'", testEnv.currentDir) 199 _ = os.Chdir(testEnv.currentDir) 200 201 _, err := CreateProject(testEnv.currentDir, "myApp", "", "") 202 203 assert.Equal(t, nil, err) 204 205 err = ListContribs(NewAppProject(filepath.Join(testEnv.currentDir, "myApp")), true, "") 206 assert.Equal(t, nil, err) 207 208 }