From 4a509bb5f14bb853eb0656455e9597c40991eedf Mon Sep 17 00:00:00 2001 From: punithnayak Date: Wed, 2 Aug 2023 19:13:47 +0530 Subject: [PATCH] [WIP]Fixed:Compilation errors in choas_hub/handler tests Signed-off-by: punithnayak --- .../server/pkg/chaoshub/handler/handler.go | 2 +- .../pkg/chaoshub/handler/handler_test.go | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler.go b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler.go index db3f4f535a2..aba7fc45d48 100644 --- a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler.go +++ b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler.go @@ -29,7 +29,7 @@ const DefaultPath = "/tmp/" func GetChartsPath(chartsInput model.CloningInput, projectID string, isDefault bool) string { var repoPath string if isDefault { - repoPath = DefaultPath + "/default/" + chartsInput.Name + "/faults/" + repoPath = DefaultPath + "default/" + chartsInput.Name + "/faults/" } else { repoPath = DefaultPath + projectID + "/" + chartsInput.Name + "/faults/" } diff --git a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_test.go b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_test.go index e81e73a5513..2bc9a48c52e 100644 --- a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_test.go +++ b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_test.go @@ -33,9 +33,22 @@ func TestGetChartsPath(t *testing.T) { Name: "test", } // when - path := handler.GetChartsPath(chartsInput, projectID) + path := handler.GetChartsPath(chartsInput, projectID, true) // then - assert.Equal(t, "/tmp/version/test/test/charts/", path) + assert.Equal(t, "/tmp/default/test/faults/", path) +} + +func TestGetChartsPathFalse(t *testing.T) { + // given + projectID := "test" + + chartsInput := model.CloningInput{ + Name: "test", + } + // when + path := handler.GetChartsPath(chartsInput, projectID, false) + // then + assert.Equal(t, "/tmp/test/test/faults/", path) } // TestReadExperimentFile is used to test the ReadExperimentFile function @@ -273,6 +286,7 @@ func TestGetChartsData(t *testing.T) { RepoBranch: "master", IsPrivate: false, }, + isError: false, }, { name: "invalid url", @@ -290,7 +304,7 @@ func TestGetChartsData(t *testing.T) { t.Run(tc.name, func(t *testing.T) { if tc.isError { // when - chartsPath := handler.GetChartsPath(tc.repoData, tc.projectID) + chartsPath := handler.GetChartsPath(tc.repoData, tc.projectID, false) _, err := handler.GetChartsData(chartsPath) // then assert.Error(t, err) @@ -300,7 +314,7 @@ func TestGetChartsData(t *testing.T) { err := chaosHubOps.GitClone(tc.repoData, tc.projectID) assert.NoError(t, err) - chartsPath := handler.GetChartsPath(tc.repoData, tc.projectID) + chartsPath := handler.GetChartsPath(tc.repoData, tc.projectID, true) // when _, err = handler.GetChartsData(chartsPath) // then