Skip to content

Commit

Permalink
Update the Swagger for runtimes endpoint (bindings)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmiskiewicz committed Oct 23, 2024
1 parent f27310b commit 591d3d4
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
106 changes: 106 additions & 0 deletions internal/broker/bind_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / run-go-tests / build

missing import path

Check failure on line 21 in internal/broker/bind_create_test.go

View workflow job for this annotation

GitHub Actions / run-govulncheck

missing import path

Check failure on line 21 in internal/broker/bind_create_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

syntax error: missing import path

Check failure on line 21 in internal/broker/bind_create_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

syntax error: missing import path

Check failure on line 21 in internal/broker/bind_create_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

syntax error: missing import path

Check failure on line 21 in internal/broker/bind_create_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

syntax error: missing import path
)

=======

Check failure on line 24 in internal/broker/bind_create_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

syntax error: non-declaration statement outside function body

Check failure on line 24 in internal/broker/bind_create_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

syntax error: non-declaration statement outside function body

Check failure on line 24 in internal/broker/bind_create_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

syntax error: non-declaration statement outside function body

"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

View workflow job for this annotation

GitHub Actions / run-go-linter

syntax error: non-declaration statement outside function body

Check failure on line 121 in internal/broker/bind_create_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

syntax error: non-declaration statement outside function body)

Check failure on line 121 in internal/broker/bind_create_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

syntax error: non-declaration statement outside function body
func TestCreatedBy(t *testing.T) {
emptyStr := ""
email := "[email protected]"
Expand Down
36 changes: 36 additions & 0 deletions resources/keb/files/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 591d3d4

Please sign in to comment.