From cb16ad1184bb6ffddd23bc2aefb497602a728fa8 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Fri, 9 Dec 2022 15:41:04 +0100 Subject: [PATCH] Add RequireSuccessfulRun helper (#125) --- internal/api_test.go | 14 ++++---------- internal/helpers.go | 7 +++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/api_test.go b/internal/api_test.go index 80825fe4..190f9654 100644 --- a/internal/api_test.go +++ b/internal/api_test.go @@ -15,13 +15,11 @@ import ( func TestAccApiGet(t *testing.T) { t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) - c := NewCobraTestRunner(t, "api", "get", "/api/2.0/preview/scim/v2/Me") - stdout, _, err := c.Run() - require.NoError(t, err) + stdout, _ := RequireSuccessfulRun(t, "api", "get", "/api/2.0/preview/scim/v2/Me") // Deserialize SCIM API response. var out map[string]any - err = json.Unmarshal(stdout.Bytes(), &out) + err := json.Unmarshal(stdout.Bytes(), &out) require.NoError(t, err) // Assert that the output somewhat makes sense for the SCIM API. @@ -43,15 +41,11 @@ func TestAccApiPost(t *testing.T) { // Post to mkdir { - c := NewCobraTestRunner(t, "api", "post", "--body=@"+requestPath, "/api/2.0/dbfs/mkdirs") - _, _, err := c.Run() - require.NoError(t, err) + RequireSuccessfulRun(t, "api", "post", "--body=@"+requestPath, "/api/2.0/dbfs/mkdirs") } // Post to delete { - c := NewCobraTestRunner(t, "api", "post", "--body=@"+requestPath, "/api/2.0/dbfs/delete") - _, _, err := c.Run() - require.NoError(t, err) + RequireSuccessfulRun(t, "api", "post", "--body=@"+requestPath, "/api/2.0/dbfs/delete") } } diff --git a/internal/helpers.go b/internal/helpers.go index 515ef3d3..ec349a94 100644 --- a/internal/helpers.go +++ b/internal/helpers.go @@ -151,6 +151,13 @@ func NewCobraTestRunner(t *testing.T, args ...string) *cobraTestRunner { } } +func RequireSuccessfulRun(t *testing.T, args ...string) (bytes.Buffer, bytes.Buffer) { + c := NewCobraTestRunner(t, args...) + stdout, stderr, err := c.Run() + require.NoError(t, err) + return stdout, stderr +} + func writeFile(t *testing.T, name string, body string) string { f, err := os.Create(filepath.Join(t.TempDir(), name)) require.NoError(t, err)