generated from kedacore/github-template
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: provide support to allow HTTP scaler to work alongside other co…
…re KEDA scalers Signed-off-by: Paul Cooke <Paul.Cooke@10xbanking.com>
- Loading branch information
Showing
6 changed files
with
492 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
operator/controllers/http/httpscaledobject_controller_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package http | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/kedacore/http-add-on/operator/controllers/http/config" | ||
) | ||
|
||
func TestHttpScaledObjectControllerWhenSkipAnnotationNotSet(t *testing.T) { | ||
r := require.New(t) | ||
|
||
testInfra := newCommonTestInfra("testns", "testapp") | ||
|
||
reconciller := &HTTPScaledObjectReconciler{ | ||
Client: testInfra.cl, | ||
Scheme: testInfra.cl.Scheme(), | ||
ExternalScalerConfig: config.ExternalScaler{}, | ||
BaseConfig: config.Base{}, | ||
} | ||
|
||
// Create required app objects for the application defined by the CRD | ||
err := reconciller.createOrUpdateApplicationResources( | ||
testInfra.ctx, | ||
testInfra.logger, | ||
testInfra.cl, | ||
config.Base{}, | ||
config.ExternalScaler{}, | ||
&testInfra.httpso, | ||
) | ||
r.NoError(err) | ||
|
||
// check for scaledobject, expect no error as scaledobject should get created | ||
_, err = getSO( | ||
testInfra.ctx, | ||
testInfra.cl, | ||
testInfra.httpso, | ||
) | ||
r.NoError(err) | ||
} | ||
|
||
func TestHttpScaledObjectControllerWhenSkipAnnotationSet(t *testing.T) { | ||
r := require.New(t) | ||
|
||
testInfra := newCommonTestInfraWithSkipScaledObjectCreation("testns", "testapp") | ||
|
||
reconciller := &HTTPScaledObjectReconciler{ | ||
Client: testInfra.cl, | ||
Scheme: testInfra.cl.Scheme(), | ||
ExternalScalerConfig: config.ExternalScaler{}, | ||
BaseConfig: config.Base{}, | ||
} | ||
|
||
// Create required app objects for the application defined by the CRD | ||
err := reconciller.createOrUpdateApplicationResources( | ||
testInfra.ctx, | ||
testInfra.logger, | ||
testInfra.cl, | ||
config.Base{}, | ||
config.ExternalScaler{}, | ||
&testInfra.httpso, | ||
) | ||
r.NoError(err) | ||
|
||
// check for scaledobject, expect error as scaledobject should not exist when skipScaledObjectCreation annotation is set | ||
_, err = getSO( | ||
testInfra.ctx, | ||
testInfra.cl, | ||
testInfra.httpso, | ||
) | ||
r.Error(err) | ||
} | ||
|
||
func TestHttpScaledObjectControllerWhenSkipAnnotationAddedToExistingHttpSo(t *testing.T) { | ||
r := require.New(t) | ||
|
||
testInfra := newCommonTestInfra("testns", "testapp") | ||
|
||
reconciller := &HTTPScaledObjectReconciler{ | ||
Client: testInfra.cl, | ||
Scheme: testInfra.cl.Scheme(), | ||
ExternalScalerConfig: config.ExternalScaler{}, | ||
BaseConfig: config.Base{}, | ||
} | ||
|
||
// Create required app objects for the application defined by the CRD | ||
err := reconciller.createOrUpdateApplicationResources( | ||
testInfra.ctx, | ||
testInfra.logger, | ||
testInfra.cl, | ||
config.Base{}, | ||
config.ExternalScaler{}, | ||
&testInfra.httpso, | ||
) | ||
r.NoError(err) | ||
|
||
// check for scaledobject, expect no error as scaledobject should exist when skipScaledObjectCreation annotation is not set | ||
_, err = getSO( | ||
testInfra.ctx, | ||
testInfra.cl, | ||
testInfra.httpso, | ||
) | ||
r.NoError(err) | ||
|
||
// add skipScaledObjectCreation annotation to HTTPScaledObject | ||
testInfra = newCommonTestInfraWithSkipScaledObjectCreation("testns", "testapp") | ||
|
||
// update required app objects for the application defined by the CRD | ||
err = reconciller.createOrUpdateApplicationResources( | ||
testInfra.ctx, | ||
testInfra.logger, | ||
testInfra.cl, | ||
config.Base{}, | ||
config.ExternalScaler{}, | ||
&testInfra.httpso, | ||
) | ||
r.NoError(err) | ||
|
||
// check for scaledobject, expect error as scaledobject should not exist when skipScaledObjectCreation annotation is set | ||
_, err = getSO( | ||
testInfra.ctx, | ||
testInfra.cl, | ||
testInfra.httpso, | ||
) | ||
r.Error(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.