-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #900 from Cloudzp/bugfix
fix issues #898
- Loading branch information
Showing
5 changed files
with
250 additions
and
9 deletions.
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
115 changes: 115 additions & 0 deletions
115
pkg/controller/recommendation/recommendation_rule_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,115 @@ | ||
package recommendation | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
analysisv1alph1 "github.com/gocrane/api/analysis/v1alpha1" | ||
corev1 "k8s.io/api/core/v1" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestRecommendationIndex_GetRecommendation(t *testing.T) { | ||
type fields struct { | ||
recommendationList analysisv1alph1.RecommendationList | ||
} | ||
type args struct { | ||
id ObjectIdentity | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want *analysisv1alph1.Recommendation | ||
}{ | ||
{ | ||
name: "TestRecommendationIndex_GetRecommendation good case", | ||
fields: fields{ | ||
recommendationList: analysisv1alph1.RecommendationList{ | ||
Items: []analysisv1alph1.Recommendation{ | ||
{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: "test-recommendation-rule", | ||
Namespace: "test-namespace", | ||
}, | ||
Spec: analysisv1alph1.RecommendationSpec{ | ||
TargetRef: corev1.ObjectReference{ | ||
Namespace: "test-namespace", | ||
Kind: "Deployment", | ||
Name: "test-deployment-bar", | ||
APIVersion: "app/v1", | ||
}, | ||
Type: analysisv1alph1.AnalysisTypeResource, | ||
}, | ||
}, | ||
{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: "test-recommendation-rule", | ||
Namespace: "test-namespace", | ||
}, | ||
Spec: analysisv1alph1.RecommendationSpec{ | ||
TargetRef: corev1.ObjectReference{ | ||
Namespace: "test-namespace", | ||
Kind: "Deployment", | ||
Name: "test-deployment-foo", | ||
APIVersion: "app/v1", | ||
}, | ||
Type: analysisv1alph1.AnalysisTypeResource, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: &analysisv1alph1.Recommendation{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: "test-recommendation-rule", | ||
Namespace: "test-namespace", | ||
}, | ||
Spec: analysisv1alph1.RecommendationSpec{ | ||
TargetRef: corev1.ObjectReference{ | ||
Namespace: "test-namespace", | ||
Kind: "Deployment", | ||
Name: "test-deployment-bar", | ||
APIVersion: "app/v1", | ||
}, | ||
Type: analysisv1alph1.AnalysisTypeResource, | ||
}, | ||
}, | ||
args: args{ | ||
id: ObjectIdentity{ | ||
Name: "test-deployment-bar", | ||
Namespace: "test-namespace", | ||
APIVersion: "app/v1", | ||
Kind: "Deployment", | ||
Recommender: "Resource", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "TestRecommendationIndex_GetRecommendation empty case", | ||
fields: fields{ | ||
recommendationList: analysisv1alph1.RecommendationList{ | ||
Items: []analysisv1alph1.Recommendation{}, | ||
}, | ||
}, | ||
args: args{ | ||
id: ObjectIdentity{ | ||
Name: "test-deployment-name", | ||
Namespace: "test-namespace", | ||
APIVersion: "app/v1", | ||
Kind: "Deployment", | ||
Recommender: "Resources", | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
idx := NewRecommendationIndex(tt.fields.recommendationList) | ||
if got := idx.GetRecommendation(tt.args.id); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("GetRecommendation() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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