-
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.
Corrected Binding Insert Order (#1366)
* Corrected Binding Insert Order * Linter * Review Remarks - Removed Unnecessary Configs * Test Correction * Import Issues Fix * Linter * Update with Created Kubeconfig * Corrected Memory Bindings Repository to Reflect Real Usage * Setting ExpiresAt * Linter * Merge Correction * Review Remarks - #1366 (comment) * Linter * Update internal/storage/driver/memory/binding.go Co-authored-by: Jarosław Pieszka <[email protected]> * Update internal/storage/driver/memory/binding.go Co-authored-by: Jarosław Pieszka <[email protected]> --------- Co-authored-by: Jarosław Pieszka <[email protected]>
- Loading branch information
1 parent
4490219
commit 07fa3b9
Showing
7 changed files
with
169 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,120 @@ package broker | |
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http/httptest" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
"k8s.io/client-go/kubernetes" | ||
|
||
"code.cloudfoundry.org/lager" | ||
"github.com/kyma-project/kyma-environment-broker/internal/fixture" | ||
"github.com/kyma-project/kyma-environment-broker/internal/storage" | ||
"github.com/kyma-project/kyma-environment-broker/internal/storage/dberr" | ||
"github.com/pivotal-cf/brokerapi/v8/domain" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
"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" | ||
maxBindingsCount = 10 | ||
) | ||
|
||
var httpServer *httptest.Server | ||
|
||
type provider struct { | ||
} | ||
|
||
func (p *provider) K8sClientSetForRuntimeID(runtimeID string) (kubernetes.Interface, error) { | ||
return nil, fmt.Errorf("error") | ||
} | ||
|
||
func (p *provider) KubeconfigForRuntimeID(runtimeID string) ([]byte, error) { | ||
return []byte{}, 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: maxBindingsCount, | ||
} | ||
|
||
//// api handler | ||
bindEndpoint := NewBind(*bindingCfg, db, logs, &provider{}, &provider{}) | ||
|
||
// 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 | ||
_, err = bindEndpoint.Bind(context.Background(), instanceID1, "binding-id", domain.BindDetails{ | ||
ServiceID: "123", | ||
PlanID: fixture.PlanId, | ||
}, false) | ||
|
||
require.Error(t, err) | ||
|
||
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) | ||
|
||
require.NotNil(t, binding.ExpiresAt) | ||
require.Empty(t, binding.Kubeconfig) | ||
}) | ||
} | ||
|
||
func TestCreatedBy(t *testing.T) { | ||
emptyStr := "" | ||
email := "[email protected]" | ||
|
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
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