Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
luomingmeng committed Mar 7, 2024
1 parent 77b958e commit 21c7fc9
Show file tree
Hide file tree
Showing 4 changed files with 511 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/controller/spd/spd_baseline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ func TestSPDController_updateBaselinePercentile(t *testing.T) {
APIVersion: stsGVK.GroupVersion().String(),
},
BaselinePercent: pointer.Int32(50),
ExtendedIndicator: []apiworkload.ServiceExtendedIndicatorSpec{
{
Name: "TestExtended",
BaselinePercent: pointer.Int32(50),
Indicators: runtime.RawExtension{
Object: &apiworkload.TestExtendedIndicators{},
},
},
},
},
Status: apiworkload.ServiceProfileDescriptorStatus{},
},
Expand All @@ -294,7 +303,8 @@ func TestSPDController_updateBaselinePercentile(t *testing.T) {
Namespace: "default",
Name: "spd1",
Annotations: map[string]string{
consts.SPDAnnotationBaselineSentinelKey: "{\"timeStamp\":\"2023-08-01T00:00:01Z\",\"podName\":\"pod2\"}",
consts.SPDAnnotationBaselineSentinelKey: "{\"timeStamp\":\"2023-08-01T00:00:01Z\",\"podName\":\"pod2\"}",
consts.SPDAnnotationExtendedBaselineSentinelKey: "{\"TestExtended\":{\"timeStamp\":\"2023-08-01T00:00:01Z\",\"podName\":\"pod2\"}}",
},
},
Spec: apiworkload.ServiceProfileDescriptorSpec{
Expand All @@ -304,6 +314,15 @@ func TestSPDController_updateBaselinePercentile(t *testing.T) {
APIVersion: stsGVK.GroupVersion().String(),
},
BaselinePercent: pointer.Int32(50),
ExtendedIndicator: []apiworkload.ServiceExtendedIndicatorSpec{
{
Name: "TestExtended",
BaselinePercent: pointer.Int32(50),
Indicators: runtime.RawExtension{
Object: &apiworkload.TestExtendedIndicators{},
},
},
},
},
Status: apiworkload.ServiceProfileDescriptorStatus{},
},
Expand Down
25 changes: 25 additions & 0 deletions pkg/controller/spd/spd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,16 @@ func TestIndicatorUpdater(t *testing.T) {
APIVersion: stsGVK.GroupVersion().String(),
},
BaselinePercent: pointer.Int32(20),
ExtendedIndicator: []apiworkload.ServiceExtendedIndicatorSpec{
{
Name: "TestExtended",
Indicators: runtime.RawExtension{
Object: &apiworkload.TestExtendedIndicators{
Indicators: &apiworkload.TestIndicators{},
},
},
},
},
BusinessIndicator: []apiworkload.ServiceBusinessIndicatorSpec{
{
Name: "business-1",
Expand Down Expand Up @@ -614,6 +624,9 @@ func TestIndicatorUpdater(t *testing.T) {
}

d1 := indicator_plugin.DummyIndicatorPlugin{
ExtendedSpecNames: []string{
"TestExtended",
},
SystemSpecNames: []apiworkload.ServiceSystemIndicatorName{
"system-1",
},
Expand Down Expand Up @@ -671,6 +684,17 @@ func TestIndicatorUpdater(t *testing.T) {
synced := cache.WaitForCacheSync(ctx.Done(), sc.syncedFunc...)
assert.True(t, synced)

sc.indicatorManager.UpdateExtendedIndicatorSpec(nn, []apiworkload.ServiceExtendedIndicatorSpec{
{
Name: "TestExtended",
Indicators: runtime.RawExtension{
Object: &apiworkload.TestExtendedIndicators{
Indicators: &apiworkload.TestIndicators{},
},
},
},
})

sc.indicatorManager.UpdateBusinessIndicatorSpec(nn, []apiworkload.ServiceBusinessIndicatorSpec{
{
Name: "business-1",
Expand Down Expand Up @@ -753,6 +777,7 @@ func TestIndicatorUpdater(t *testing.T) {
newSPD, err := controlCtx.Client.InternalClient.WorkloadV1alpha1().
ServiceProfileDescriptors("default").Get(ctx, "spd1", metav1.GetOptions{})
assert.NoError(t, err)
assert.Equal(t, expectedSpd.Spec.ExtendedIndicator, newSPD.Spec.ExtendedIndicator)
assert.Equal(t, expectedSpd.Spec.BusinessIndicator, newSPD.Spec.BusinessIndicator)
assert.Equal(t, expectedSpd.Spec.SystemIndicator, newSPD.Spec.SystemIndicator)
assert.Equal(t, expectedSpd.Status.BusinessStatus, newSPD.Status.BusinessStatus)
Expand Down
Loading

0 comments on commit 21c7fc9

Please sign in to comment.