Skip to content

Commit

Permalink
Move binding createdBy tests (#1356)
Browse files Browse the repository at this point in the history
* Move binding createdBy tests

* wip
  • Loading branch information
KsaweryZietara authored Oct 17, 2024
1 parent c7b718b commit dc87347
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 53 deletions.
53 changes: 0 additions & 53 deletions cmd/broker/bind_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,59 +513,6 @@ func assertServiceAccountsNotExists(t *testing.T, k8sClient client.Client, bindi
assert.True(t, apierrors.IsNotFound(err))
}

func TestCreatedBy(t *testing.T) {
emptyStr := ""
email := "[email protected]"
origin := "origin"
tests := []struct {
name string
context broker.BindingContext
expected string
}{
{
name: "Both Email and Origin are nil",
context: broker.BindingContext{Email: nil, Origin: nil},
expected: "",
},
{
name: "Both Email and Origin are empty",
context: broker.BindingContext{Email: &emptyStr, Origin: &emptyStr},
expected: "",
},
{
name: "Origin is nil",
context: broker.BindingContext{Email: &email, Origin: nil},
expected: "[email protected]",
},
{
name: "Origin is empty",
context: broker.BindingContext{Email: &email, Origin: &emptyStr},
expected: "[email protected]",
},
{
name: "Email is nil",
context: broker.BindingContext{Email: nil, Origin: &origin},
expected: "origin",
},
{
name: "Email is empty",
context: broker.BindingContext{Email: &emptyStr, Origin: &origin},
expected: "origin",
},
{
name: "Both Email and Origin are set",
context: broker.BindingContext{Email: &email, Origin: &origin},
expected: "[email protected]",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, tt.context.CreatedBy())
})
}
}

func assertExistsAndKubeconfigCreated(t *testing.T, actual domain.Binding, bindingID, instanceID string, httpServer *httptest.Server, db storage.BrokerStorage) {
expected, err := db.Bindings().Get(instanceID, bindingID)
require.NoError(t, err)
Expand Down
60 changes: 60 additions & 0 deletions internal/broker/bind_create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package broker

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCreatedBy(t *testing.T) {
emptyStr := ""
email := "[email protected]"
origin := "origin"
tests := []struct {
name string
context BindingContext
expected string
}{
{
name: "Both Email and Origin are nil",
context: BindingContext{Email: nil, Origin: nil},
expected: "",
},
{
name: "Both Email and Origin are empty",
context: BindingContext{Email: &emptyStr, Origin: &emptyStr},
expected: "",
},
{
name: "Origin is nil",
context: BindingContext{Email: &email, Origin: nil},
expected: "[email protected]",
},
{
name: "Origin is empty",
context: BindingContext{Email: &email, Origin: &emptyStr},
expected: "[email protected]",
},
{
name: "Email is nil",
context: BindingContext{Email: nil, Origin: &origin},
expected: "origin",
},
{
name: "Email is empty",
context: BindingContext{Email: &emptyStr, Origin: &origin},
expected: "origin",
},
{
name: "Both Email and Origin are set",
context: BindingContext{Email: &email, Origin: &origin},
expected: "[email protected]",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, tt.context.CreatedBy())
})
}
}

0 comments on commit dc87347

Please sign in to comment.