-
Notifications
You must be signed in to change notification settings - Fork 396
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 #3256 from kcp-dev/mjudeikis/apiexport.ep
✨ make APIExportEndpointSlice consumer aware
- Loading branch information
Showing
20 changed files
with
1,479 additions
and
510 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
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,95 @@ | ||
/* | ||
Copyright 2025 The KCP Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package indexers | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/kcp-dev/logicalcluster/v3" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1" | ||
) | ||
|
||
func TestIndexAPIExportEndpointSliceByAPIExport(t *testing.T) { | ||
tests := map[string]struct { | ||
obj interface{} | ||
want []string | ||
wantErr bool | ||
}{ | ||
"not an APIExportEndpointSlice": { | ||
obj: "not an APIExportEndpointSlice", | ||
want: []string{}, | ||
wantErr: true, | ||
}, | ||
"valid APIExportEndpointSlice": { | ||
obj: &apisv1alpha1.APIExportEndpointSlice{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
logicalcluster.AnnotationKey: "root:local", | ||
}, | ||
Name: "foo", | ||
}, | ||
Spec: apisv1alpha1.APIExportEndpointSliceSpec{ | ||
APIExport: apisv1alpha1.ExportBindingReference{ | ||
Path: "root:default", | ||
Name: "foo", | ||
}, | ||
}, | ||
}, | ||
want: []string{ | ||
logicalcluster.NewPath("root:default:foo").String(), | ||
logicalcluster.NewPath("root:local:foo").String(), | ||
}, | ||
wantErr: false, | ||
}, | ||
"valid APIExportEndpointSlice local to export": { | ||
obj: &apisv1alpha1.APIExportEndpointSlice{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
logicalcluster.AnnotationKey: "root:local", | ||
}, | ||
Name: "foo", | ||
}, | ||
Spec: apisv1alpha1.APIExportEndpointSliceSpec{ | ||
APIExport: apisv1alpha1.ExportBindingReference{ | ||
Name: "foo", | ||
}, | ||
}, | ||
}, | ||
want: []string{ | ||
logicalcluster.NewPath("root:local:foo").String(), | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for name, tt := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
got, err := IndexAPIExportEndpointSliceByAPIExport(tt.obj) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("IndexAPIExportEndpointSliceByAPIExport() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("IndexAPIExportEndpointSliceByAPIExport() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.