github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/testutil/apps/servicedescriptor_factory.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 This file is part of KubeBlocks project 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package apps 21 22 import ( 23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 25 appsv1alpha1 "github.com/1aal/kubeblocks/apis/apps/v1alpha1" 26 "github.com/1aal/kubeblocks/pkg/constant" 27 ) 28 29 type MockServiceDescriptorFactory struct { 30 BaseFactory[appsv1alpha1.ServiceDescriptor, *appsv1alpha1.ServiceDescriptor, MockServiceDescriptorFactory] 31 } 32 33 func NewServiceDescriptorFactory(namespace, name string) *MockServiceDescriptorFactory { 34 f := &MockServiceDescriptorFactory{} 35 f.Init(namespace, name, 36 &appsv1alpha1.ServiceDescriptor{ 37 ObjectMeta: metav1.ObjectMeta{ 38 Name: name, 39 Labels: map[string]string{ 40 constant.AppManagedByLabelKey: constant.AppName, 41 }, 42 }, 43 Spec: appsv1alpha1.ServiceDescriptorSpec{}, 44 }, f) 45 return f 46 } 47 48 func (factory *MockServiceDescriptorFactory) SetServiceKind(serviceKind string) *MockServiceDescriptorFactory { 49 factory.Get().Spec.ServiceKind = serviceKind 50 return factory 51 } 52 53 func (factory *MockServiceDescriptorFactory) SetServiceVersion(serviceVersion string) *MockServiceDescriptorFactory { 54 factory.Get().Spec.ServiceVersion = serviceVersion 55 return factory 56 } 57 58 func (factory *MockServiceDescriptorFactory) SetEndpoint(endpoint appsv1alpha1.CredentialVar) *MockServiceDescriptorFactory { 59 factory.Get().Spec.Endpoint = &endpoint 60 return factory 61 } 62 63 func (factory *MockServiceDescriptorFactory) SetPort(port appsv1alpha1.CredentialVar) *MockServiceDescriptorFactory { 64 factory.Get().Spec.Port = &port 65 return factory 66 } 67 68 func (factory *MockServiceDescriptorFactory) SetAuth(auth appsv1alpha1.ConnectionCredentialAuth) *MockServiceDescriptorFactory { 69 factory.Get().Spec.Auth = &auth 70 return factory 71 }