Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move binding createdBy tests #1356

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
})
}
}
Loading