-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
309 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ extension-postman | |
*.iml | ||
/vendor | ||
coverage.out | ||
/e2e/e2e-coverage-docker.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2022 Steadybit GmbH | ||
|
||
package config | ||
|
||
import ( | ||
"github.com/kelseyhightower/envconfig" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
var ( | ||
Config Specification | ||
) | ||
|
||
func ParseConfiguration() { | ||
err := envconfig.Process("steadybit_extension", &Config) | ||
if err != nil { | ||
log.Fatal().Err(err).Msgf("Failed to parse configuration from environment.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2022 Steadybit GmbH | ||
|
||
package config | ||
|
||
type Specification struct { | ||
PostmanBaseUrl string `json:"postmanBaseUrl" split_words:"true" required:"false" default:"https://api.getpostman.com"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2023 Steadybit GmbH | ||
|
||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"github.com/steadybit/action-kit/go/action_kit_test/e2e" | ||
"github.com/steadybit/extension-kit/extlogging" | ||
"github.com/stretchr/testify/require" | ||
"strings" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestWithMinikube(t *testing.T) { | ||
extlogging.InitZeroLog() | ||
server := createMockPostmanServer() | ||
defer server.Close() | ||
split := strings.SplitAfter(server.URL, ":") | ||
port := split[len(split)-1] | ||
|
||
extFactory := e2e.HelmExtensionFactory{ | ||
Name: "extension-postman", | ||
Port: 8086, | ||
ExtraArgs: func(m *e2e.Minikube) []string { | ||
return []string{ | ||
"--set", "logging.level=debug", | ||
"--set", "extraEnv[0].name=STEADYBIT_EXTENSION_POSTMAN_BASE_URL", | ||
"--set", fmt.Sprintf("extraEnv[0].value=%s:%s", "http://host.minikube.internal:", port), | ||
} | ||
}, | ||
} | ||
|
||
e2e.WithDefaultMinikube(t, &extFactory, []e2e.WithMinikubeTestCase{ | ||
{ | ||
Name: "run postman", | ||
Test: testRunPostman, | ||
}, | ||
}) | ||
} | ||
|
||
func testRunPostman(t *testing.T, m *e2e.Minikube, e *e2e.Extension) { | ||
config := struct { | ||
CollectionId string | ||
ApiKey string | ||
}{ | ||
CollectionId: "testCollectionId", | ||
ApiKey: "testApiKey", | ||
} | ||
|
||
exec, err := e.RunAction("com.steadybit.extension_postman.collection.run", nil, config, nil) | ||
require.NoError(t, err) | ||
e2e.AssertLogContainsWithTimeout(t, m, e.Pod, "Starting newman!", 90*time.Second) | ||
e2e.AssertLogContainsWithTimeout(t, m, e.Pod, "Postman run completed successfully", 90*time.Second) | ||
require.NoError(t, exec.Cancel()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"github.com/rs/zerolog/log" | ||
"net" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
) | ||
|
||
func createMockPostmanServer() *httptest.Server { | ||
listener, err := net.Listen("tcp", "0.0.0.0:0") | ||
if err != nil { | ||
panic(fmt.Sprintf("httptest: failed to listen: %v", err)) | ||
} | ||
server := httptest.Server{ | ||
Listener: listener, | ||
Config: &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
log.Info().Str("path", r.URL.Path).Str("method", r.Method).Str("query", r.URL.RawQuery).Msg("Request received") | ||
if strings.Contains(r.URL.Path, "collections/testCollectionId") { | ||
w.WriteHeader(http.StatusOK) | ||
w.Write(getCollection()) | ||
} else { | ||
w.WriteHeader(http.StatusBadRequest) | ||
} | ||
})}, | ||
} | ||
server.Start() | ||
log.Info().Str("url", server.URL).Msg("Started Mock-Server") | ||
return &server | ||
} | ||
|
||
func getCollection() []byte { | ||
log.Info().Msg("Return collection") | ||
return []byte(`{"collection":{"info":{"_postman_id":"1c89f353-9e9d-4daf-9442-bc64f4c1b29b","name":"Simple Get","schema":"https://schema.getpostman.com/json/collection/v2.1.0/collection.json","updatedAt":"2023-09-14T11:22:30.000Z","uid":"21222108-1c89f353-9e9d-4daf-9442-bc64f4c1b29b"},"item":[{"name":"Is google online","event":[{"listen":"test","script":{"id":"13df8fb5-f68d-4822-93b4-a6a67c512420","exec":["pm.test(\"Body matches string\", function () {"," pm.expect(pm.response.text()).to.include(\"Google\");","});"],"type":"text/javascript"}}],"id":"fd6c6e49-dbf2-4f21-92ef-c0a2bf10b426","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":{"raw":"https://www.google.de","protocol":"https","host":["www","google","de"]}},"response":[],"uid":"21222108-fd6c6e49-dbf2-4f21-92ef-c0a2bf10b426"}]}}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.