-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,122 @@ package broker | |
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/kubernetes/fake" | ||
k8stesting "k8s.io/client-go/testing" | ||
"net/http/httptest" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/kyma-project/kyma-environment-broker/internal/fixture" | ||
"github.com/kyma-project/kyma-environment-broker/internal/storage" | ||
"github.com/pivotal-cf/brokerapi/v8/domain" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
<<<<<<< Updated upstream | ||
Check failure on line 21 in internal/broker/bind_create_test.go GitHub Actions / run-go-tests / build
Check failure on line 21 in internal/broker/bind_create_test.go GitHub Actions / run-govulncheck
Check failure on line 21 in internal/broker/bind_create_test.go GitHub Actions / run-go-linter
Check failure on line 21 in internal/broker/bind_create_test.go GitHub Actions / run-go-linter
Check failure on line 21 in internal/broker/bind_create_test.go GitHub Actions / run-go-linter
|
||
) | ||
|
||
======= | ||
Check failure on line 24 in internal/broker/bind_create_test.go GitHub Actions / run-go-linter
Check failure on line 24 in internal/broker/bind_create_test.go GitHub Actions / run-go-linter
|
||
|
||
"code.cloudfoundry.org/lager" | ||
"github.com/kyma-project/kyma-environment-broker/internal/storage/dberr" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type Kubeconfig struct { | ||
Users []User `yaml:"users"` | ||
} | ||
|
||
type User struct { | ||
Name string `yaml:"name"` | ||
User struct { | ||
Token string `yaml:"token"` | ||
} `yaml:"user"` | ||
} | ||
|
||
const ( | ||
instanceID1 = "1" | ||
instanceID2 = "2" | ||
instanceID3 = "max-bindings" | ||
) | ||
|
||
var httpServer *httptest.Server | ||
|
||
type provider struct { | ||
} | ||
|
||
func (p *provider) K8sClientSetForRuntimeID(runtimeID string) (kubernetes.Interface, error) { | ||
c := fake.NewSimpleClientset() | ||
c.PrependReactor("create", "serviceaccounts", func(action k8stesting.Action) (bool, runtime.Object, error) { | ||
return true, nil, fmt.Errorf("error") | ||
}) | ||
return c, nil | ||
} | ||
|
||
func TestCreateBindingEndpoint(t *testing.T) { | ||
t.Log("test create binding endpoint") | ||
|
||
// Given | ||
//// logger | ||
logs := logrus.New() | ||
logs.SetLevel(logrus.DebugLevel) | ||
logs.SetFormatter(&logrus.JSONFormatter{ | ||
TimestampFormat: time.RFC3339Nano, | ||
}) | ||
|
||
brokerLogger := lager.NewLogger("test") | ||
brokerLogger.RegisterSink(lager.NewWriterSink(logs.Writer(), lager.DEBUG)) | ||
|
||
//// schema | ||
|
||
//// database | ||
db := storage.NewMemoryStorage() | ||
|
||
err := db.Instances().Insert(fixture.FixInstance(instanceID1)) | ||
require.NoError(t, err) | ||
|
||
err = db.Instances().Insert(fixture.FixInstance(instanceID2)) | ||
require.NoError(t, err) | ||
|
||
err = db.Instances().Insert(fixture.FixInstance(instanceID3)) | ||
require.NoError(t, err) | ||
|
||
//// binding configuration | ||
bindingCfg := &BindingConfig{ | ||
Enabled: true, | ||
BindablePlans: EnablePlans{ | ||
fixture.PlanName, | ||
}, | ||
MaxBindingsCount: 10, | ||
} | ||
|
||
p := &provider{} //// api handler | ||
bindEndpoint := NewBind(*bindingCfg, db.Instances(), db.Bindings(), logs, p, nil) // test relies on checking if got nil on kubeconfig provider but the instance got inserted either way | ||
|
||
//t.Run("should INSERT binding despite error on k8s api call", func(t *testing.T) { | ||
// given | ||
_, err = db.Bindings().Get(instanceID1, "binding-id") | ||
require.Error(t, err) | ||
require.True(t, dberr.IsNotFound(err)) | ||
|
||
// when | ||
_, _ = bindEndpoint.Bind(context.Background(), instanceID1, "binding-id", domain.BindDetails{ | ||
ServiceID: "123", | ||
PlanID: fixture.PlanId, | ||
}, false) | ||
|
||
// then | ||
binding, err := db.Bindings().Get(instanceID1, "binding-id") | ||
require.NoError(t, err) | ||
require.Equal(t, instanceID1, binding.InstanceID) | ||
require.Equal(t, "binding-id", binding.ID) | ||
//}) | ||
} | ||
|
||
>>>>>>> Stashed changes | ||
Check failure on line 121 in internal/broker/bind_create_test.go GitHub Actions / run-go-linter
Check failure on line 121 in internal/broker/bind_create_test.go GitHub Actions / run-go-linter
|
||
func TestCreatedBy(t *testing.T) { | ||
emptyStr := "" | ||
email := "[email protected]" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,17 @@ paths: | |
description: Get Gardener cluster config | ||
schema: | ||
type: boolean | ||
- in: query | ||
name: bindings | ||
required: false | ||
description: Provides bindings for every runtime | ||
schema: | ||
type: boolean | ||
- in: query | ||
name: with_bindings | ||
description: Filter runtimes to show only those with bindings. | ||
schema: | ||
type: boolean | ||
- in: query | ||
name: state | ||
required: false | ||
|
@@ -1784,6 +1795,31 @@ components: | |
example: azure | ||
status: | ||
$ref: '#/components/schemas/StatusDTO' | ||
bindings: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/ServiceBindingDTO' | ||
|
||
ServiceBindingDTO: | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
example: 054ac2c2-318f-45dd-855c-eee41513d40d | ||
createdAt: | ||
type: string | ||
example: 2024-10-22T07:41:00.52046Z | ||
expiresInSeconds: | ||
type: integer | ||
example: 600 | ||
expiresAt: | ||
type: string | ||
example: 2024-10-22T07:51:00Z | ||
kubeconfigExists: | ||
type: boolean | ||
createdBy: | ||
type: string | ||
example: [email protected] | ||
|
||
EventDTO: | ||
type: object | ||
|