-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create e2e provisioning API test (#1371)
* Create e2e provisioning API test * Test bindings API * Test secret existence with kubeconfig from binding * Refactor files structure * Rename folder * Update docs * Rename test * Change require no error to assertion * Update end-2-end tests docs * Extract paths to functions * Update docs * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs/contributor/05-10-e2e_tests.md Co-authored-by: Iwona Langer <[email protected]> * Update docs * Update docs * Update docs --------- Co-authored-by: Iwona Langer <[email protected]>
- Loading branch information
1 parent
251b8bc
commit 9244517
Showing
9 changed files
with
808 additions
and
40 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
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,9 @@ | ||
APP_PROVISIONING_URL= | ||
APP_PROVISIONING_CLIENT_ID= | ||
APP_PROVISIONING_CLIENT_SECRET= | ||
APP_PROVISIONING_UAA_URL= | ||
APP_PROVISIONING_PLAN_NAME= | ||
APP_PROVISIONING_PLAN_ID= | ||
APP_PROVISIONING_USER= | ||
APP_PROVISIONING_INSTANCE_NAME= | ||
APP_PROVISIONING_REGION= |
62 changes: 62 additions & 0 deletions
62
testing/e2e/skr/provisioning-service-test/cmd/provisioning_service_test.go
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,62 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestProvisioningService(t *testing.T) { | ||
suite := NewProvisioningSuite(t) | ||
|
||
suite.logger.Info("Creating a new environment") | ||
environment, err := suite.provisioningClient.CreateEnvironment() | ||
require.NoError(t, err) | ||
|
||
err = suite.provisioningClient.AwaitEnvironmentCreated(environment.ID) | ||
assert.NoError(t, err) | ||
suite.logger.Info("Environment created successfully", "environmentID", environment.ID) | ||
|
||
suite.logger.Info("Creating a new binding") | ||
createdBinding, err := suite.provisioningClient.CreateBinding(environment.ID) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, createdBinding.Credentials.Kubeconfig) | ||
|
||
if len(createdBinding.Credentials.Kubeconfig) != 0 { | ||
suite.logger.Info("Creating a new K8s client set") | ||
clientset, err := suite.K8sClientSetForKubeconfig(createdBinding.Credentials.Kubeconfig) | ||
assert.NoError(t, err) | ||
|
||
suite.logger.Info("Fetching a secret", "Secret namespace", secretNamespace, "Secret name", secretName) | ||
_, err = clientset.CoreV1().Secrets(secretNamespace).Get(context.TODO(), secretName, metav1.GetOptions{}) | ||
assert.NoError(t, err) | ||
|
||
suite.logger.Info("Fetching a binding", "Binding ID", createdBinding.ID) | ||
fetchedBinding, err := suite.provisioningClient.GetBinding(environment.ID, createdBinding.ID) | ||
assert.NoError(t, err) | ||
assert.Equal(t, createdBinding.Credentials.Kubeconfig, fetchedBinding.Credentials.Kubeconfig) | ||
|
||
suite.logger.Info("Deleting a binding", "Binding ID", createdBinding.ID) | ||
err = suite.provisioningClient.DeleteBinding(environment.ID, createdBinding.ID) | ||
assert.NoError(t, err) | ||
|
||
suite.logger.Info("Trying to fetch a secret using invalidated kubeconfig", "Secret namespace", secretNamespace, "Secret name", secretName) | ||
_, err = clientset.CoreV1().Secrets(secretNamespace).Get(context.TODO(), secretName, metav1.GetOptions{}) | ||
assert.Error(t, err) | ||
|
||
suite.logger.Info("Trying to fetch a deleted binding", "Binding ID", createdBinding.ID) | ||
_, err = suite.provisioningClient.GetBinding(environment.ID, createdBinding.ID) | ||
assert.EqualError(t, err, "unexpected status code 404: body is empty") | ||
} | ||
|
||
suite.logger.Info("Deleting the environment", "environmentID", environment.ID) | ||
_, err = suite.provisioningClient.DeleteEnvironment(environment.ID) | ||
require.NoError(t, err) | ||
|
||
err = suite.provisioningClient.AwaitEnvironmentDeleted(environment.ID) | ||
assert.NoError(t, err) | ||
suite.logger.Info("Environment deleted successfully", "environmentID", environment.ID) | ||
} |
66 changes: 66 additions & 0 deletions
66
testing/e2e/skr/provisioning-service-test/cmd/suite_test.go
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,66 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
"os" | ||
"testing" | ||
|
||
"github.com/kyma-project/kyma-environment-broker/testing/e2e/skr/provisioning-service-test/internal" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/vrischmann/envconfig" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
const ( | ||
secretNamespace = "kyma-system" | ||
secretName = "sap-btp-manager" | ||
) | ||
|
||
type Config struct { | ||
Provisioning internal.ProvisioningConfig | ||
} | ||
|
||
type ProvisioningSuite struct { | ||
t *testing.T | ||
logger *slog.Logger | ||
|
||
provisioningClient *internal.ProvisioningClient | ||
} | ||
|
||
func NewProvisioningSuite(t *testing.T) *ProvisioningSuite { | ||
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})) | ||
|
||
ctx := context.Background() | ||
|
||
var cfg Config | ||
err := envconfig.InitWithPrefix(&cfg, "APP") | ||
require.NoError(t, err) | ||
|
||
logger.Info("Creating a new provisioning client") | ||
provisioningClient := internal.NewProvisioningClient(cfg.Provisioning, logger, ctx, 60) | ||
err = provisioningClient.GetAccessToken() | ||
require.NoError(t, err) | ||
|
||
return &ProvisioningSuite{ | ||
t: t, | ||
logger: logger, | ||
provisioningClient: provisioningClient, | ||
} | ||
} | ||
|
||
func (p *ProvisioningSuite) K8sClientSetForKubeconfig(kubeconfig string) (kubernetes.Interface, error) { | ||
config, err := clientcmd.RESTConfigFromKubeConfig([]byte(kubeconfig)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
clientset, err := kubernetes.NewForConfig(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return clientset, nil | ||
} |
Oops, something went wrong.