Skip to content

Commit

Permalink
Return configuration in json format (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
adelinag08 authored Mar 11, 2024
1 parent 2efd96f commit f736272
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.5

require (
github.com/MakeNowJust/heredoc v1.0.0
github.com/SneaksAndData/esd-services-api-client-go v0.0.7
github.com/SneaksAndData/esd-services-api-client-go v0.0.9
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
golang.org/x/mod v0.15.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/AzureAD/microsoft-authentication-library-for-go v1.2.0 h1:hVeq+yCyUi+
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.0/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
github.com/SneaksAndData/esd-services-api-client-go v0.0.7 h1:JhKb32ho2VA3NtWy+3DLECJ2DGVcnahTaOnHFu/WUZo=
github.com/SneaksAndData/esd-services-api-client-go v0.0.7/go.mod h1:StEYmGCRQ8IWA+UDcoMOTw/MpYmlFAfTTS15yeXy5Q4=
github.com/SneaksAndData/esd-services-api-client-go v0.0.9 h1:Ha6kBxG5n/I9bxarNNWiwKQY/cJQKNcfH4EyP8F79ZM=
github.com/SneaksAndData/esd-services-api-client-go v0.0.9/go.mod h1:StEYmGCRQ8IWA+UDcoMOTw/MpYmlFAfTTS15yeXy5Q4=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
11 changes: 8 additions & 3 deletions pkg/cmd/spark/configuration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package spark

import (
"encoding/json"
"fmt"
"github.com/SneaksAndData/esd-services-api-client-go/spark"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -34,11 +35,15 @@ func NewCmdConfiguration(authServiceFactory *cmdutil.AuthServiceFactory, service
return cmd
}

func configurationRun(sparkService Service, name string) (spark.SubmissionConfiguration, error) {
func configurationRun(sparkService Service, name string) (string, error) {
response, err := sparkService.GetConfiguration(name)
if err != nil {

return spark.SubmissionConfiguration{}, fmt.Errorf("failed to retrieve configuration with name %s: %w", name, err)
return "", fmt.Errorf("failed to retrieve configuration with name %s: %w", name, err)
}
return response, nil
m, err := json.Marshal(&response)
if err != nil {
return "", fmt.Errorf("Failed to serialize configuration: %w", err)
}
return string(m), nil
}
5 changes: 3 additions & 2 deletions pkg/cmd/spark/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ func Test_configurationRun(t *testing.T) {
mockResponse spark.SubmissionConfiguration
mockError error
expectedError bool
expectedResp spark.SubmissionConfiguration
expectedResp string
}{
{
name: "ExistingConfig",
mockResponse: spark.SubmissionConfiguration{
RootPath: "ExistingConfig",
},
expectedResp: "{\"rootPath\":\"ExistingConfig\",\"projectName\":\"\",\"runnable\":\"\",\"submissionDetails\":{\"version\":\"\",\"executionGroup\":\"\",\"expectedParallelism\":0,\"flexibleDriver\":false,\"additionalDriverNodeTolerations\":null,\"maxRuntimeHours\":0,\"debugMode\":{\"eventLogLocation\":\"\",\"maxSizePerFile\":\"\"},\"submissionMode\":\"\",\"extendedCodeMount\":false,\"submissionJobTemplate\":\"\",\"executorSpecTemplate\":\"\",\"driverJobRetries\":0,\"defaultArguments\":null,\"inputs\":null,\"outputs\":null,\"overwrite\":false}}",
expectedError: false,
},
{
Expand Down Expand Up @@ -48,7 +49,7 @@ func Test_configurationRun(t *testing.T) {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, tc.mockResponse, resp)
assert.Equal(t, tc.expectedResp, resp)
}

mockService.AssertExpectations(t)
Expand Down

0 comments on commit f736272

Please sign in to comment.