How to use Selector method of dummy Package

Best Testkube code snippet using dummy.Selector

webhook_test.go

Source:webhook_test.go Github

copy

Full Screen

...43 winOptionsFactory := func(containerName string) *corev1.WindowsSecurityContextOptions {44 return buildWindowsOptions(containerName+"-cred-spec", containerName+"-cred-spec-contents")45 }46 runWebhookValidateOrMutateTests(t, winOptionsFactory, map[string]webhookValidateOrMutateTest{47 "with matching name & content, it passes": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, _ gmsaResourceKind, _ string) {48 webhook := newWebhook(kubeClientFactory())49 setWindowsOptions(optionsSelector(pod), dummyCredSpecName, dummyCredSpecContents)50 response, err := webhook.validateCreateRequest(context.Background(), pod, dummyNamespace)51 assert.Nil(t, err)52 require.NotNil(t, response)53 assert.True(t, response.Allowed)54 },55 "if the cred spec contents are not byte-to-byte equal to that of the one named, but still represent equivalent JSONs, it passes": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, _ gmsaResourceKind, _ string) {56 webhook := newWebhook(kubeClientFactory())57 setWindowsOptions(58 optionsSelector(pod),59 dummyCredSpecName,60 `{"All in all you're just another": {"the":"wall","brick": "in"},"We don't need no":["education", "thought control","dark sarcasm in the classroom"]}`,61 )62 response, err := webhook.validateCreateRequest(context.Background(), pod, dummyNamespace)63 assert.Nil(t, err)64 require.NotNil(t, response)65 assert.True(t, response.Allowed)66 },67 "if the cred spec contents are not that of the one named, it fails": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, resourceKind gmsaResourceKind, resourceName string) {68 webhook := newWebhook(kubeClientFactory())69 setWindowsOptions(70 optionsSelector(pod),71 dummyCredSpecName,72 `{"We don't need no": ["money"], "All in all you're just another": {"brick": "in", "the": "wall"}}`,73 )74 response, err := webhook.validateCreateRequest(context.Background(), pod, dummyNamespace)75 assert.Nil(t, response)76 assertPodAdmissionErrorContains(t, err, pod, http.StatusUnprocessableEntity,77 "the GMSA cred spec contents for %s %q does not match the contents of GMSA resource %q",78 resourceKind, resourceName, dummyCredSpecName)79 },80 "if the cred spec contents are not byte-to-byte equal to that of the one named, and are not even a valid JSON object, it fails": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, resourceKind gmsaResourceKind, resourceName string) {81 webhook := newWebhook(kubeClientFactory())82 setWindowsOptions(optionsSelector(pod), dummyCredSpecName, "i ain't no JSON object")83 response, err := webhook.validateCreateRequest(context.Background(), pod, dummyNamespace)84 assert.Nil(t, response)85 assertPodAdmissionErrorContains(t, err, pod, http.StatusUnprocessableEntity,86 "the GMSA cred spec contents for %s %q does not match the contents of GMSA resource %q",87 resourceKind, resourceName, dummyCredSpecName)88 },89 "if the contents are set, but the name one isn't provided, it fails": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, resourceKind gmsaResourceKind, resourceName string) {90 webhook := newWebhook(kubeClientFactory())91 setWindowsOptions(optionsSelector(pod), "", dummyCredSpecContents)92 response, err := webhook.validateCreateRequest(context.Background(), pod, dummyNamespace)93 assert.Nil(t, response)94 assertPodAdmissionErrorContains(t, err, pod, http.StatusUnprocessableEntity,95 "%s %q has a GMSA cred spec set, but does not define the name of the corresponding resource",96 resourceKind, resourceName)97 },98 "if the service account is not authorized to use the cred-spec, it fails": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, _ gmsaResourceKind, _ string) {99 dummyReason := "dummy reason"100 client := kubeClientFactory()101 client.isAuthorizedToUseCredSpecFunc = func(ctx context.Context, serviceAccountName, namespace, credSpecName string) (authorized bool, reason string) {102 if credSpecName == dummyCredSpecName {103 assert.Equal(t, dummyServiceAccoutName, serviceAccountName)104 assert.Equal(t, dummyNamespace, namespace)105 return false, dummyReason106 }107 return true, ""108 }109 webhook := newWebhook(client)110 setWindowsOptions(optionsSelector(pod), dummyCredSpecName, dummyCredSpecContents)111 response, err := webhook.validateCreateRequest(context.Background(), pod, dummyNamespace)112 assert.Nil(t, response)113 assertPodAdmissionErrorContains(t, err, pod, http.StatusForbidden,114 "service account %q is not authorized to `use` GMSA cred spec %q, reason: %q",115 dummyServiceAccoutName, dummyCredSpecName, dummyReason)116 },117 "if there is an error when retrieving the cred-spec's contents, it fails": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, _ gmsaResourceKind, _ string) {118 dummyError := fmt.Errorf("dummy error")119 client := kubeClientFactory()120 previousRetrieveCredSpecContentsFunc := client.retrieveCredSpecContentsFunc121 client.retrieveCredSpecContentsFunc = func(ctx context.Context, credSpecName string) (contents string, httpCode int, err error) {122 if credSpecName == dummyCredSpecName {123 return "", http.StatusNotFound, dummyError124 }125 return previousRetrieveCredSpecContentsFunc(ctx, credSpecName)126 }127 webhook := newWebhook(client)128 setWindowsOptions(optionsSelector(pod), dummyCredSpecName, dummyCredSpecContents)129 response, err := webhook.validateCreateRequest(context.Background(), pod, dummyNamespace)130 assert.Nil(t, response)131 assertPodAdmissionErrorContains(t, err, pod, http.StatusNotFound, dummyError.Error())132 },133 })134}135func TestMutateCreateRequest(t *testing.T) {136 for testCaseName, winOptionsFactory := range map[string]func() *corev1.WindowsSecurityContextOptions{137 "with empty GMSA settings, it passes and does nothing": func() *corev1.WindowsSecurityContextOptions {138 return &corev1.WindowsSecurityContextOptions{}139 },140 "with no GMSA settings, it passes and does nothing": func() *corev1.WindowsSecurityContextOptions {141 return nil142 },143 } {144 t.Run(testCaseName, func(t *testing.T) {145 webhook := newWebhook(nil)146 pod := buildPod(dummyServiceAccoutName, winOptionsFactory(), map[string]*corev1.WindowsSecurityContextOptions{dummyContainerName: winOptionsFactory()})147 response, err := webhook.mutateCreateRequest(context.Background(), pod)148 assert.Nil(t, err)149 require.NotNil(t, response)150 assert.True(t, response.Allowed)151 })152 }153 kubeClientFactory := func() *dummyKubeClient {154 return &dummyKubeClient{155 retrieveCredSpecContentsFunc: func(ctx context.Context, credSpecName string) (contents string, httpCode int, err error) {156 if credSpecName == dummyCredSpecName {157 contents = dummyCredSpecContents158 } else {159 contents = credSpecName + "-contents"160 }161 return162 },163 }164 }165 winOptionsFactory := func(containerName string) *corev1.WindowsSecurityContextOptions {166 return buildWindowsOptions(containerName+"-cred-spec", "")167 }168 runWebhookValidateOrMutateTests(t, winOptionsFactory, map[string]webhookValidateOrMutateTest{169 "with a GMSA cred spec name, it passes and inlines the cred-spec's contents": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, resourceKind gmsaResourceKind, resourceName string) {170 webhook := newWebhook(kubeClientFactory())171 setWindowsOptions(optionsSelector(pod), dummyCredSpecName, "")172 response, err := webhook.mutateCreateRequest(context.Background(), pod)173 assert.Nil(t, err)174 require.NotNil(t, response)175 assert.True(t, response.Allowed)176 if assert.NotNil(t, response.PatchType) {177 assert.Equal(t, admissionV1.PatchTypeJSONPatch, *response.PatchType)178 }179 patchPath := func(kind gmsaResourceKind, name string) string {180 partialPath := ""181 if kind == containerKind {182 containerIndex := -1183 for i, container := range pod.Spec.Containers {184 if container.Name == name {185 containerIndex = i186 break187 }188 }189 if containerIndex == -1 {190 t.Fatalf("Did not find any container named %q", name)191 }192 partialPath = fmt.Sprintf("/containers/%d", containerIndex)193 }194 return fmt.Sprintf("/spec%s/securityContext/windowsOptions/gmsaCredentialSpec", partialPath)195 }196 // maps the contents to the expected patch for that container197 expectedPatches := make(map[string]map[string]string)198 for i := 0; i < len(pod.Spec.Containers)-1; i++ {199 credSpecContents := extraContainerName(i) + "-cred-spec-contents"200 expectedPatches[credSpecContents] = map[string]string{201 "op": "add",202 "path": patchPath(containerKind, extraContainerName(i)),203 "value": credSpecContents,204 }205 }206 // and the patch for this test's specific cred spec207 expectedPatches[dummyCredSpecContents] = map[string]string{208 "op": "add",209 "path": patchPath(resourceKind, resourceName),210 "value": dummyCredSpecContents,211 }212 var patches []map[string]string213 if err := json.Unmarshal(response.Patch, &patches); assert.Nil(t, err) && assert.Equal(t, len(pod.Spec.Containers), len(patches)) {214 for _, patch := range patches {215 if value, hasValue := patch["value"]; assert.True(t, hasValue) {216 if expectedPatch, present := expectedPatches[value]; assert.True(t, present, "value %s not found in expected patches", value) {217 assert.Equal(t, expectedPatch, patch)218 }219 }220 }221 }222 },223 "it the cred spec's contents are already set, along with its name, it passes and doesn't overwrite the provided contents": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, _ gmsaResourceKind, _ string) {224 webhook := newWebhook(kubeClientFactory())225 setWindowsOptions(optionsSelector(pod), dummyCredSpecName, `{"pre-set GMSA": "cred contents"}`)226 response, err := webhook.mutateCreateRequest(context.Background(), pod)227 assert.Nil(t, err)228 // all the patches we receive should be for the extra containers229 expectedPatchesLen := len(pod.Spec.Containers) - 1230 if expectedPatchesLen == 0 {231 assert.Nil(t, response.PatchType)232 assert.Nil(t, response.Patch)233 } else {234 var patches []map[string]string235 if err := json.Unmarshal(response.Patch, &patches); assert.Nil(t, err) && assert.Equal(t, expectedPatchesLen, len(patches)) {236 for _, patch := range patches {237 if path, hasPath := patch["path"]; assert.True(t, hasPath) {238 assert.NotContains(t, path, dummyCredSpecName)239 }240 }241 }242 }243 },244 "if there is an error when retrieving the cred-spec's contents, it fails": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, _ gmsaResourceKind, _ string) {245 dummyError := fmt.Errorf("dummy error")246 client := kubeClientFactory()247 previousRetrieveCredSpecContentsFunc := client.retrieveCredSpecContentsFunc248 client.retrieveCredSpecContentsFunc = func(ctx context.Context, credSpecName string) (contents string, httpCode int, err error) {249 if credSpecName == dummyCredSpecName {250 return "", http.StatusNotFound, dummyError251 }252 return previousRetrieveCredSpecContentsFunc(ctx, credSpecName)253 }254 webhook := newWebhook(client)255 setWindowsOptions(optionsSelector(pod), dummyCredSpecName, "")256 response, err := webhook.mutateCreateRequest(context.Background(), pod)257 assert.Nil(t, response)258 assertPodAdmissionErrorContains(t, err, pod, http.StatusNotFound, dummyError.Error())259 },260 })261}262func TestValidateUpdateRequest(t *testing.T) {263 for testCaseName, winOptionsFactory := range map[string]func() *corev1.WindowsSecurityContextOptions{264 "with empty GMSA settings, it passes and does nothing": func() *corev1.WindowsSecurityContextOptions {265 return &corev1.WindowsSecurityContextOptions{}266 },267 "with no GMSA settings, it passes and does nothing": func() *corev1.WindowsSecurityContextOptions {268 return nil269 },270 } {271 t.Run(testCaseName, func(t *testing.T) {272 pod := buildPod(dummyServiceAccoutName, winOptionsFactory(), map[string]*corev1.WindowsSecurityContextOptions{dummyContainerName: winOptionsFactory()})273 oldPod := buildPod(dummyServiceAccoutName, winOptionsFactory(), map[string]*corev1.WindowsSecurityContextOptions{dummyContainerName: winOptionsFactory()})274 response, err := validateUpdateRequest(pod, oldPod)275 assert.Nil(t, err)276 require.NotNil(t, response)277 assert.True(t, response.Allowed)278 })279 }280 winOptionsFactory := func(containerName string) *corev1.WindowsSecurityContextOptions {281 return buildWindowsOptions(containerName+"-cred-spec", containerName+"-cred-spec-contents")282 }283 runWebhookValidateOrMutateTests(t, winOptionsFactory, map[string]webhookValidateOrMutateTest{284 "if there was no changes to GMSA settings, it passes": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, _ gmsaResourceKind, _ string) {285 setWindowsOptions(optionsSelector(pod), dummyCredSpecName, dummyCredSpecContents)286 oldPod := pod.DeepCopy()287 response, err := validateUpdateRequest(pod, oldPod)288 assert.Nil(t, err)289 require.NotNil(t, response)290 assert.True(t, response.Allowed)291 },292 "if there was a change to a GMSA name, it fails": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, resourceKind gmsaResourceKind, resourceName string) {293 setWindowsOptions(optionsSelector(pod), "new-cred-spec-name", dummyCredSpecContents)294 oldPod := pod.DeepCopy()295 setWindowsOptions(optionsSelector(oldPod), dummyCredSpecName, "")296 response, err := validateUpdateRequest(pod, oldPod)297 assert.Nil(t, response)298 assertPodAdmissionErrorContains(t, err, pod, http.StatusForbidden,299 "cannot update an existing pod's GMSA settings (GMSA name modified on %s %q)",300 resourceKind, resourceName)301 },302 "if there was a change to a GMSA contents, it fails": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, resourceKind gmsaResourceKind, resourceName string) {303 setWindowsOptions(optionsSelector(pod), dummyCredSpecName, "new-cred-spec-contents")304 oldPod := pod.DeepCopy()305 setWindowsOptions(optionsSelector(oldPod), "", dummyCredSpecContents)306 response, err := validateUpdateRequest(pod, oldPod)307 assert.Nil(t, response)308 assertPodAdmissionErrorContains(t, err, pod, http.StatusForbidden,309 "cannot update an existing pod's GMSA settings (GMSA contents modified on %s %q)",310 resourceKind, resourceName)311 },312 "if there were changes to both GMSA name & contents, it fails": func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, resourceKind gmsaResourceKind, resourceName string) {313 setWindowsOptions(optionsSelector(pod), "new-cred-spec-name", "new-cred-spec-contents")314 oldPod := pod.DeepCopy()315 setWindowsOptions(optionsSelector(oldPod), dummyCredSpecName, dummyCredSpecContents)316 response, err := validateUpdateRequest(pod, oldPod)317 assert.Nil(t, response)318 assertPodAdmissionErrorContains(t, err, pod, http.StatusForbidden,319 "cannot update an existing pod's GMSA settings (GMSA name and contents modified on %s %q)",320 resourceKind, resourceName)321 },322 })323}324func TestEqualStringPointers(t *testing.T) {325 ptrToString := func(s *string) string {326 if s == nil {327 return "nil"328 }329 return " = " + *s330 }331 foo := "foo"332 bar := "bar"333 for _, testCase := range []struct {334 s1 *string335 s2 *string336 expectedResult bool337 }{338 {339 s1: nil,340 s2: nil,341 expectedResult: true,342 },343 {344 s1: &foo,345 s2: nil,346 expectedResult: false,347 },348 {349 s1: &foo,350 s2: &foo,351 expectedResult: true,352 },353 {354 s1: &foo,355 s2: &bar,356 expectedResult: false,357 },358 } {359 for _, ptrs := range [][]*string{360 {testCase.s1, testCase.s2},361 {testCase.s2, testCase.s1},362 } {363 s1 := ptrs[0]364 s2 := ptrs[1]365 testName := fmt.Sprintf("with s1 %s and s2 %s, should return %v",366 ptrToString(s1),367 ptrToString(s2),368 testCase.expectedResult)369 t.Run(testName, func(t *testing.T) {370 assert.Equal(t, testCase.expectedResult, equalStringPointers(s1, s2))371 })372 }373 }374}375/* Helpers below */376type containerWindowsOptionsFactory func(containerName string) *corev1.WindowsSecurityContextOptions377type winOptionsSelector func(pod *corev1.Pod) *corev1.WindowsSecurityContextOptions378// a webhookValidateOrMutateTest function should run a test on one of the webhook's validate or mutate379// functions, given a selector to extract the WindowsSecurityOptions struct it can play with from the pod.380// It should assume that the pod it receives has any number of extra containers with correct381// (in the sense of the test) windows security options generated by a relevant containerWindowsOptionsFactory.382type webhookValidateOrMutateTest func(t *testing.T, pod *corev1.Pod, optionsSelector winOptionsSelector, resourceKind gmsaResourceKind, resourceName string)383// runWebhookValidateOrMutateTests runs the given tests with 0 to 5 extra containers with correct windows384// security options as generated by winOptionsFactory.385func runWebhookValidateOrMutateTests(t *testing.T, winOptionsFactory containerWindowsOptionsFactory, tests map[string]webhookValidateOrMutateTest) {386 for extraContainersCount := 0; extraContainersCount <= 5; extraContainersCount++ {387 containerNamesAndWindowsOptions := make(map[string]*corev1.WindowsSecurityContextOptions)388 for i := 0; i < extraContainersCount; i++ {389 containerName := extraContainerName(i)390 containerNamesAndWindowsOptions[containerName] = winOptionsFactory(containerName)391 }392 testNameSuffix := ""393 if extraContainersCount > 0 {394 testNameSuffix = fmt.Sprintf(" and %d extra containers", extraContainersCount)395 }396 for _, resourceKind := range []gmsaResourceKind{podKind, containerKind} {397 for testName, testFunc := range tests {398 podWindowsOptions := &corev1.WindowsSecurityContextOptions{}399 containerNamesAndWindowsOptions[dummyContainerName] = &corev1.WindowsSecurityContextOptions{}400 pod := buildPod(dummyServiceAccoutName, podWindowsOptions, containerNamesAndWindowsOptions)401 var optionsSelector winOptionsSelector402 var resourceName string403 switch resourceKind {404 case podKind:405 optionsSelector = func(pod *corev1.Pod) *corev1.WindowsSecurityContextOptions {406 if pod != nil && pod.Spec.SecurityContext != nil {407 return pod.Spec.SecurityContext.WindowsOptions408 }409 return nil410 }411 resourceName = dummyPodName412 case containerKind:413 optionsSelector = func(pod *corev1.Pod) *corev1.WindowsSecurityContextOptions {414 if pod != nil {415 for _, container := range pod.Spec.Containers {416 if container.Name == dummyContainerName {417 if container.SecurityContext != nil {418 return container.SecurityContext.WindowsOptions419 }420 return nil421 }422 }423 }424 return nil425 }426 resourceName = dummyContainerName427 default:428 t.Fatalf("Unknown resource kind: %q", resourceKind)429 }430 t.Run(fmt.Sprintf("%s - with %s-level windows options%s", testName, resourceKind, testNameSuffix), func(t *testing.T) {431 testFunc(t, pod, optionsSelector, resourceKind, resourceName)432 })433 }434 }435 }436}437func extraContainerName(i int) string {438 return fmt.Sprintf("extra-container-%d", i)439}440func assertPodAdmissionErrorContains(t *testing.T, err *podAdmissionError, pod *corev1.Pod, httpCode int, msgFormat string, msgArgs ...interface{}) bool {441 if !assert.NotNil(t, err) {442 return false443 }444 result := assert.Equal(t, pod, err.pod)445 result = assert.Equal(t, httpCode, err.code) && result...

Full Screen

Full Screen

validation_test.go

Source:validation_test.go Github

copy

Full Screen

...53 assertAllowedResponseWithWarnings(t, 3, &dynatracev1beta1.DynaKube{54 ObjectMeta: defaultDynakubeObjectMeta,55 Spec: dynatracev1beta1.DynaKubeSpec{56 APIURL: testApiUrl,57 NamespaceSelector: metav1.LabelSelector{58 MatchLabels: dummyLabels,59 },60 OneAgent: dynatracev1beta1.OneAgentSpec{61 CloudNativeFullStack: &dynatracev1beta1.CloudNativeFullStackSpec{62 HostInjectSpec: dynatracev1beta1.HostInjectSpec{63 NodeSelector: map[string]string{64 "node": "1",65 },66 },67 },68 },69 ActiveGate: dynatracev1beta1.ActiveGateSpec{70 Capabilities: []dynatracev1beta1.CapabilityDisplayName{71 dynatracev1beta1.RoutingCapability.DisplayName,72 dynatracev1beta1.KubeMonCapability.DisplayName,73 dynatracev1beta1.MetricsIngestCapability.DisplayName,74 },75 },76 KubernetesMonitoring: dynatracev1beta1.KubernetesMonitoringSpec{77 Enabled: false,78 },79 Routing: dynatracev1beta1.RoutingSpec{80 Enabled: false,81 },82 },83 },84 &dynatracev1beta1.DynaKube{85 ObjectMeta: defaultDynakubeObjectMeta,86 Spec: dynatracev1beta1.DynaKubeSpec{87 APIURL: testApiUrl,88 NamespaceSelector: metav1.LabelSelector{89 MatchLabels: dummyLabels2,90 },91 OneAgent: dynatracev1beta1.OneAgentSpec{92 CloudNativeFullStack: &dynatracev1beta1.CloudNativeFullStackSpec{93 HostInjectSpec: dynatracev1beta1.HostInjectSpec{94 NodeSelector: map[string]string{95 "node": "2",96 },97 },98 },99 },100 },101 }, &dummyNamespace, &dummyNamespace2, &defaultCSIDaemonSet)102 })103 t.Run(`conflicting dynakube specs`, func(t *testing.T) {104 assertDeniedResponse(t,105 []string{106 errorCSIRequired,107 errorNoApiUrl,108 errorConflictingActiveGateSections,109 errorConflictingNamespaceSelector,110 fmt.Sprintf(errorDuplicateActiveGateCapability, dynatracev1beta1.KubeMonCapability.DisplayName),111 fmt.Sprintf(errorInvalidActiveGateCapability, "me dumb"),112 fmt.Sprintf(errorNodeSelectorConflict, "conflict2")},113 &dynatracev1beta1.DynaKube{114 ObjectMeta: metav1.ObjectMeta{115 Name: testName,116 Namespace: testNamespace,117 },118 Spec: dynatracev1beta1.DynaKubeSpec{119 APIURL: "",120 NamespaceSelector: metav1.LabelSelector{121 MatchLabels: dummyLabels,122 },123 OneAgent: dynatracev1beta1.OneAgentSpec{124 CloudNativeFullStack: &dynatracev1beta1.CloudNativeFullStackSpec{},125 },126 ActiveGate: dynatracev1beta1.ActiveGateSpec{127 Capabilities: []dynatracev1beta1.CapabilityDisplayName{128 dynatracev1beta1.KubeMonCapability.DisplayName,129 dynatracev1beta1.KubeMonCapability.DisplayName,130 "me dumb",131 },132 },133 KubernetesMonitoring: dynatracev1beta1.KubernetesMonitoringSpec{134 Enabled: true,135 },136 Routing: dynatracev1beta1.RoutingSpec{137 Enabled: true,138 },139 },140 },141 &dynatracev1beta1.DynaKube{142 ObjectMeta: metav1.ObjectMeta{143 Name: "conflict1",144 Namespace: testNamespace,145 },146 Spec: dynatracev1beta1.DynaKubeSpec{147 APIURL: testApiUrl,148 NamespaceSelector: metav1.LabelSelector{149 MatchLabels: dummyLabels,150 },151 OneAgent: dynatracev1beta1.OneAgentSpec{152 ApplicationMonitoring: &dynatracev1beta1.ApplicationMonitoringSpec{},153 },154 },155 },156 &dynatracev1beta1.DynaKube{157 ObjectMeta: metav1.ObjectMeta{158 Name: "conflict2",159 Namespace: testNamespace,160 },161 Spec: dynatracev1beta1.DynaKubeSpec{162 APIURL: testApiUrl,...

Full Screen

Full Screen

namespace_selector_test.go

Source:namespace_selector_test.go Github

copy

Full Screen

...3 "testing"4 dynatracev1beta1 "github.com/Dynatrace/dynatrace-operator/src/api/v1beta1"5 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"6)7func TestConflictingNamespaceSelector(t *testing.T) {8 t.Run(`valid dynakube specs`, func(t *testing.T) {9 assertAllowedResponseWithoutWarnings(t, &dynatracev1beta1.DynaKube{10 ObjectMeta: defaultDynakubeObjectMeta,11 Spec: dynatracev1beta1.DynaKubeSpec{12 APIURL: testApiUrl,13 NamespaceSelector: metav1.LabelSelector{14 MatchLabels: dummyLabels,15 },16 OneAgent: dynatracev1beta1.OneAgentSpec{17 ApplicationMonitoring: &dynatracev1beta1.ApplicationMonitoringSpec{},18 },19 },20 },21 &dynatracev1beta1.DynaKube{22 ObjectMeta: defaultDynakubeObjectMeta,23 Spec: dynatracev1beta1.DynaKubeSpec{24 APIURL: testApiUrl,25 NamespaceSelector: metav1.LabelSelector{26 MatchLabels: dummyLabels2,27 },28 OneAgent: dynatracev1beta1.OneAgentSpec{29 ApplicationMonitoring: &dynatracev1beta1.ApplicationMonitoringSpec{},30 },31 },32 }, &dummyNamespace, &dummyNamespace2)33 })34 t.Run(`invalid dynakube specs`, func(t *testing.T) {35 assertDeniedResponse(t,36 []string{errorConflictingNamespaceSelectorNoSelector},37 &dynatracev1beta1.DynaKube{38 ObjectMeta: defaultDynakubeObjectMeta,39 Spec: dynatracev1beta1.DynaKubeSpec{40 APIURL: testApiUrl,41 OneAgent: dynatracev1beta1.OneAgentSpec{42 CloudNativeFullStack: &dynatracev1beta1.CloudNativeFullStackSpec{},43 },44 },45 },46 &dynatracev1beta1.DynaKube{47 ObjectMeta: metav1.ObjectMeta{48 Name: "conflicting-dk",49 Namespace: testNamespace,50 },51 Spec: dynatracev1beta1.DynaKubeSpec{52 APIURL: testApiUrl,53 OneAgent: dynatracev1beta1.OneAgentSpec{54 ApplicationMonitoring: &dynatracev1beta1.ApplicationMonitoringSpec{},55 },56 },57 }, &defaultCSIDaemonSet, &dummyNamespace)58 assertDeniedResponse(t,59 []string{errorConflictingNamespaceSelector},60 &dynatracev1beta1.DynaKube{61 ObjectMeta: defaultDynakubeObjectMeta,62 Spec: dynatracev1beta1.DynaKubeSpec{63 NamespaceSelector: metav1.LabelSelector{64 MatchLabels: dummyLabels,65 },66 APIURL: testApiUrl,67 OneAgent: dynatracev1beta1.OneAgentSpec{68 ApplicationMonitoring: &dynatracev1beta1.ApplicationMonitoringSpec{},69 },70 },71 },72 &dynatracev1beta1.DynaKube{73 ObjectMeta: metav1.ObjectMeta{74 Name: "conflicting-dk",75 Namespace: testNamespace,76 },77 Spec: dynatracev1beta1.DynaKubeSpec{78 APIURL: testApiUrl,79 NamespaceSelector: metav1.LabelSelector{80 MatchLabels: dummyLabels,81 },82 OneAgent: dynatracev1beta1.OneAgentSpec{83 ApplicationMonitoring: &dynatracev1beta1.ApplicationMonitoringSpec{},84 },85 },86 }, &defaultCSIDaemonSet, &dummyNamespace)87 })88}...

Full Screen

Full Screen

Selector

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 d := dummy{}4 d.Selector()5}6import (7func main() {8 d := dummy{}9 d.Selector()10}11import (12func main() {13 d := dummy{}14 d.Selector()15}16import (17func main() {18 d := dummy{}19 d.Selector()20}21import (22func main() {23 d := dummy{}24 d.Selector()25}26import (27func main() {28 d := dummy{}29 d.Selector()30}31import (32func main() {33 d := dummy{}34 d.Selector()35}36import (37func main() {38 d := dummy{}39 d.Selector()40}41import (42func main() {43 d := dummy{}44 d.Selector()45}46import (47func main() {48 d := dummy{}49 d.Selector()50}51import (52func main() {53 d := dummy{}54 d.Selector()55}56import (57func main() {58 d := dummy{}59 d.Selector()60}61import (62func main() {63 d := dummy{}64 d.Selector()65}

Full Screen

Full Screen

Selector

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(dummy.Selector(1))4}5import (6func main() {7 fmt.Println(dummy.Selector(2))8}9import (10func main() {11 fmt.Println(dummy.Selector(3))12}13import (14func main() {15 fmt.Println(dummy.Selector(4))16}17import (18func main() {19 fmt.Println(dummy.Selector(5))20}21import (22func main() {23 fmt.Println(dummy.Selector(6))24}25import (26func main() {27 fmt.Println(dummy.Selector(7))28}29import (30func main() {31 fmt.Println(dummy.Selector(8))32}33import (34func main() {35 fmt.Println(dummy.Selector(9))36}37import (38func main() {39 fmt.Println(dummy.Selector(10))40}41import (42func main() {43 fmt.Println(dummy.Selector(11))44}

Full Screen

Full Screen

Selector

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(d.Selector(1))4}5import (6func main() {7 fmt.Println(d.Selector(2))8}9import (10func main() {11 fmt.Println(d.Selector(3))12}13import (14func main() {15 fmt.Println(d.Selector(4))16}17import (18func main() {19 fmt.Println(d.Selector(5))20}21import (22func main() {23 fmt.Println(d.Selector(6))24}25import (26func main() {27 fmt.Println(d.Selector(7))28}29import (30func main() {31 fmt.Println(d.Selector(8))32}33import (34func main() {35 fmt.Println(d.Selector(9))36}37import (38func main() {39 fmt.Println(d.Selector(10))40}41import (42func main() {43 fmt.Println(d.Selector(11))44}45import (46func main() {47 fmt.Println(d.Selector(12))

Full Screen

Full Screen

Selector

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World!")4 dummy.Selector()5}6import (7func main() {8 fmt.Println("Hello World!")9 dummy.Selector()10}11import (12func main() {13 fmt.Println("Hello World!")14 dummy.Selector()15}16import (17func main() {18 fmt.Println("Hello World!")19 dummy.Selector()20}21import (22func main() {23 fmt.Println("Hello World!")24 dummy.Selector()25}26import (27func main() {28 fmt.Println("Hello World!")29 dummy.Selector()30}31import (32func main() {33 fmt.Println("Hello World!")34 dummy.Selector()35}36import (37func main() {38 fmt.Println("Hello World!")39 dummy.Selector()40}41import (42func main() {43 fmt.Println("Hello World!")44 dummy.Selector()45}46import (47func main() {48 fmt.Println("Hello World!")49 dummy.Selector()50}51import (52func main() {53 fmt.Println("Hello World!")54 dummy.Selector()55}

Full Screen

Full Screen

Selector

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 obj.Selector()4 fmt.Println("Hello World!")5}6import (7func main() {8 obj.Selector()9 fmt.Println("Hello World!")10}11import (12func main() {13 obj.Selector()14 fmt.Println("Hello World!")15}16import (17func main() {18 obj.Selector()19 fmt.Println("Hello World!")20}21import (22func main() {23 obj.Selector()24 fmt.Println("Hello World!")25}26import (27func main() {28 obj.Selector()29 fmt.Println("Hello World!")30}31import (32func main() {33 obj.Selector()34 fmt.Println("Hello World!")35}36import (37func main() {38 obj.Selector()39 fmt.Println("Hello World!")40}41import (42func main() {43 obj.Selector()44 fmt.Println("Hello World!")45}46import (47func main() {48 obj.Selector()49 fmt.Println("Hello World!")50}

Full Screen

Full Screen

Selector

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(stringutil.Selector("Hello World"))4}5import (6func main() {7 fmt.Println(stringutil.Selector("Hello World"))8}9import (10func main() {11 fmt.Println(stringutil.Selector("Hello World"))12}13import (14func main() {15 fmt.Println(stringutil.Selector("Hello World"))16}17import (18func main() {19 fmt.Println(stringutil.Selector("Hello World"))20}21import (22func main() {23 fmt.Println(stringutil.Selector("Hello World"))24}25import (26func main() {27 fmt.Println(stringutil.Selector("Hello World"))28}29import (30func main() {31 fmt.Println(stringutil.Selector("Hello World"))32}33import (34func main() {35 fmt.Println(stringutil.Selector("Hello World"))36}37import (

Full Screen

Full Screen

Selector

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 d1.setdata(10, 20)4 fmt.Println(d1.getdata())5}6import (7func main() {8 d1.setdata(10, 20)9 fmt.Println(d1.getdata())10}11import (12func main() {13 d1.setdata(10, 20)14 fmt.Println(d1.getdata())15}16import (17func main() {18 d1.setdata(10, 20)19 fmt.Println(d1.getdata())20}21import (22func main() {23 d1.setdata(10, 20)24 fmt.Println(d1.getdata())25}26import (27func main() {28 d1.setdata(10, 20)29 fmt.Println(d1.getdata())30}31import (32func main() {33 d1.setdata(10, 20)34 fmt.Println(d1.getdata())35}36import (37func main() {38 d1.setdata(10, 20)39 fmt.Println(d1.getdata())40}41import (42func main() {43 d1.setdata(10, 20)44 fmt.Println(d1.getdata())45}46import (47func main() {

Full Screen

Full Screen

Selector

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(d.Selector(2))4}5import (6func main() {7 fmt.Println(d.Selector(3))8}9import (10func main() {11 fmt.Println(d.Selector(4))12}13import (14func main() {15 fmt.Println(d.Selector(5))16}17import (18func main() {19 fmt.Println(d.Selector(6))20}21import (22func main() {23 fmt.Println(d.Selector(7))24}25import (26func main() {27 fmt.Println(d.Selector(8))28}29import (30func main() {31 fmt.Println(d.Selector(9))32}33import (34func main() {35 fmt.Println(d.Selector(10))36}37import (38func main() {39 fmt.Println(d.Select

Full Screen

Full Screen

Selector

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, World!")4 dummy.Selector(2)5}6import (7func main() {8 fmt.Println("Hello, World!")9 dummy.Selector(3)10}11import (12func main() {13 fmt.Println("Hello, World!")14 dummy.Selector(4)15}16import (17func main() {18 fmt.Println("Hello, World!")19 dummy.Selector(5)20}21import (22func main() {23 fmt.Println("Hello, World!")24 dummy.Selector(6)25}26import (27func main() {28 fmt.Println("Hello, World!")29 dummy.Selector(7)30}31import (32func main() {33 fmt.Println("Hello, World!")34 dummy.Selector(8)35}36import (37func main() {38 fmt.Println("Hello, World!")39 dummy.Selector(9)40}41import (42func main()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful