pkg/generator: add output verification for TestGenRegister
@@ -60,12 +60,46 @@ func TestGenHandler(t *testing.T) {
}
}
+const registerExp = `package v1alpha1
+
+import (
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/apimachinery/pkg/runtime"
+ "k8s.io/apimachinery/pkg/runtime/schema"
+)
+
+const (
+ version = "v1alpha1"
+ groupName = "play.example.com"
+)
+
+var (
+ SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
+ AddToScheme = SchemeBuilder.AddToSchemes
+ // SchemeGroupVersion is the group version used to register these objects.
+ SchemeGroupVersion = schema.GroupVersion{Group: groupName, Version: version}
+)
+
+// addKnownTypes adds the set of types defined in this package to the supplied scheme.
+func addKnownTypes(scheme *runtime.Scheme) error {
+ scheme.AddKnownTypes(SchemeGroupVersion,
+ &PlayService{},
+ &PlayServiceList{},
+ )
+ metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
+ return nil
+}
+`
+
func TestGenRegister(t *testing.T) {
buf := &bytes.Buffer{}
if err := renderAPIRegisterFile(buf, "PlayService", "play.example.com", "v1alpha1"); err != nil {
t.Error(err)
return
}
+ if registerExp != buf.String() {
+ t.Errorf("want %v, got %v", registerExp, buf.String())
+ }
// TODO add verification
}
