Skip to content

Commit

Permalink
fix test name
Browse files Browse the repository at this point in the history
  • Loading branch information
elenagerman committed Jun 5, 2024
1 parent a119a61 commit 7e5bb6b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
11 changes: 9 additions & 2 deletions pkg/keda/triggerauthentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func NewTriggerAuthenticationBuilder(
"Initializing new triggerAuthentication structure with the following params: "+
"name: %s, namespace: %s", name, nsname)

if apiClient == nil {
glog.V(100).Infof("triggerAuthentication 'apiClient' cannot be empty")

return nil
}

builder := &TriggerAuthenticationBuilder{
apiClient: apiClient.Client,
Definition: &kedav2v1alpha1.TriggerAuthentication{
Expand Down Expand Up @@ -63,8 +69,9 @@ func NewTriggerAuthenticationBuilder(
return builder
}

// Pull pulls existing triggerAuthentication from cluster.
func Pull(apiClient *clients.Settings, name, nsname string) (*TriggerAuthenticationBuilder, error) {
// PullTriggerAuthentication pulls existing triggerAuthentication from cluster.
func PullTriggerAuthentication(apiClient *clients.Settings,
name, nsname string) (*TriggerAuthenticationBuilder, error) {
glog.V(100).Infof("Pulling existing triggerAuthentication name %s in namespace %s from cluster",
name, nsname)

Expand Down
50 changes: 30 additions & 20 deletions pkg/keda/triggerauthentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestPullTriggerAuthentication(t *testing.T) {
})
}

builderResult, err := Pull(testSettings, testCase.name, testCase.namespace)
builderResult, err := PullTriggerAuthentication(testSettings, testCase.name, testCase.namespace)
assert.Equal(t, testCase.expectedError, err)

if testCase.expectedError != nil {
Expand All @@ -108,33 +108,47 @@ func TestNewTriggerAuthenticationBuilder(t *testing.T) {
name string
namespace string
expectedError string
client bool
}{
{
name: defaultTriggerAuthName,
namespace: defaultTriggerAuthNamespace,
expectedError: "",
client: true,
},
{
name: "",
namespace: defaultTriggerAuthNamespace,
expectedError: "triggerAuthentication 'name' cannot be empty",
client: true,
},
{
name: defaultTriggerAuthName,
namespace: "",
expectedError: "triggerAuthentication 'nsname' cannot be empty",
expectedError: "",
client: false,
},
}

for _, testCase := range testCases {

Check failure on line 133 in pkg/keda/triggerauthentication_test.go

View workflow job for this annotation

GitHub Actions / build

block should not start with a whitespace (wsl)
testSettings := clients.GetTestClients(clients.TestClientParams{})

var testSettings *clients.Settings
if testCase.client {
testSettings = clients.GetTestClients(clients.TestClientParams{})
}

testTriggerAuthBuilder := NewTriggerAuthenticationBuilder(testSettings, testCase.name, testCase.namespace)
assert.Equal(t, testCase.expectedError, testTriggerAuthBuilder.errorMsg)
assert.NotNil(t, testTriggerAuthBuilder.Definition)

if testCase.expectedError == "" {
assert.Equal(t, testCase.name, testTriggerAuthBuilder.Definition.Name)
assert.Equal(t, testCase.namespace, testTriggerAuthBuilder.Definition.Namespace)
if testCase.client {
assert.Equal(t, testCase.name, testTriggerAuthBuilder.Definition.Name)
assert.Equal(t, testCase.namespace, testTriggerAuthBuilder.Definition.Namespace)
} else {
assert.Nil(t, testTriggerAuthBuilder)
}
} else {
assert.Equal(t, testCase.expectedError, testTriggerAuthBuilder.errorMsg)
assert.NotNil(t, testTriggerAuthBuilder.Definition)
}
}
}
Expand Down Expand Up @@ -198,25 +212,25 @@ func TestTriggerAuthenticationGet(t *testing.T) {

func TestTriggerAuthenticationCreate(t *testing.T) {
testCases := []struct {
TriggerAuth *TriggerAuthenticationBuilder
expectedError string
testTriggerAuth *TriggerAuthenticationBuilder
expectedError string
}{
{
TriggerAuth: buildValidTriggerAuthBuilder(buildTriggerAuthClientWithDummyObject()),
expectedError: "",
testTriggerAuth: buildValidTriggerAuthBuilder(buildTriggerAuthClientWithDummyObject()),
expectedError: "",
},
{
TriggerAuth: buildInValidTriggerAuthBuilder(buildTriggerAuthClientWithDummyObject()),
expectedError: " \"\" is invalid: metadata.name: Required value: name is required",
testTriggerAuth: buildInValidTriggerAuthBuilder(buildTriggerAuthClientWithDummyObject()),
expectedError: " \"\" is invalid: metadata.name: Required value: name is required",
},
{
TriggerAuth: buildValidTriggerAuthBuilder(clients.GetTestClients(clients.TestClientParams{})),
expectedError: "",
testTriggerAuth: buildValidTriggerAuthBuilder(clients.GetTestClients(clients.TestClientParams{})),
expectedError: "",
},
}

for _, testCase := range testCases {
testTriggerAuthBuilder, err := testCase.TriggerAuth.Create()
testTriggerAuthBuilder, err := testCase.testTriggerAuth.Create()

if testCase.expectedError == "" {
assert.Equal(t, testTriggerAuthBuilder.Definition.Name, testTriggerAuthBuilder.Object.Name)
Expand All @@ -237,10 +251,6 @@ func TestTriggerAuthenticationDelete(t *testing.T) {
testTriggerAuth: buildValidTriggerAuthBuilder(buildTriggerAuthClientWithDummyObject()),
expectedError: nil,
},
{
testTriggerAuth: buildInValidTriggerAuthBuilder(buildTriggerAuthClientWithDummyObject()),
expectedError: nil,
},
{
testTriggerAuth: buildValidTriggerAuthBuilder(clients.GetTestClients(clients.TestClientParams{})),
expectedError: nil,
Expand Down

0 comments on commit 7e5bb6b

Please sign in to comment.