Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmiskiewicz committed Dec 12, 2024
1 parent 4ff73d7 commit cd48448
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions internal/broker/bind_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (p *provider) KubeconfigForRuntimeID(runtimeID string) ([]byte, error) {
return []byte{}, nil
}

func TestCreateBindingEndpoint(t *testing.T) {
func TestCreateBindingEndpoint_dbInsertionInCaseOfError(t *testing.T) {
t.Log("test create binding endpoint")

// Given
Expand Down Expand Up @@ -122,36 +122,6 @@ func TestCreateBindingEndpoint(t *testing.T) {
require.NotNil(t, binding.ExpiresAt)
require.Empty(t, binding.Kubeconfig)
})

t.Run("should return error when expiration_seconds is greater than maxExpirationSeconds", func(t *testing.T) {
// when
_, err := bindEndpoint.Bind(context.Background(), instanceID1, "binding-id-001", domain.BindDetails{
ServiceID: "123",
PlanID: fixture.PlanId,
RawParameters: json.RawMessage(`{"expirationSeconds": 10}`),
}, false)
require.Error(t, err)

// then
assert.IsType(t, err, &apiresponses.FailureResponse{}, "Get request returned error of unexpected type")
apierr := err.(*apiresponses.FailureResponse)
assert.Equal(t, http.StatusBadRequest, apierr.ValidatedStatusCode(nil), "Get request status code not matching")
})

t.Run("should return error when expiration_seconds is less than minExpirationSeconds", func(t *testing.T) {
// when
_, err := bindEndpoint.Bind(context.Background(), instanceID1, "binding-id-002", domain.BindDetails{
ServiceID: "123",
PlanID: fixture.PlanId,
RawParameters: json.RawMessage(`{"expirationSeconds": 100000}`),
}, false)
require.Error(t, err)

// then
assert.IsType(t, err, &apiresponses.FailureResponse{}, "Get request returned error of unexpected type")
apierr := err.(*apiresponses.FailureResponse)
assert.Equal(t, http.StatusBadRequest, apierr.ValidatedStatusCode(nil), "Get request status code not matching")
})
}

func TestCreateBindingExceedsAllowedNumberOfNonExpiredBindings(t *testing.T) {
Expand Down Expand Up @@ -193,7 +163,7 @@ func TestCreateBindingExceedsAllowedNumberOfNonExpiredBindings(t *testing.T) {

}

func TestCreateBindng(t *testing.T) {
func TestCreateBindingEndpoint(t *testing.T) {
bindEndpoint, _ := prepareBindingEndpoint(t, fixBindingConfig())

t.Run("should return error when expiration_seconds is less than minExpirationSeconds", func(t *testing.T) {
Expand Down Expand Up @@ -234,6 +204,18 @@ func TestCreateBindng(t *testing.T) {
assert.NotEmptyf(t, binding.Credentials.(Credentials).Kubeconfig, "kubeconfig is empty")
})

t.Run("should create binding with expiration seconds provided", func(t *testing.T) {
binding, err := bindEndpoint.Bind(context.Background(), instanceID1, "binding-id-003", domain.BindDetails{
ServiceID: "123",
PlanID: fixture.PlanId,
RawParameters: json.RawMessage(`{"expiration_seconds": 1000}`),
}, false)

// then
require.NoError(t, err)
assert.NotEmptyf(t, binding.Credentials.(Credentials).Kubeconfig, "kubeconfig is empty")
})

t.Run("should report a conflict", func(t *testing.T) {
_, err := bindEndpoint.Bind(context.Background(), instanceID1, "binding-id-004", domain.BindDetails{
ServiceID: "123",
Expand All @@ -258,6 +240,27 @@ func TestCreateBindng(t *testing.T) {
assert.Equal(t, http.StatusConflict, apierr.ValidatedStatusCode(nil), "Get request status code not matching")
})

t.Run("should not report a conflict if parameters are the same", func(t *testing.T) {
_, err := bindEndpoint.Bind(context.Background(), instanceID1, "binding-id-005", domain.BindDetails{
ServiceID: "123",
PlanID: fixture.PlanId,
RawParameters: json.RawMessage(`{"expiration_seconds": 1000}`),
}, false)

// then
require.NoError(t, err)

// when
_, err = bindEndpoint.Bind(context.Background(), instanceID1, "binding-id-005", domain.BindDetails{
ServiceID: "123",
PlanID: fixture.PlanId,
RawParameters: json.RawMessage(`{"expiration_seconds": 1000}`),
}, false)

// then
require.NoError(t, err)
})

}

func TestCreatedBy(t *testing.T) {
Expand Down

0 comments on commit cd48448

Please sign in to comment.