From 485787a643fd80eaf23b0f7d115c39d61c65a3f8 Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Mon, 28 Mar 2022 00:49:34 +0300 Subject: [PATCH 01/13] Create code-files_test.go --- .../Tests/pipelines/code-files_test.go | 275 ++++++++++++++++++ 1 file changed, 275 insertions(+) create mode 100644 app/mainapp/Tests/pipelines/code-files_test.go diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go new file mode 100644 index 000000000..fb6aded6d --- /dev/null +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -0,0 +1,275 @@ +package pipelinetests + +import ( + "dataplane/mainapp/Tests/testutils" + "dataplane/mainapp/database" + "dataplane/mainapp/database/models" + "log" + "net/http" + "strings" + "testing" + + "github.com/bxcodec/faker/v3" + jsoniter "github.com/json-iterator/go" + "github.com/stretchr/testify/assert" +) + +/* +For individual tests - in separate window run: go run server.go +go test -p 1 -v -count=1 -run TestPipelines dataplane/mainapp/Tests/codefiles +* Login +* Create pipeline +* Add pipeline flow + +* Create folder node - +* Upload file node - WIP + +* Delete pipeline flow +* Delete pipeline + +*/ +func TestCodeFiles(t *testing.T) { + + database.DBConnect() + + graphQLUrl := testutils.GraphQLUrlPublic + graphQLUrlPrivate := testutils.GraphQLUrlPrivate + + testUser := testutils.AdminUser + testPassword := testutils.AdminPassword + + //--------- Login ------------ + + loginUser := `{ + loginUser( + username: "` + testUser + `", + password: "` + testPassword + `", + ) { + access_token + refresh_token + } + }` + + loginUserResponse, httpLoginResponse := testutils.GraphQLRequestPublic(loginUser, "{}", graphQLUrl, t) + accessToken := jsoniter.Get(loginUserResponse, "data", "loginUser", "access_token").ToString() + + // log.Println(string(loginUserResponse)) + + if strings.Contains(string(loginUserResponse), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpLoginResponse.StatusCode, "Login user 200 status code") + + // envID := testutils.TestEnvironmentID + // if testutils.TestEnvironmentID == "" { + // envID = "test-environment-id" + // } + + pipelineId := testutils.TextEscape(faker.UUIDHyphenated()) + + // -------- clean data ------- + // database.DBConn.Where("environment_id =?", envID).Delete(&models.PipelineNodes{}) + // database.DBConn.Where("environment_id =?", envID).Delete(&models.PipelineEdges{}) + // database.DBConn.Where("environment_id =?", envID).Delete(&models.Pipelines{}) + database.DBConn.Where("name =?", "test_Code_Files_Environment").Delete(&models.Environment{}) + // -------- Add environment ------------- + + mutation := `mutation { + addEnvironment( + input: { + name: "test_Code_Files_Environment", + description: "" + } + ){ + id + name + description + } + }` + + response, httpResponse := testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add environment 200 status code") + envID := jsoniter.Get(response, "data", "addEnvironment", "id").ToString() + + // -------- Create pipeline ------------- + + mutation = `mutation { + addPipeline( + name: "test_` + pipelineId + `", + environmentID: "` + envID + `", + description: "Test", + workerGroup: "python_1" + ) + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Create pipeline 200 status code") + id := jsoniter.Get(response, "data", "addPipeline").ToString() + + // -------- Add pipeline flow ------------- + mutation = `mutation { + addUpdatePipelineFlow( + environmentID: "` + envID + `", + pipelineID: "` + id + `", + input:{ + nodesInput: [{ + nodeID: "nodeID", + name: "TestNodePython", + nodeType: "pythonNode", + nodeTypeDesc: "", + triggerOnline: false, + description: "", + commands: [""], + workerGroup: "python_1", + meta: { + position: { + x: 75, + y: 315 + }, + data: { + language: "Python", + genericdata: null + } + }, + active: false + } + ], + edgesInput: [], + json: {} + } + ) + + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add pipeline flow 200 status code") + + // -------- Create folder ------------- + // Get parent's folder id + f := models.CodeFolders{} + err := database.DBConn.Where("folder_name = ? AND pipeline_id = ?", "TestNodePython", id).Find(&f).Error + if err != nil { + t.Errorf(err.Error()) + } + + mutation = `mutation { + createFolderNode( + input: { + folderID: "Folder1-ID", + parentID: "` + f.FolderID + `", + environmentID: "` + envID + `", + pipelineID: "` + id + `", + nodeID: "nodeID", + folderName: "Folder1", + fType: "folder", + active: true + } + ){ + folderID + parentID + folderName + level + fType + active + } + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add folder 200 status code") + + // -------- Create file ------------- + folder1ID := jsoniter.Get(response, "data", "createFolderNode", "folderID").ToString() + // emptyFile, err := os.Create("emptyFile.txt") + + mutation = `mutation { + uploadFileNode( + folderID: "` + folder1ID + `", + environmentID: "` + envID + `", + pipelineID: "` + id + `", + nodeID: "nodeID", + file: "file" + ) + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add file 200 status code") + + // -------- Delete pipeline flow ------------- + mutation = `mutation { + addUpdatePipelineFlow( + environmentID: "` + envID + `", + pipelineID: "` + pipelineId + `", + input:{ + nodesInput: [], + edgesInput: [], + json: {} + } + ) + + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete pipeline 200 status code") + + // -------- Delete pipeline ------------- + + mutation = `mutation { + deletePipeline( + environmentID: "` + envID + `", + pipelineID: "` + id + `") + + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete pipeline 200 status code") +} From fe3aa62c3e0ab6085b59b36006716dfeb59dfd30 Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Tue, 29 Mar 2022 20:29:11 +0300 Subject: [PATCH 02/13] Added upload file to tests. --- .../Tests/pipelines/code-files_test.go | 2 +- .../testutils/GraphqlClientPrivateUpload.go | 76 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go index fb6aded6d..58cad8bd0 100644 --- a/app/mainapp/Tests/pipelines/code-files_test.go +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -220,7 +220,7 @@ func TestCodeFiles(t *testing.T) { ) }` - response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + response, httpResponse = testutils.GraphQLRequestPrivateUpload(accessToken, graphQLUrlPrivate, folder1ID, envID, id, "nodeID", t) log.Println(string(response)) diff --git a/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go b/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go new file mode 100644 index 000000000..cc9a08092 --- /dev/null +++ b/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go @@ -0,0 +1,76 @@ +package testutils + +import ( + "bytes" + "fmt" + "io" + "io/ioutil" + "mime/multipart" + "net/http" + "os" + "path/filepath" + "testing" +) + +func GraphQLRequestPrivateUpload(token string, url string, folderID string, envID string, pipelineID string, nodeID string, t *testing.T) (responseBody []byte, res *http.Response) { + + method := "POST" + + payload := &bytes.Buffer{} + writer := multipart.NewWriter(payload) + _ = writer.WriteField("operations", "{\"query\":\"\\n mutation uploadFileNode($environmentID: String!, $nodeID: String!, $pipelineID: String!, $folderID: String!, $file: Upload!) {\\n uploadFileNode(environmentID: $environmentID, nodeID: $nodeID, pipelineID: $pipelineID, folderID: $folderID, file: $file)\\n }\\n\",\"variables\":{\"environmentID\":\""+envID+"\",\"pipelineID\":\""+pipelineID+"\",\"nodeID\":\""+nodeID+"\",\"folderID\":\""+folderID+"\",\"file\":null}}\n") + _ = writer.WriteField("map", "{\"1\":[\"variables.file\"]}") + + // not working ==> config.CodeDirectory+"dp-entrypoint.py" + file, errFile3 := os.Open("/appdev/code-files/dp-entrypoint.py") + + if errFile3 != nil { + fmt.Println(errFile3) + return + } + + defer file.Close() + + part3, errFile3 := writer.CreateFormFile("1", filepath.Base("dp-entrypoint.py")) + if errFile3 != nil { + fmt.Println(errFile3) + return + } + + _, errFile3 = io.Copy(part3, file) + if errFile3 != nil { + fmt.Println(errFile3) + return + } + err := writer.Close() + if err != nil { + fmt.Println(err) + return + } + + client := &http.Client{} + req, err := http.NewRequest(method, url, payload) + + if err != nil { + fmt.Println(err) + return + } + req.Header.Add("Authorization", "Bearer "+token) + + req.Header.Set("Content-Type", writer.FormDataContentType()) + res, err = client.Do(req) + if err != nil { + fmt.Println(err) + return + } + defer res.Body.Close() + + body, err := ioutil.ReadAll(res.Body) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(string(body)) + + return +} From e6eda0b83171e049c55fd28dc8ee5a90ded9f59a Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Tue, 29 Mar 2022 21:22:43 +0300 Subject: [PATCH 03/13] Added delete file to tests --- .../Tests/pipelines/code-files_test.go | 26 +++++++++++++++++-- .../testutils/GraphqlClientPrivateUpload.go | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go index 58cad8bd0..4521a8e75 100644 --- a/app/mainapp/Tests/pipelines/code-files_test.go +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -21,8 +21,8 @@ go test -p 1 -v -count=1 -run TestPipelines dataplane/mainapp/Tests/codefiles * Create pipeline * Add pipeline flow -* Create folder node - -* Upload file node - WIP +* Create folder node +* Upload file node * Delete pipeline flow * Delete pipeline @@ -230,6 +230,28 @@ func TestCodeFiles(t *testing.T) { assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add file 200 status code") + // -------- Delete file ------------- + uploadedFileID := jsoniter.Get(response, "data", "uploadFileNode").ToString() + + mutation = `mutation { + deleteFileNode( + fileID: "` + uploadedFileID + `", + environmentID: "` + envID + `", + pipelineID: "` + id + `", + nodeID: "nodeID" + ) + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete file 200 status code") + // -------- Delete pipeline flow ------------- mutation = `mutation { addUpdatePipelineFlow( diff --git a/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go b/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go index cc9a08092..370efef22 100644 --- a/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go +++ b/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go @@ -72,5 +72,5 @@ func GraphQLRequestPrivateUpload(token string, url string, folderID string, envI } fmt.Println(string(body)) - return + return body, res } From c3cb8b9458fd8e74dc43d624baf8f435a0351b68 Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Tue, 29 Mar 2022 21:40:41 +0300 Subject: [PATCH 04/13] Added rename file --- .../Tests/pipelines/code-files_test.go | 48 +++++++++++++++++-- .../testutils/GraphqlClientPrivateUpload.go | 4 +- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go index 4521a8e75..1e156edaf 100644 --- a/app/mainapp/Tests/pipelines/code-files_test.go +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -2,6 +2,7 @@ package pipelinetests import ( "dataplane/mainapp/Tests/testutils" + "dataplane/mainapp/config" "dataplane/mainapp/database" "dataplane/mainapp/database/models" "log" @@ -23,13 +24,16 @@ go test -p 1 -v -count=1 -run TestPipelines dataplane/mainapp/Tests/codefiles * Create folder node * Upload file node +* Rename file node +* Delete file node * Delete pipeline flow * Delete pipeline +* Delete environment */ func TestCodeFiles(t *testing.T) { - + config.LoadConfig() database.DBConnect() graphQLUrl := testutils.GraphQLUrlPublic @@ -223,6 +227,7 @@ func TestCodeFiles(t *testing.T) { response, httpResponse = testutils.GraphQLRequestPrivateUpload(accessToken, graphQLUrlPrivate, folder1ID, envID, id, "nodeID", t) log.Println(string(response)) + uploadedFileID := jsoniter.Get(response, "data", "uploadFileNode").ToString() if strings.Contains(string(response), `"errors":`) { t.Errorf("Error in graphql response") @@ -230,9 +235,28 @@ func TestCodeFiles(t *testing.T) { assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add file 200 status code") - // -------- Delete file ------------- - uploadedFileID := jsoniter.Get(response, "data", "uploadFileNode").ToString() + // -------- Rename file ------------- + mutation = `mutation { + renameFile( + fileID: "` + uploadedFileID + `", + environmentID: "` + envID + `", + pipelineID: "` + id + `", + nodeID: "nodeID", + newName: "dp-entrypoint_Renamed.py" + ) + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete file 200 status code") + // -------- Delete file ------------- mutation = `mutation { deleteFileNode( fileID: "` + uploadedFileID + `", @@ -294,4 +318,22 @@ func TestCodeFiles(t *testing.T) { } assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete pipeline 200 status code") + + // -------- Delte environment ------------- + + mutation = `mutation { + updateDeleteEnvironment( + environment_id: "` + envID + `") + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete environment 200 status code") + } diff --git a/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go b/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go index 370efef22..31e5d4d16 100644 --- a/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go +++ b/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go @@ -2,6 +2,7 @@ package testutils import ( "bytes" + "dataplane/mainapp/config" "fmt" "io" "io/ioutil" @@ -21,8 +22,7 @@ func GraphQLRequestPrivateUpload(token string, url string, folderID string, envI _ = writer.WriteField("operations", "{\"query\":\"\\n mutation uploadFileNode($environmentID: String!, $nodeID: String!, $pipelineID: String!, $folderID: String!, $file: Upload!) {\\n uploadFileNode(environmentID: $environmentID, nodeID: $nodeID, pipelineID: $pipelineID, folderID: $folderID, file: $file)\\n }\\n\",\"variables\":{\"environmentID\":\""+envID+"\",\"pipelineID\":\""+pipelineID+"\",\"nodeID\":\""+nodeID+"\",\"folderID\":\""+folderID+"\",\"file\":null}}\n") _ = writer.WriteField("map", "{\"1\":[\"variables.file\"]}") - // not working ==> config.CodeDirectory+"dp-entrypoint.py" - file, errFile3 := os.Open("/appdev/code-files/dp-entrypoint.py") + file, errFile3 := os.Open(config.CodeDirectory + "dp-entrypoint.py") if errFile3 != nil { fmt.Println(errFile3) From 4895b99cacf78b4c00e1e448ba2222602c4474d4 Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Tue, 29 Mar 2022 21:48:10 +0300 Subject: [PATCH 05/13] Added rename folder to tests --- .../Tests/pipelines/code-files_test.go | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go index 1e156edaf..e7b8acad5 100644 --- a/app/mainapp/Tests/pipelines/code-files_test.go +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -23,6 +23,7 @@ go test -p 1 -v -count=1 -run TestPipelines dataplane/mainapp/Tests/codefiles * Add pipeline flow * Create folder node +* Rename folder node * Upload file node * Rename file node * Delete file node @@ -186,7 +187,7 @@ func TestCodeFiles(t *testing.T) { environmentID: "` + envID + `", pipelineID: "` + id + `", nodeID: "nodeID", - folderName: "Folder1", + folderName: "Folder", fType: "folder", active: true } @@ -203,6 +204,7 @@ func TestCodeFiles(t *testing.T) { response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) log.Println(string(response)) + renamedFolderID := jsoniter.Get(response, "data", "createFolderNode", "folderID").ToString() if strings.Contains(string(response), `"errors":`) { t.Errorf("Error in graphql response") @@ -210,13 +212,32 @@ func TestCodeFiles(t *testing.T) { assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add folder 200 status code") + // -------- Rename folder ------------- + mutation = `mutation { + renameFolder( + folderID: "` + renamedFolderID + `", + environmentID: "` + envID + `", + pipelineID: "` + id + `", + nodeID: "nodeID", + newName: "Folder1" + ) + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Rename folder 200 status code") + // -------- Create file ------------- - folder1ID := jsoniter.Get(response, "data", "createFolderNode", "folderID").ToString() - // emptyFile, err := os.Create("emptyFile.txt") mutation = `mutation { uploadFileNode( - folderID: "` + folder1ID + `", + folderID: "` + renamedFolderID + `", environmentID: "` + envID + `", pipelineID: "` + id + `", nodeID: "nodeID", @@ -224,7 +245,7 @@ func TestCodeFiles(t *testing.T) { ) }` - response, httpResponse = testutils.GraphQLRequestPrivateUpload(accessToken, graphQLUrlPrivate, folder1ID, envID, id, "nodeID", t) + response, httpResponse = testutils.GraphQLRequestPrivateUpload(accessToken, graphQLUrlPrivate, renamedFolderID, envID, id, "nodeID", t) log.Println(string(response)) uploadedFileID := jsoniter.Get(response, "data", "uploadFileNode").ToString() @@ -254,7 +275,7 @@ func TestCodeFiles(t *testing.T) { t.Errorf("Error in graphql response") } - assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete file 200 status code") + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Rename file 200 status code") // -------- Delete file ------------- mutation = `mutation { From 2480efebf67a21e02358f7dacb9a44a1133ff752 Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Tue, 29 Mar 2022 22:05:44 +0300 Subject: [PATCH 06/13] Added delete folder to tests --- .../Tests/pipelines/code-files_test.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go index e7b8acad5..e1074ce58 100644 --- a/app/mainapp/Tests/pipelines/code-files_test.go +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -27,6 +27,8 @@ go test -p 1 -v -count=1 -run TestPipelines dataplane/mainapp/Tests/codefiles * Upload file node * Rename file node * Delete file node +* Delete folder node + * Delete pipeline flow * Delete pipeline @@ -297,6 +299,26 @@ func TestCodeFiles(t *testing.T) { assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete file 200 status code") + // -------- Delete folder ------------- + mutation = `mutation { + deleteFolderNode( + folderID: "` + renamedFolderID + `", + environmentID: "` + envID + `", + pipelineID: "` + id + `", + nodeID: "nodeID" + ) + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete folder 200 status code") + // -------- Delete pipeline flow ------------- mutation = `mutation { addUpdatePipelineFlow( From 90c37a7563bca8a2af51b3de349faa3cce8dc86c Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Tue, 29 Mar 2022 22:15:47 +0300 Subject: [PATCH 07/13] Added getFilesNode to tests --- .../Tests/pipelines/code-files_test.go | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go index e1074ce58..f185c8bfd 100644 --- a/app/mainapp/Tests/pipelines/code-files_test.go +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -22,12 +22,13 @@ go test -p 1 -v -count=1 -run TestPipelines dataplane/mainapp/Tests/codefiles * Create pipeline * Add pipeline flow -* Create folder node -* Rename folder node -* Upload file node -* Rename file node -* Delete file node -* Delete folder node +* Create folder +* Rename folder +* Upload file +* Rename file +* Get Files node +* Delete file +* Delete folder * Delete pipeline flow @@ -279,6 +280,42 @@ func TestCodeFiles(t *testing.T) { assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Rename file 200 status code") + // -------- Get files node ------------- + mutation = `query { + filesNode( + environmentID: "` + envID + `", + pipelineID: "` + id + `", + nodeID: "nodeID" + ){ + folders{ + folderID + parentID + folderName + level + fType + active + } + files{ + fileID + folderID + fileName + level + fType + active + } + } + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Get files node 200 status code") + // -------- Delete file ------------- mutation = `mutation { deleteFileNode( From 567ebf58bae4bf49c5f6a6cf15e0bf5f359d9d26 Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Tue, 29 Mar 2022 23:24:58 +0300 Subject: [PATCH 08/13] Added delete temporary environment to tests --- .../Tests/pipelines/code-files_test.go | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go index f185c8bfd..53612eb7f 100644 --- a/app/mainapp/Tests/pipelines/code-files_test.go +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -2,11 +2,13 @@ package pipelinetests import ( "dataplane/mainapp/Tests/testutils" + "dataplane/mainapp/code_editor/filesystem" "dataplane/mainapp/config" "dataplane/mainapp/database" "dataplane/mainapp/database/models" "log" "net/http" + "os" "strings" "testing" @@ -129,6 +131,15 @@ func TestCodeFiles(t *testing.T) { assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Create pipeline 200 status code") id := jsoniter.Get(response, "data", "addPipeline").ToString() + // Get environment folder path + f := models.CodeFolders{} + err := database.DBConn.Where("pipeline_id = ? and level = ?", id, "pipeline").Find(&f).Error + if err != nil { + t.Errorf(err.Error()) + } + folderpath, _ := filesystem.FolderConstructByID(database.DBConn, f.ParentID, envID) + deleteFolder := config.CodeDirectory + folderpath + // -------- Add pipeline flow ------------- mutation = `mutation { addUpdatePipelineFlow( @@ -176,8 +187,7 @@ func TestCodeFiles(t *testing.T) { // -------- Create folder ------------- // Get parent's folder id - f := models.CodeFolders{} - err := database.DBConn.Where("folder_name = ? AND pipeline_id = ?", "TestNodePython", id).Find(&f).Error + err = database.DBConn.Where("folder_name = ? AND pipeline_id = ?", "TestNodePython", id).Find(&f).Error if err != nil { t.Errorf(err.Error()) } @@ -399,8 +409,7 @@ func TestCodeFiles(t *testing.T) { assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete pipeline 200 status code") - // -------- Delte environment ------------- - + // -------- Delete environment ------------- mutation = `mutation { updateDeleteEnvironment( environment_id: "` + envID + `") @@ -416,4 +425,9 @@ func TestCodeFiles(t *testing.T) { assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete environment 200 status code") + // -------- Remove Temporary environment + err = os.RemoveAll(deleteFolder) + if err != nil { + t.Errorf(err.Error()) + } } From a62dd2dec0092797c432d059915aa4b270dbe09d Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Tue, 29 Mar 2022 23:42:33 +0300 Subject: [PATCH 09/13] Added move file to tests --- .../Tests/pipelines/code-files_test.go | 68 ++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go index 53612eb7f..6e56ddd15 100644 --- a/app/mainapp/Tests/pipelines/code-files_test.go +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -24,18 +24,20 @@ go test -p 1 -v -count=1 -run TestPipelines dataplane/mainapp/Tests/codefiles * Create pipeline * Add pipeline flow -* Create folder +* Create folder 2 +* Create folder 1 * Rename folder * Upload file +* Move file * Rename file * Get Files node * Delete file * Delete folder - * Delete pipeline flow * Delete pipeline * Delete environment +* Delete temoprary environment folder */ func TestCodeFiles(t *testing.T) { @@ -192,6 +194,46 @@ func TestCodeFiles(t *testing.T) { t.Errorf(err.Error()) } + mutation = `mutation { + createFolderNode( + input: { + folderID: "Folder1-ID", + parentID: "` + f.FolderID + `", + environmentID: "` + envID + `", + pipelineID: "` + id + `", + nodeID: "nodeID", + folderName: "Folder2", + fType: "folder", + active: true + } + ){ + folderID + parentID + folderName + level + fType + active + } + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + Folder2ID := jsoniter.Get(response, "data", "createFolderNode", "folderID").ToString() + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add folder 200 status code") + + // -------- Create folder ------------- + // Get parent's folder id + err = database.DBConn.Where("folder_name = ? AND pipeline_id = ?", "TestNodePython", id).Find(&f).Error + if err != nil { + t.Errorf(err.Error()) + } + mutation = `mutation { createFolderNode( input: { @@ -269,6 +311,28 @@ func TestCodeFiles(t *testing.T) { assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add file 200 status code") + // -------- Move file ------------- + + mutation = `mutation { + moveFileNode( + fileID: "` + uploadedFileID + `", + toFolderID: "` + Folder2ID + `", + environmentID: "` + envID + `", + pipelineID: "` + id + `" + + ) + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add file 200 status code") + // -------- Rename file ------------- mutation = `mutation { renameFile( From e020443be1a02e03218b887203ba002d2cd7fd5f Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Wed, 30 Mar 2022 11:26:26 +0300 Subject: [PATCH 10/13] Added move folder to tests. --- .../Tests/pipelines/code-files_test.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go index 6e56ddd15..b37cf0e74 100644 --- a/app/mainapp/Tests/pipelines/code-files_test.go +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -288,6 +288,26 @@ func TestCodeFiles(t *testing.T) { assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Rename folder 200 status code") + // -------- Move folder ------------- + mutation = `mutation { + moveFolderNode( + folderID: "` + renamedFolderID + `", + environmentID: "` + envID + `", + pipelineID: "` + id + `", + toFolderID: "` + Folder2ID + `" + ) + }` + + response, httpResponse = testutils.GraphQLRequestPrivate(mutation, accessToken, "{}", graphQLUrlPrivate, t) + + log.Println(string(response)) + + if strings.Contains(string(response), `"errors":`) { + t.Errorf("Error in graphql response") + } + + assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Move folder 200 status code") + // -------- Create file ------------- mutation = `mutation { From a96a77495d51ca48b4062de43f1a1c32be4b9ec3 Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Wed, 30 Mar 2022 11:30:43 +0300 Subject: [PATCH 11/13] update to folderConstructByID --- app/mainapp/Tests/pipelines/code-files_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go index b37cf0e74..244dce4fa 100644 --- a/app/mainapp/Tests/pipelines/code-files_test.go +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -139,7 +139,7 @@ func TestCodeFiles(t *testing.T) { if err != nil { t.Errorf(err.Error()) } - folderpath, _ := filesystem.FolderConstructByID(database.DBConn, f.ParentID, envID) + folderpath, _ := filesystem.FolderConstructByID(database.DBConn, f.ParentID, envID, "") deleteFolder := config.CodeDirectory + folderpath // -------- Add pipeline flow ------------- From c023cb5602b8271ceab1b25ba4e9bfe65e84605f Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Wed, 30 Mar 2022 13:01:39 +0300 Subject: [PATCH 12/13] clean up --- app/mainapp/Tests/pipelines/code-files_test.go | 10 ++++++---- .../Tests/testutils/GraphqlClientPrivateUpload.go | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go index 244dce4fa..3f8fdaa13 100644 --- a/app/mainapp/Tests/pipelines/code-files_test.go +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -19,7 +19,7 @@ import ( /* For individual tests - in separate window run: go run server.go -go test -p 1 -v -count=1 -run TestPipelines dataplane/mainapp/Tests/codefiles +go test -p 1 -v -count=1 -run TestCodeFiles dataplane/mainapp/Tests/pipelines * Login * Create pipeline * Add pipeline flow @@ -27,6 +27,7 @@ go test -p 1 -v -count=1 -run TestPipelines dataplane/mainapp/Tests/codefiles * Create folder 2 * Create folder 1 * Rename folder +* Move folder * Upload file * Move file * Rename file @@ -81,9 +82,7 @@ func TestCodeFiles(t *testing.T) { pipelineId := testutils.TextEscape(faker.UUIDHyphenated()) // -------- clean data ------- - // database.DBConn.Where("environment_id =?", envID).Delete(&models.PipelineNodes{}) - // database.DBConn.Where("environment_id =?", envID).Delete(&models.PipelineEdges{}) - // database.DBConn.Where("environment_id =?", envID).Delete(&models.Pipelines{}) + database.DBConn.Where("node_id =?", "nodeID").Delete(&models.PipelineNodes{}) database.DBConn.Where("name =?", "test_Code_Files_Environment").Delete(&models.Environment{}) // -------- Add environment ------------- @@ -514,4 +513,7 @@ func TestCodeFiles(t *testing.T) { if err != nil { t.Errorf(err.Error()) } + // -------- Remove zombie folders + database.DBConn.Where("environment_id = ? ", envID).Delete(&models.CodeFolders{}) + } diff --git a/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go b/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go index 31e5d4d16..81ea05fa6 100644 --- a/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go +++ b/app/mainapp/Tests/testutils/GraphqlClientPrivateUpload.go @@ -2,7 +2,6 @@ package testutils import ( "bytes" - "dataplane/mainapp/config" "fmt" "io" "io/ioutil" @@ -22,12 +21,15 @@ func GraphQLRequestPrivateUpload(token string, url string, folderID string, envI _ = writer.WriteField("operations", "{\"query\":\"\\n mutation uploadFileNode($environmentID: String!, $nodeID: String!, $pipelineID: String!, $folderID: String!, $file: Upload!) {\\n uploadFileNode(environmentID: $environmentID, nodeID: $nodeID, pipelineID: $pipelineID, folderID: $folderID, file: $file)\\n }\\n\",\"variables\":{\"environmentID\":\""+envID+"\",\"pipelineID\":\""+pipelineID+"\",\"nodeID\":\""+nodeID+"\",\"folderID\":\""+folderID+"\",\"file\":null}}\n") _ = writer.WriteField("map", "{\"1\":[\"variables.file\"]}") - file, errFile3 := os.Open(config.CodeDirectory + "dp-entrypoint.py") + // file, errFile3 := os.Open(config.CodeDirectory + "dp-entrypoint.py") + file, errFile3 := os.CreateTemp("", "dp-entrypoint.py") // in Go version older than 1.17 you can use ioutil.TempFile if errFile3 != nil { fmt.Println(errFile3) return } + defer file.Close() + defer os.Remove(file.Name()) defer file.Close() From 4ae6106c67be5664ce92149438a71357b9768e25 Mon Sep 17 00:00:00 2001 From: Onat <53895969+onattech@users.noreply.github.com> Date: Wed, 30 Mar 2022 22:30:44 +0300 Subject: [PATCH 13/13] Code files tests are complete --- .../Tests/pipelines/code-files_test.go | 37 ++-- .../Tests/testutils/TreeIntegrityCheck.go | 169 ++++++++++++++++++ 2 files changed, 186 insertions(+), 20 deletions(-) create mode 100644 app/mainapp/Tests/testutils/TreeIntegrityCheck.go diff --git a/app/mainapp/Tests/pipelines/code-files_test.go b/app/mainapp/Tests/pipelines/code-files_test.go index 3f8fdaa13..29f75dde6 100644 --- a/app/mainapp/Tests/pipelines/code-files_test.go +++ b/app/mainapp/Tests/pipelines/code-files_test.go @@ -27,13 +27,13 @@ go test -p 1 -v -count=1 -run TestCodeFiles dataplane/mainapp/Tests/pipelines * Create folder 2 * Create folder 1 * Rename folder -* Move folder -* Upload file -* Move file -* Rename file +* Move folder - Tree integrity check +* Upload file - Tree integrity check +* Move file - Tree integrity check +* Rename file - Tree integrity check * Get Files node -* Delete file -* Delete folder +* Delete file - Tree integrity check +* Delete folder - Tree integrity check * Delete pipeline flow * Delete pipeline @@ -74,11 +74,6 @@ func TestCodeFiles(t *testing.T) { assert.Equalf(t, http.StatusOK, httpLoginResponse.StatusCode, "Login user 200 status code") - // envID := testutils.TestEnvironmentID - // if testutils.TestEnvironmentID == "" { - // envID = "test-environment-id" - // } - pipelineId := testutils.TextEscape(faker.UUIDHyphenated()) // -------- clean data ------- @@ -188,7 +183,8 @@ func TestCodeFiles(t *testing.T) { // -------- Create folder ------------- // Get parent's folder id - err = database.DBConn.Where("folder_name = ? AND pipeline_id = ?", "TestNodePython", id).Find(&f).Error + nf := models.CodeFolders{} + err = database.DBConn.Where("folder_name = ? AND pipeline_id = ?", "TestNodePython", id).Find(&nf).Error if err != nil { t.Errorf(err.Error()) } @@ -197,7 +193,7 @@ func TestCodeFiles(t *testing.T) { createFolderNode( input: { folderID: "Folder1-ID", - parentID: "` + f.FolderID + `", + parentID: "` + nf.FolderID + `", environmentID: "` + envID + `", pipelineID: "` + id + `", nodeID: "nodeID", @@ -227,17 +223,12 @@ func TestCodeFiles(t *testing.T) { assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add folder 200 status code") // -------- Create folder ------------- - // Get parent's folder id - err = database.DBConn.Where("folder_name = ? AND pipeline_id = ?", "TestNodePython", id).Find(&f).Error - if err != nil { - t.Errorf(err.Error()) - } mutation = `mutation { createFolderNode( input: { folderID: "Folder1-ID", - parentID: "` + f.FolderID + `", + parentID: "` + nf.FolderID + `", environmentID: "` + envID + `", pipelineID: "` + id + `", nodeID: "nodeID", @@ -285,6 +276,7 @@ func TestCodeFiles(t *testing.T) { t.Errorf("Error in graphql response") } + testutils.TreeIntegrityCheck(envID, id, "default", t) assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Rename folder 200 status code") // -------- Move folder ------------- @@ -305,6 +297,7 @@ func TestCodeFiles(t *testing.T) { t.Errorf("Error in graphql response") } + testutils.TreeIntegrityCheck(envID, id, "afterMoveFolder", t) assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Move folder 200 status code") // -------- Create file ------------- @@ -328,6 +321,7 @@ func TestCodeFiles(t *testing.T) { t.Errorf("Error in graphql response") } + testutils.TreeIntegrityCheck(envID, id, "afterFileCreated", t) assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add file 200 status code") // -------- Move file ------------- @@ -350,6 +344,7 @@ func TestCodeFiles(t *testing.T) { t.Errorf("Error in graphql response") } + testutils.TreeIntegrityCheck(envID, id, "afterFileMoved", t) assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Add file 200 status code") // -------- Rename file ------------- @@ -371,6 +366,7 @@ func TestCodeFiles(t *testing.T) { t.Errorf("Error in graphql response") } + testutils.TreeIntegrityCheck(envID, id, "afterFileRenamed", t) assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Rename file 200 status code") // -------- Get files node ------------- @@ -427,6 +423,7 @@ func TestCodeFiles(t *testing.T) { t.Errorf("Error in graphql response") } + testutils.TreeIntegrityCheck(envID, id, "afterFileDeleted", t) assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete file 200 status code") // -------- Delete folder ------------- @@ -447,6 +444,7 @@ func TestCodeFiles(t *testing.T) { t.Errorf("Error in graphql response") } + testutils.TreeIntegrityCheck(envID, id, "afterFolderDeleted", t) assert.Equalf(t, http.StatusOK, httpResponse.StatusCode, "Delete folder 200 status code") // -------- Delete pipeline flow ------------- @@ -515,5 +513,4 @@ func TestCodeFiles(t *testing.T) { } // -------- Remove zombie folders database.DBConn.Where("environment_id = ? ", envID).Delete(&models.CodeFolders{}) - } diff --git a/app/mainapp/Tests/testutils/TreeIntegrityCheck.go b/app/mainapp/Tests/testutils/TreeIntegrityCheck.go new file mode 100644 index 000000000..239f04ec2 --- /dev/null +++ b/app/mainapp/Tests/testutils/TreeIntegrityCheck.go @@ -0,0 +1,169 @@ +package testutils + +import ( + "dataplane/mainapp/code_editor/filesystem" + "dataplane/mainapp/config" + "dataplane/mainapp/database" + "dataplane/mainapp/database/models" + "log" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TreeIntegrityCheck(environmentID string, pipelineID string, checkType string, t *testing.T) { + database.DBConnect() + + // Environment folder + ef := models.CodeFolders{} + err := database.DBConn.Where("environment_id = ? and level = ?", environmentID, "environment").Find(&ef).Error + if err != nil { + log.Println("err: ", err) + } + + // Pipeline folder + pf := models.CodeFolders{} + err = database.DBConn.Where("pipeline_id = ? and level = ?", pipelineID, "pipeline").Find(&pf).Error + if err != nil { + log.Println("err: ", err) + } + + // Node folder + nf := models.CodeFolders{} + err = database.DBConn.Where("pipeline_id = ? and folder_name = ?", pipelineID, "TestNodePython").Find(&nf).Error + if err != nil { + log.Println("err: ", err) + } + + // Folder1 folder + f1 := models.CodeFolders{} + err = database.DBConn.Where("pipeline_id = ? and folder_name = ?", pipelineID, "Folder1").Find(&f1).Error + if err != nil { + log.Println("err: ", err) + } + + // Folder2 folder + f2 := models.CodeFolders{} + err = database.DBConn.Where("pipeline_id = ? and folder_name = ?", pipelineID, "Folder2").Find(&f2).Error + if err != nil { + log.Println("err: ", err) + } + + platformFolderName := ef.ParentID + "_Platform" + environmentFolderName := ef.FolderID + "_" + ef.FolderName + pipelineFolderName := pf.FolderID + "_" + pf.FolderName + nodeFolderName := nf.FolderID + "_" + nf.FolderName + F1FolderName := f1.FolderID + "_" + f1.FolderName + F2FolderName := f2.FolderID + "_" + f2.FolderName + + treeBefore := []string{} + treeBefore2 := []string{} + treeAfter := []string{} + + switch checkType { + case "afterMoveFolder": + treeBefore = []string{ + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/" + F1FolderName} + + case "afterFileCreated": + treeBefore = []string{ + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/" + F1FolderName, + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/" + F1FolderName + "/dp-entrypoint.py"} + + case "afterFileMoved": + treeBefore = []string{ + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/" + F1FolderName, + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/" + "dp-entrypoint.py"} + treeBefore2 = []string{ + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/" + "dp-entrypoint.py", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/" + F1FolderName} + + case "afterFileRenamed": + treeBefore = []string{ + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/" + F1FolderName, + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/" + "dp-entrypoint_Renamed.py"} + treeBefore2 = []string{ + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/" + "dp-entrypoint_Renamed.py", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/" + F1FolderName} + + case "afterFileDeleted": + treeBefore = []string{ + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/" + F1FolderName} + + case "afterFolderDeleted": + treeBefore = []string{ + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/"} + + case "default": + treeBefore = []string{ + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F1FolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/"} + treeBefore2 = []string{ + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F2FolderName + "/", + config.CodeDirectory + platformFolderName + "/" + environmentFolderName + "/" + "pipelines/" + pipelineFolderName + "/" + nodeFolderName + "/" + F1FolderName + "/"} + } + + path, _ := filesystem.FolderConstructByID(database.DBConn, nf.ParentID, environmentID, "pipelines") + err = filepath.Walk(config.CodeDirectory+path, + func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if info.IsDir() && info.Name() == ".git" { + return filepath.SkipDir + } + treeAfter = append(treeAfter, path) + return nil + }) + if err != nil { + log.Println(err) + } + + check := stringSlicesEqual(treeBefore, treeAfter) + check2 := stringSlicesEqual(treeBefore2, treeAfter) + + assert.Equalf(t, (check || check2), true, "File tree integrity check: ", checkType) + +} + +func stringSlicesEqual(a, b []string) bool { + if len(a) != len(b) { + return false + } + for i, v := range a { + if strings.TrimRight(v, "/") != strings.TrimRight(b[i], "/") { + return false + } + } + return true +}