-
Notifications
You must be signed in to change notification settings - Fork 3
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 #5 from mercedes-benz/fix_pool_validation_logic
fix: reject pool creation if pool with spec exists
- Loading branch information
Showing
5 changed files
with
163 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/utils/ptr" | ||
) | ||
|
||
func TestPoolList_FilterByFields(t *testing.T) { | ||
type fields struct { | ||
TypeMeta metav1.TypeMeta | ||
ListMeta metav1.ListMeta | ||
Items []Pool | ||
} | ||
type args struct { | ||
predicates []Predicate | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
length int | ||
}{ | ||
{ | ||
name: "pool with spec already exist", | ||
fields: fields{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ListMeta: metav1.ListMeta{}, | ||
Items: []Pool{ | ||
{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "ubuntu-2004-large", | ||
Namespace: "test", | ||
}, | ||
Spec: PoolSpec{ | ||
ImageName: "ubuntu-2004", | ||
Flavor: "large", | ||
ProviderName: "openstack", | ||
GitHubScopeRef: corev1.TypedLocalObjectReference{ | ||
Name: "test", | ||
Kind: "Enterprise", | ||
APIGroup: ptr.To[string]("github.com"), | ||
}, | ||
}, | ||
}, | ||
{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "ubuntu-2204-large", | ||
Namespace: "test", | ||
}, | ||
Spec: PoolSpec{ | ||
ImageName: "ubuntu-2204", | ||
Flavor: "large", | ||
ProviderName: "openstack", | ||
GitHubScopeRef: corev1.TypedLocalObjectReference{ | ||
Name: "test", | ||
Kind: "Enterprise", | ||
APIGroup: ptr.To[string]("github.com"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
args: args{ | ||
predicates: []Predicate{ | ||
MatchesImage("ubuntu-2204"), | ||
MatchesFlavour("large"), | ||
MatchesProvider("openstack"), | ||
MatchesGitHubScope("test", "Enterprise"), | ||
}, | ||
}, | ||
length: 1, | ||
}, | ||
{ | ||
name: "pool with spec does not exist", | ||
fields: fields{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ListMeta: metav1.ListMeta{}, | ||
Items: []Pool{ | ||
{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "ubuntu-2004-large", | ||
Namespace: "test", | ||
}, | ||
Spec: PoolSpec{ | ||
ImageName: "ubuntu-2004", | ||
Flavor: "large", | ||
ProviderName: "openstack", | ||
GitHubScopeRef: corev1.TypedLocalObjectReference{ | ||
Name: "test", | ||
Kind: "Enterprise", | ||
APIGroup: ptr.To[string]("github.com"), | ||
}, | ||
}, | ||
}, | ||
{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "ubuntu-2204-large", | ||
Namespace: "test", | ||
}, | ||
Spec: PoolSpec{ | ||
ImageName: "ubuntu-2204", | ||
Flavor: "large", | ||
ProviderName: "openstack", | ||
GitHubScopeRef: corev1.TypedLocalObjectReference{ | ||
Name: "test", | ||
Kind: "Enterprise", | ||
APIGroup: ptr.To[string]("github.com"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
args: args{ | ||
predicates: []Predicate{ | ||
MatchesImage("ubuntu-2404"), | ||
MatchesFlavour("large"), | ||
MatchesProvider("openstack"), | ||
MatchesGitHubScope("test", "Enterprise"), | ||
}, | ||
}, | ||
length: 0, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
p := &PoolList{ | ||
TypeMeta: tt.fields.TypeMeta, | ||
ListMeta: tt.fields.ListMeta, | ||
Items: tt.fields.Items, | ||
} | ||
|
||
p.FilterByFields(tt.args.predicates...) | ||
|
||
if len(p.Items) != tt.length { | ||
t.Errorf("FilterByFields() = %v, want %v", len(p.Items), tt.length) | ||
} | ||
}) | ||
} | ||
} |
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