Skip to content

Commit

Permalink
fix: update function parameter for passing test cases (#4016)
Browse files Browse the repository at this point in the history
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Co-authored-by: Amit Kumar Das <amit.das@harness.io>
  • Loading branch information
namkyu1999 and amityt committed Jun 21, 2023
1 parent ab0aa7a commit 30cbd7c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
9 changes: 2 additions & 7 deletions litmus-portal/graphql-server/graph/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
imageRegistry "github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/image_registry"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/k8s"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/usage"
log "github.com/sirupsen/logrus"
)

// This file will not be regenerated automatically.
Expand All @@ -43,7 +42,7 @@ type Resolver struct {
}

// NewConfig returns a new generated.Config
func NewConfig(mongodbOperator mongodb.MongoOperator) generated.Config {
func NewConfig(mongodbOperator mongodb.MongoOperator, kubeClients *k8s.KubeClients) generated.Config {
// operator
chaosHubOperator := dbSchemaChaosHub.NewChaosHubOperator(mongodbOperator)
clusterOperator := dbSchemaCluster.NewClusterOperator(mongodbOperator)
Expand All @@ -53,12 +52,8 @@ func NewConfig(mongodbOperator mongodb.MongoOperator) generated.Config {
analyticsOperator := dbSchemaAnalytics.NewAnalyticsOperator(mongodbOperator)
imageRegistryOperator := dbOperationsImageRegistry.NewImageRegistryOperator(mongodbOperator)

kubeCluster, err := k8s.NewKubeCluster()
if err != nil {
log.Fatalf("Error in getting k8s cluster, err: %v", err)
}
// service
clusterService := cluster.NewService(clusterOperator, chaosWorkflowOperator, kubeCluster)
clusterService := cluster.NewService(clusterOperator, chaosWorkflowOperator, kubeClients)
chaosHubService := chaoshub.NewService(chaosHubOperator)
analyticsService := service.NewService(analyticsOperator, chaosWorkflowOperator, clusterService)
usageService := usage.NewService(clusterOperator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ import (
)

// FileHandler dynamically generates the manifest file and sends it as a response
func FileHandler(mongodbOperator mongodb.MongoOperator) gin.HandlerFunc {
func FileHandler(mongodbOperator mongodb.MongoOperator, kubeClients *k8s.KubeClients) gin.HandlerFunc {
return func(c *gin.Context) {
token := strings.TrimSuffix(c.Param("key"), ".yaml")
kubeCluster, err := k8s.NewKubeCluster()
if err != nil {
log.Fatalf("error while getting kube config: %v", err)
}

response, statusCode, err := cluster.NewService(
dbSchemaCluster.NewClusterOperator(mongodbOperator),
dbOperationsWorkflow.NewChaosWorkflowOperator(mongodbOperator),
kubeCluster,
kubeClients,
).GetManifest(token)
if err != nil {
log.WithError(err).Error("error while generating manifest file")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/cluster"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/database/mongodb"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/database/mongodb/model/mocks"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/k8s"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/rest_handlers"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/utils"
"github.com/stretchr/testify/assert"
Expand All @@ -24,6 +25,7 @@ func TestFileHandler(t *testing.T) {
w *httptest.ResponseRecorder
ctx *gin.Context
mongoOperator = new(mocks.MongoOperator)
kubeClients = new(k8s.KubeClients)
)
testcases := []struct {
name string
Expand Down Expand Up @@ -105,10 +107,11 @@ metadata:
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
// given
tc.given()
// when
rest_handlers.FileHandler(mongoOperator)(ctx)

// when
rest_handlers.FileHandler(mongoOperator, kubeClients)(ctx)
// then
assert.Equal(t, w.Code, tc.statusCode)
})
Expand Down
10 changes: 8 additions & 2 deletions litmus-portal/graphql-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
dbOperationsGitOps "github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/database/mongodb/gitops"
dbOperationsWorkflow "github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/database/mongodb/workflow"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/gitops"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/k8s"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/projects"
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/rest_handlers"
pb "github.com/litmuschaos/litmus/litmus-portal/graphql-server/protos"
Expand Down Expand Up @@ -105,7 +106,12 @@ func main() {

go startGRPCServer(utils.Config.RpcPort, mongodbOperator) // start GRPC server

srv := handler.New(generated.NewExecutableSchema(graph.NewConfig(mongodbOperator)))
kubeClients, err := k8s.NewKubeCluster()
if err != nil {
log.Fatalf("Error in getting k8s cluster, err: %v", err)
}

srv := handler.New(generated.NewExecutableSchema(graph.NewConfig(mongodbOperator, kubeClients)))
srv.AddTransport(transport.POST{})
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.Websocket{
Expand Down Expand Up @@ -136,7 +142,7 @@ func main() {
router.Any("/query", authorization.Middleware(srv))
router.GET("/readiness", rest_handlers.ReadinessHandler(client, mongodbOperator))
router.GET("/icon/:ProjectID/:HubName/:ChartName/:IconName", authorization.RestMiddlewareWithRole(rest_handlers.GetIconHandler, nil))
router.Any("/file/:key", rest_handlers.FileHandler(mongodbOperator))
router.Any("/file/:key", rest_handlers.FileHandler(mongodbOperator, kubeClients))
router.GET("/status", rest_handlers.StatusHandler)
router.GET("/workflow_helper_image_version", rest_handlers.WorkflowHelperImageVersionHandler)

Expand Down

0 comments on commit 30cbd7c

Please sign in to comment.