Skip to content

Commit 1d4fba8

Browse files
authored
Add internal APIs for the testing purpose (#169)
* Add internal APIs for the testing purpose * Fix code coverage metrics
1 parent ca8de51 commit 1d4fba8

33 files changed

+2106
-10
lines changed

.testcoverage.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ threshold:
99

1010
exclude:
1111
paths:
12-
- \.pb\.go$ # excludes all protobuf generated files
13-
- ^pkg/generated # exclude generated code
14-
- ^pkg/apis/ # exclude API definitions
15-
- ^pkg/signals # exclude signal handlers from sample controller
16-
- hack/*.go # exclude hack folder
17-
- main.go # application entry point
12+
- \.pb\.go$ # excludes all protobuf generated files
13+
- ^pkg/generated # exclude generated code
14+
- ^pkg/internal/generated # exclude generated code
15+
- ^pkg/internal/apis_test # exclude test API definitions
16+
- ^pkg/apis/ # exclude API definitions
17+
- ^pkg/signals # exclude signal handlers from sample controller
18+
- hack/*.go # exclude hack folder
19+
- tests/mocks # exclude mocks
20+
- main.go # application entry point

hack/update-codegen.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,26 @@ source "${CODEGEN_PKG}/kube_codegen.sh"
2525

2626
THIS_PKG="github.com/SneaksAndData/arcane-operator"
2727

28+
if [ -z "${API_ROOT:-}" ]; then
29+
API_ROOT="${SCRIPT_ROOT}/pkg/apis"
30+
fi
31+
32+
if [ -z "${GEN_ROOT:-}" ]; then
33+
GEN_ROOT="${SCRIPT_ROOT}/pkg/generated"
34+
fi
35+
36+
if [ -z "${GEN_PKG:-}" ]; then
37+
GEN_PKG="pkg/generated"
38+
fi
39+
2840
kube::codegen::gen_helpers \
2941
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
30-
"${SCRIPT_ROOT}/pkg/apis"
42+
"${API_ROOT}"
3143

3244
kube::codegen::gen_client \
3345
--with-watch \
3446
--with-applyconfig \
35-
--output-dir "${SCRIPT_ROOT}/pkg/generated" \
36-
--output-pkg "${THIS_PKG}/pkg/generated" \
47+
--output-dir "${GEN_ROOT}" \
48+
--output-pkg "${THIS_PKG}/${GEN_PKG}" \
3749
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
38-
"${SCRIPT_ROOT}/pkg/apis"
50+
"${API_ROOT}"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2024. ECCO Data & AI Open-Source Project Maintainers.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package streaming
18+
19+
// GroupName is the group name used in this package
20+
const (
21+
GroupName = "streaming.sneaksanddata.com"
22+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2024. ECCO Data & AI Open-Source Project Maintainers.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// +k8s:deepcopy-gen=package
18+
// +groupName=streaming.sneaksanddata.com
19+
20+
// Package v1 is the v1 version of the API.
21+
package v1
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2024. ECCO Data & AI Open-Source Project Maintainers.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
"github.com/SneaksAndData/arcane-operator/pkg/apis/streaming"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"k8s.io/apimachinery/pkg/runtime"
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
)
25+
26+
// SchemeGroupVersion is group version used to register these objects
27+
var SchemeGroupVersion = schema.GroupVersion{Group: streaming.GroupName, Version: "v1"}
28+
29+
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
30+
func Kind(kind string) schema.GroupKind {
31+
return SchemeGroupVersion.WithKind(kind).GroupKind()
32+
}
33+
34+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
35+
func Resource(resource string) schema.GroupResource {
36+
return SchemeGroupVersion.WithResource(resource).GroupResource()
37+
}
38+
39+
var (
40+
// SchemeBuilder initializes a scheme builder
41+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
42+
// AddToScheme is a global function that registers this API group & version to a scheme
43+
AddToScheme = SchemeBuilder.AddToScheme
44+
)
45+
46+
// Adds the list of known types to Scheme.
47+
func addKnownTypes(scheme *runtime.Scheme) error {
48+
scheme.AddKnownTypes(SchemeGroupVersion,
49+
&MockStreamDefinition{},
50+
&MockStreamDefinitionList{},
51+
)
52+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
53+
return nil
54+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//go: build test
2+
3+
package v1
4+
5+
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
7+
// MockStreamDefinitionSpec is a mock implementation of the StreamDefinitionSpec for testing purposes.
8+
type MockStreamDefinitionSpec struct {
9+
// Source represents the source of the stream.
10+
Source string `json:"source"`
11+
12+
// Destination represents the destination of the stream.
13+
Destination string `json:"destination"`
14+
}
15+
16+
type MockStreamDefinitionStatus struct {
17+
// Phase represents the current phase of the stream.
18+
Phase string `json:"phase"`
19+
}
20+
21+
// MockStreamDefinition is a mock implementation of the StreamDefinition for testing purposes.
22+
// +genclient
23+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
24+
// +kubebuilder:subresource:status
25+
// +kubebuilder:object:root=true
26+
type MockStreamDefinition struct {
27+
metav1.TypeMeta `json:",inline"`
28+
metav1.ObjectMeta `json:"metadata,omitempty"`
29+
30+
Spec MockStreamDefinitionSpec `json:"spec,omitempty"`
31+
Status MockStreamDefinitionStatus `json:"status,omitempty"`
32+
}
33+
34+
// MockStreamDefinitionList contains a list of MockStreamDefinition resources
35+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
36+
type MockStreamDefinitionList struct {
37+
metav1.TypeMeta `json:",inline"`
38+
metav1.ListMeta `json:"metadata,omitempty"`
39+
Items []MockStreamDefinition `json:"items"`
40+
}

pkg/internal/apis_test/streaming/v1/zz_generated.deepcopy.go

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/internal/generated/applyconfiguration/internal/internal.go

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)