Best Mock code snippet using source.Two
max_attachable_volume_predicate_test.go
Source:max_attachable_volume_predicate_test.go
1/*2Copyright 2018 The Kubernetes Authors.3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12*/13package predicates14import (15 "os"16 "reflect"17 "strconv"18 "strings"19 "testing"20 "k8s.io/api/core/v1"21 "k8s.io/apimachinery/pkg/api/resource"22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"23 utilfeature "k8s.io/apiserver/pkg/util/feature"24 featuregatetesting "k8s.io/component-base/featuregate/testing"25 "k8s.io/kubernetes/pkg/features"26 schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"27 volumeutil "k8s.io/kubernetes/pkg/volume/util"28)29func onePVCPod(filterName string) *v1.Pod {30 return &v1.Pod{31 Spec: v1.PodSpec{32 Volumes: []v1.Volume{33 {34 VolumeSource: v1.VolumeSource{35 PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{36 ClaimName: "some" + filterName + "Vol",37 },38 },39 },40 },41 },42 }43}44func splitPVCPod(filterName string) *v1.Pod {45 return &v1.Pod{46 Spec: v1.PodSpec{47 Volumes: []v1.Volume{48 {49 VolumeSource: v1.VolumeSource{50 PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{51 ClaimName: "someNon" + filterName + "Vol",52 },53 },54 },55 {56 VolumeSource: v1.VolumeSource{57 PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{58 ClaimName: "some" + filterName + "Vol",59 },60 },61 },62 },63 },64 }65}66func TestVolumeCountConflicts(t *testing.T) {67 oneVolPod := &v1.Pod{68 Spec: v1.PodSpec{69 Volumes: []v1.Volume{70 {71 VolumeSource: v1.VolumeSource{72 AWSElasticBlockStore: &v1.AWSElasticBlockStoreVolumeSource{VolumeID: "ovp"},73 },74 },75 },76 },77 }78 twoVolPod := &v1.Pod{79 Spec: v1.PodSpec{80 Volumes: []v1.Volume{81 {82 VolumeSource: v1.VolumeSource{83 AWSElasticBlockStore: &v1.AWSElasticBlockStoreVolumeSource{VolumeID: "tvp1"},84 },85 },86 {87 VolumeSource: v1.VolumeSource{88 AWSElasticBlockStore: &v1.AWSElasticBlockStoreVolumeSource{VolumeID: "tvp2"},89 },90 },91 },92 },93 }94 splitVolsPod := &v1.Pod{95 Spec: v1.PodSpec{96 Volumes: []v1.Volume{97 {98 VolumeSource: v1.VolumeSource{99 HostPath: &v1.HostPathVolumeSource{},100 },101 },102 {103 VolumeSource: v1.VolumeSource{104 AWSElasticBlockStore: &v1.AWSElasticBlockStoreVolumeSource{VolumeID: "svp"},105 },106 },107 },108 },109 }110 nonApplicablePod := &v1.Pod{111 Spec: v1.PodSpec{112 Volumes: []v1.Volume{113 {114 VolumeSource: v1.VolumeSource{115 HostPath: &v1.HostPathVolumeSource{},116 },117 },118 },119 },120 }121 deletedPVCPod := &v1.Pod{122 Spec: v1.PodSpec{123 Volumes: []v1.Volume{124 {125 VolumeSource: v1.VolumeSource{126 PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{127 ClaimName: "deletedPVC",128 },129 },130 },131 },132 },133 }134 twoDeletedPVCPod := &v1.Pod{135 Spec: v1.PodSpec{136 Volumes: []v1.Volume{137 {138 VolumeSource: v1.VolumeSource{139 PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{140 ClaimName: "deletedPVC",141 },142 },143 },144 {145 VolumeSource: v1.VolumeSource{146 PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{147 ClaimName: "anotherDeletedPVC",148 },149 },150 },151 },152 },153 }154 deletedPVPod := &v1.Pod{155 Spec: v1.PodSpec{156 Volumes: []v1.Volume{157 {158 VolumeSource: v1.VolumeSource{159 PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{160 ClaimName: "pvcWithDeletedPV",161 },162 },163 },164 },165 },166 }167 // deletedPVPod2 is a different pod than deletedPVPod but using the same PVC168 deletedPVPod2 := &v1.Pod{169 Spec: v1.PodSpec{170 Volumes: []v1.Volume{171 {172 VolumeSource: v1.VolumeSource{173 PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{174 ClaimName: "pvcWithDeletedPV",175 },176 },177 },178 },179 },180 }181 // anotherDeletedPVPod is a different pod than deletedPVPod and uses another PVC182 anotherDeletedPVPod := &v1.Pod{183 Spec: v1.PodSpec{184 Volumes: []v1.Volume{185 {186 VolumeSource: v1.VolumeSource{187 PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{188 ClaimName: "anotherPVCWithDeletedPV",189 },190 },191 },192 },193 },194 }195 emptyPod := &v1.Pod{196 Spec: v1.PodSpec{},197 }198 unboundPVCPod := &v1.Pod{199 Spec: v1.PodSpec{200 Volumes: []v1.Volume{201 {202 VolumeSource: v1.VolumeSource{203 PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{204 ClaimName: "unboundPVC",205 },206 },207 },208 },209 },210 }211 // Different pod than unboundPVCPod, but using the same unbound PVC212 unboundPVCPod2 := &v1.Pod{213 Spec: v1.PodSpec{214 Volumes: []v1.Volume{215 {216 VolumeSource: v1.VolumeSource{217 PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{218 ClaimName: "unboundPVC",219 },220 },221 },222 },223 },224 }225 // pod with unbound PVC that's different to unboundPVC226 anotherUnboundPVCPod := &v1.Pod{227 Spec: v1.PodSpec{228 Volumes: []v1.Volume{229 {230 VolumeSource: v1.VolumeSource{231 PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{232 ClaimName: "anotherUnboundPVC",233 },234 },235 },236 },237 },238 }239 twoVolCinderPod := &v1.Pod{240 Spec: v1.PodSpec{241 Volumes: []v1.Volume{242 {243 VolumeSource: v1.VolumeSource{244 Cinder: &v1.CinderVolumeSource{VolumeID: "tvp1"},245 },246 },247 {248 VolumeSource: v1.VolumeSource{249 Cinder: &v1.CinderVolumeSource{VolumeID: "tvp2"},250 },251 },252 },253 },254 }255 oneVolCinderPod := &v1.Pod{256 Spec: v1.PodSpec{257 Volumes: []v1.Volume{258 {259 VolumeSource: v1.VolumeSource{260 Cinder: &v1.CinderVolumeSource{VolumeID: "ovp"},261 },262 },263 },264 },265 }266 tests := []struct {267 newPod *v1.Pod268 existingPods []*v1.Pod269 filterName string270 maxVols int271 fits bool272 test string273 }{274 // filterName:EBSVolumeFilterType275 {276 newPod: oneVolPod,277 existingPods: []*v1.Pod{twoVolPod, oneVolPod},278 filterName: EBSVolumeFilterType,279 maxVols: 4,280 fits: true,281 test: "fits when node capacity >= new pod's EBS volumes",282 },283 {284 newPod: twoVolPod,285 existingPods: []*v1.Pod{oneVolPod},286 filterName: EBSVolumeFilterType,287 maxVols: 2,288 fits: false,289 test: "doesn't fit when node capacity < new pod's EBS volumes",290 },291 {292 newPod: splitVolsPod,293 existingPods: []*v1.Pod{twoVolPod},294 filterName: EBSVolumeFilterType,295 maxVols: 3,296 fits: true,297 test: "new pod's count ignores non-EBS volumes",298 },299 {300 newPod: twoVolPod,301 existingPods: []*v1.Pod{splitVolsPod, nonApplicablePod, emptyPod},302 filterName: EBSVolumeFilterType,303 maxVols: 3,304 fits: true,305 test: "existing pods' counts ignore non-EBS volumes",306 },307 {308 newPod: onePVCPod(EBSVolumeFilterType),309 existingPods: []*v1.Pod{splitVolsPod, nonApplicablePod, emptyPod},310 filterName: EBSVolumeFilterType,311 maxVols: 3,312 fits: true,313 test: "new pod's count considers PVCs backed by EBS volumes",314 },315 {316 newPod: splitPVCPod(EBSVolumeFilterType),317 existingPods: []*v1.Pod{splitVolsPod, oneVolPod},318 filterName: EBSVolumeFilterType,319 maxVols: 3,320 fits: true,321 test: "new pod's count ignores PVCs not backed by EBS volumes",322 },323 {324 newPod: twoVolPod,325 existingPods: []*v1.Pod{oneVolPod, onePVCPod(EBSVolumeFilterType)},326 filterName: EBSVolumeFilterType,327 maxVols: 3,328 fits: false,329 test: "existing pods' counts considers PVCs backed by EBS volumes",330 },331 {332 newPod: twoVolPod,333 existingPods: []*v1.Pod{oneVolPod, twoVolPod, onePVCPod(EBSVolumeFilterType)},334 filterName: EBSVolumeFilterType,335 maxVols: 4,336 fits: true,337 test: "already-mounted EBS volumes are always ok to allow",338 },339 {340 newPod: splitVolsPod,341 existingPods: []*v1.Pod{oneVolPod, oneVolPod, onePVCPod(EBSVolumeFilterType)},342 filterName: EBSVolumeFilterType,343 maxVols: 3,344 fits: true,345 test: "the same EBS volumes are not counted multiple times",346 },347 {348 newPod: onePVCPod(EBSVolumeFilterType),349 existingPods: []*v1.Pod{oneVolPod, deletedPVCPod},350 filterName: EBSVolumeFilterType,351 maxVols: 2,352 fits: false,353 test: "pod with missing PVC is counted towards the PV limit",354 },355 {356 newPod: onePVCPod(EBSVolumeFilterType),357 existingPods: []*v1.Pod{oneVolPod, deletedPVCPod},358 filterName: EBSVolumeFilterType,359 maxVols: 3,360 fits: true,361 test: "pod with missing PVC is counted towards the PV limit",362 },363 {364 newPod: onePVCPod(EBSVolumeFilterType),365 existingPods: []*v1.Pod{oneVolPod, twoDeletedPVCPod},366 filterName: EBSVolumeFilterType,367 maxVols: 3,368 fits: false,369 test: "pod with missing two PVCs is counted towards the PV limit twice",370 },371 {372 newPod: onePVCPod(EBSVolumeFilterType),373 existingPods: []*v1.Pod{oneVolPod, deletedPVPod},374 filterName: EBSVolumeFilterType,375 maxVols: 2,376 fits: false,377 test: "pod with missing PV is counted towards the PV limit",378 },379 {380 newPod: onePVCPod(EBSVolumeFilterType),381 existingPods: []*v1.Pod{oneVolPod, deletedPVPod},382 filterName: EBSVolumeFilterType,383 maxVols: 3,384 fits: true,385 test: "pod with missing PV is counted towards the PV limit",386 },387 {388 newPod: deletedPVPod2,389 existingPods: []*v1.Pod{oneVolPod, deletedPVPod},390 filterName: EBSVolumeFilterType,391 maxVols: 2,392 fits: true,393 test: "two pods missing the same PV are counted towards the PV limit only once",394 },395 {396 newPod: anotherDeletedPVPod,397 existingPods: []*v1.Pod{oneVolPod, deletedPVPod},398 filterName: EBSVolumeFilterType,399 maxVols: 2,400 fits: false,401 test: "two pods missing different PVs are counted towards the PV limit twice",402 },403 {404 newPod: onePVCPod(EBSVolumeFilterType),405 existingPods: []*v1.Pod{oneVolPod, unboundPVCPod},406 filterName: EBSVolumeFilterType,407 maxVols: 2,408 fits: false,409 test: "pod with unbound PVC is counted towards the PV limit",410 },411 {412 newPod: onePVCPod(EBSVolumeFilterType),413 existingPods: []*v1.Pod{oneVolPod, unboundPVCPod},414 filterName: EBSVolumeFilterType,415 maxVols: 3,416 fits: true,417 test: "pod with unbound PVC is counted towards the PV limit",418 },419 {420 newPod: unboundPVCPod2,421 existingPods: []*v1.Pod{oneVolPod, unboundPVCPod},422 filterName: EBSVolumeFilterType,423 maxVols: 2,424 fits: true,425 test: "the same unbound PVC in multiple pods is counted towards the PV limit only once",426 },427 {428 newPod: anotherUnboundPVCPod,429 existingPods: []*v1.Pod{oneVolPod, unboundPVCPod},430 filterName: EBSVolumeFilterType,431 maxVols: 2,432 fits: false,433 test: "two different unbound PVCs are counted towards the PV limit as two volumes",434 },435 // filterName:GCEPDVolumeFilterType436 {437 newPod: oneVolPod,438 existingPods: []*v1.Pod{twoVolPod, oneVolPod},439 filterName: GCEPDVolumeFilterType,440 maxVols: 4,441 fits: true,442 test: "fits when node capacity >= new pod's GCE volumes",443 },444 {445 newPod: twoVolPod,446 existingPods: []*v1.Pod{oneVolPod},447 filterName: GCEPDVolumeFilterType,448 maxVols: 2,449 fits: true,450 test: "fit when node capacity < new pod's GCE volumes",451 },452 {453 newPod: splitVolsPod,454 existingPods: []*v1.Pod{twoVolPod},455 filterName: GCEPDVolumeFilterType,456 maxVols: 3,457 fits: true,458 test: "new pod's count ignores non-GCE volumes",459 },460 {461 newPod: twoVolPod,462 existingPods: []*v1.Pod{splitVolsPod, nonApplicablePod, emptyPod},463 filterName: GCEPDVolumeFilterType,464 maxVols: 3,465 fits: true,466 test: "existing pods' counts ignore non-GCE volumes",467 },468 {469 newPod: onePVCPod(GCEPDVolumeFilterType),470 existingPods: []*v1.Pod{splitVolsPod, nonApplicablePod, emptyPod},471 filterName: GCEPDVolumeFilterType,472 maxVols: 3,473 fits: true,474 test: "new pod's count considers PVCs backed by GCE volumes",475 },476 {477 newPod: splitPVCPod(GCEPDVolumeFilterType),478 existingPods: []*v1.Pod{splitVolsPod, oneVolPod},479 filterName: GCEPDVolumeFilterType,480 maxVols: 3,481 fits: true,482 test: "new pod's count ignores PVCs not backed by GCE volumes",483 },484 {485 newPod: twoVolPod,486 existingPods: []*v1.Pod{oneVolPod, onePVCPod(GCEPDVolumeFilterType)},487 filterName: GCEPDVolumeFilterType,488 maxVols: 3,489 fits: true,490 test: "existing pods' counts considers PVCs backed by GCE volumes",491 },492 {493 newPod: twoVolPod,494 existingPods: []*v1.Pod{oneVolPod, twoVolPod, onePVCPod(GCEPDVolumeFilterType)},495 filterName: GCEPDVolumeFilterType,496 maxVols: 4,497 fits: true,498 test: "already-mounted EBS volumes are always ok to allow",499 },500 {501 newPod: splitVolsPod,502 existingPods: []*v1.Pod{oneVolPod, oneVolPod, onePVCPod(GCEPDVolumeFilterType)},503 filterName: GCEPDVolumeFilterType,504 maxVols: 3,505 fits: true,506 test: "the same GCE volumes are not counted multiple times",507 },508 {509 newPod: onePVCPod(GCEPDVolumeFilterType),510 existingPods: []*v1.Pod{oneVolPod, deletedPVCPod},511 filterName: GCEPDVolumeFilterType,512 maxVols: 2,513 fits: true,514 test: "pod with missing PVC is counted towards the PV limit",515 },516 {517 newPod: onePVCPod(GCEPDVolumeFilterType),518 existingPods: []*v1.Pod{oneVolPod, deletedPVCPod},519 filterName: GCEPDVolumeFilterType,520 maxVols: 3,521 fits: true,522 test: "pod with missing PVC is counted towards the PV limit",523 },524 {525 newPod: onePVCPod(GCEPDVolumeFilterType),526 existingPods: []*v1.Pod{oneVolPod, twoDeletedPVCPod},527 filterName: GCEPDVolumeFilterType,528 maxVols: 3,529 fits: true,530 test: "pod with missing two PVCs is counted towards the PV limit twice",531 },532 {533 newPod: onePVCPod(GCEPDVolumeFilterType),534 existingPods: []*v1.Pod{oneVolPod, deletedPVPod},535 filterName: GCEPDVolumeFilterType,536 maxVols: 2,537 fits: true,538 test: "pod with missing PV is counted towards the PV limit",539 },540 {541 newPod: onePVCPod(GCEPDVolumeFilterType),542 existingPods: []*v1.Pod{oneVolPod, deletedPVPod},543 filterName: GCEPDVolumeFilterType,544 maxVols: 3,545 fits: true,546 test: "pod with missing PV is counted towards the PV limit",547 },548 {549 newPod: deletedPVPod2,550 existingPods: []*v1.Pod{oneVolPod, deletedPVPod},551 filterName: GCEPDVolumeFilterType,552 maxVols: 2,553 fits: true,554 test: "two pods missing the same PV are counted towards the PV limit only once",555 },556 {557 newPod: anotherDeletedPVPod,558 existingPods: []*v1.Pod{oneVolPod, deletedPVPod},559 filterName: GCEPDVolumeFilterType,560 maxVols: 2,561 fits: true,562 test: "two pods missing different PVs are counted towards the PV limit twice",563 },564 {565 newPod: onePVCPod(GCEPDVolumeFilterType),566 existingPods: []*v1.Pod{oneVolPod, unboundPVCPod},567 filterName: GCEPDVolumeFilterType,568 maxVols: 2,569 fits: true,570 test: "pod with unbound PVC is counted towards the PV limit",571 },572 {573 newPod: onePVCPod(GCEPDVolumeFilterType),574 existingPods: []*v1.Pod{oneVolPod, unboundPVCPod},575 filterName: GCEPDVolumeFilterType,576 maxVols: 3,577 fits: true,578 test: "pod with unbound PVC is counted towards the PV limit",579 },580 {581 newPod: unboundPVCPod2,582 existingPods: []*v1.Pod{oneVolPod, unboundPVCPod},583 filterName: GCEPDVolumeFilterType,584 maxVols: 2,585 fits: true,586 test: "the same unbound PVC in multiple pods is counted towards the PV limit only once",587 },588 {589 newPod: anotherUnboundPVCPod,590 existingPods: []*v1.Pod{oneVolPod, unboundPVCPod},591 filterName: GCEPDVolumeFilterType,592 maxVols: 2,593 fits: true,594 test: "two different unbound PVCs are counted towards the PV limit as two volumes",595 },596 // filterName:AzureDiskVolumeFilterType597 {598 newPod: oneVolPod,599 existingPods: []*v1.Pod{twoVolPod, oneVolPod},600 filterName: AzureDiskVolumeFilterType,601 maxVols: 4,602 fits: true,603 test: "fits when node capacity >= new pod's AzureDisk volumes",604 },605 {606 newPod: twoVolPod,607 existingPods: []*v1.Pod{oneVolPod},608 filterName: AzureDiskVolumeFilterType,609 maxVols: 2,610 fits: true,611 test: "fit when node capacity < new pod's AzureDisk volumes",612 },613 {614 newPod: splitVolsPod,615 existingPods: []*v1.Pod{twoVolPod},616 filterName: AzureDiskVolumeFilterType,617 maxVols: 3,618 fits: true,619 test: "new pod's count ignores non-AzureDisk volumes",620 },621 {622 newPod: twoVolPod,623 existingPods: []*v1.Pod{splitVolsPod, nonApplicablePod, emptyPod},624 filterName: AzureDiskVolumeFilterType,625 maxVols: 3,626 fits: true,627 test: "existing pods' counts ignore non-AzureDisk volumes",628 },629 {630 newPod: onePVCPod(AzureDiskVolumeFilterType),631 existingPods: []*v1.Pod{splitVolsPod, nonApplicablePod, emptyPod},632 filterName: AzureDiskVolumeFilterType,633 maxVols: 3,634 fits: true,635 test: "new pod's count considers PVCs backed by AzureDisk volumes",636 },637 {638 newPod: splitPVCPod(AzureDiskVolumeFilterType),639 existingPods: []*v1.Pod{splitVolsPod, oneVolPod},640 filterName: AzureDiskVolumeFilterType,641 maxVols: 3,642 fits: true,643 test: "new pod's count ignores PVCs not backed by AzureDisk volumes",644 },645 {646 newPod: twoVolPod,647 existingPods: []*v1.Pod{oneVolPod, onePVCPod(AzureDiskVolumeFilterType)},648 filterName: AzureDiskVolumeFilterType,649 maxVols: 3,650 fits: true,651 test: "existing pods' counts considers PVCs backed by AzureDisk volumes",652 },653 {654 newPod: twoVolPod,655 existingPods: []*v1.Pod{oneVolPod, twoVolPod, onePVCPod(AzureDiskVolumeFilterType)},656 filterName: AzureDiskVolumeFilterType,657 maxVols: 4,658 fits: true,659 test: "already-mounted AzureDisk volumes are always ok to allow",660 },661 {662 newPod: splitVolsPod,663 existingPods: []*v1.Pod{oneVolPod, oneVolPod, onePVCPod(AzureDiskVolumeFilterType)},664 filterName: AzureDiskVolumeFilterType,665 maxVols: 3,666 fits: true,667 test: "the same AzureDisk volumes are not counted multiple times",668 },669 {670 newPod: onePVCPod(AzureDiskVolumeFilterType),671 existingPods: []*v1.Pod{oneVolPod, deletedPVCPod},672 filterName: AzureDiskVolumeFilterType,673 maxVols: 2,674 fits: true,675 test: "pod with missing PVC is counted towards the PV limit",676 },677 {678 newPod: onePVCPod(AzureDiskVolumeFilterType),679 existingPods: []*v1.Pod{oneVolPod, deletedPVCPod},680 filterName: AzureDiskVolumeFilterType,681 maxVols: 3,682 fits: true,683 test: "pod with missing PVC is counted towards the PV limit",684 },685 {686 newPod: onePVCPod(AzureDiskVolumeFilterType),687 existingPods: []*v1.Pod{oneVolPod, twoDeletedPVCPod},688 filterName: AzureDiskVolumeFilterType,689 maxVols: 3,690 fits: true,691 test: "pod with missing two PVCs is counted towards the PV limit twice",692 },693 {694 newPod: onePVCPod(AzureDiskVolumeFilterType),695 existingPods: []*v1.Pod{oneVolPod, deletedPVPod},696 filterName: AzureDiskVolumeFilterType,697 maxVols: 2,698 fits: true,699 test: "pod with missing PV is counted towards the PV limit",700 },701 {702 newPod: onePVCPod(AzureDiskVolumeFilterType),703 existingPods: []*v1.Pod{oneVolPod, deletedPVPod},704 filterName: AzureDiskVolumeFilterType,705 maxVols: 3,706 fits: true,707 test: "pod with missing PV is counted towards the PV limit",708 },709 {710 newPod: deletedPVPod2,711 existingPods: []*v1.Pod{oneVolPod, deletedPVPod},712 filterName: AzureDiskVolumeFilterType,713 maxVols: 2,714 fits: true,715 test: "two pods missing the same PV are counted towards the PV limit only once",716 },717 {718 newPod: anotherDeletedPVPod,719 existingPods: []*v1.Pod{oneVolPod, deletedPVPod},720 filterName: AzureDiskVolumeFilterType,721 maxVols: 2,722 fits: true,723 test: "two pods missing different PVs are counted towards the PV limit twice",724 },725 {726 newPod: onePVCPod(AzureDiskVolumeFilterType),727 existingPods: []*v1.Pod{oneVolPod, unboundPVCPod},728 filterName: AzureDiskVolumeFilterType,729 maxVols: 2,730 fits: true,731 test: "pod with unbound PVC is counted towards the PV limit",732 },733 {734 newPod: onePVCPod(AzureDiskVolumeFilterType),735 existingPods: []*v1.Pod{oneVolPod, unboundPVCPod},736 filterName: AzureDiskVolumeFilterType,737 maxVols: 3,738 fits: true,739 test: "pod with unbound PVC is counted towards the PV limit",740 },741 {742 newPod: unboundPVCPod2,743 existingPods: []*v1.Pod{oneVolPod, unboundPVCPod},744 filterName: AzureDiskVolumeFilterType,745 maxVols: 2,746 fits: true,747 test: "the same unbound PVC in multiple pods is counted towards the PV limit only once",748 },749 {750 newPod: anotherUnboundPVCPod,751 existingPods: []*v1.Pod{oneVolPod, unboundPVCPod},752 filterName: AzureDiskVolumeFilterType,753 maxVols: 2,754 fits: true,755 test: "two different unbound PVCs are counted towards the PV limit as two volumes",756 },757 // filterName:CinderVolumeFilterType758 {759 newPod: oneVolCinderPod,760 existingPods: []*v1.Pod{twoVolCinderPod},761 filterName: CinderVolumeFilterType,762 maxVols: 4,763 fits: true,764 test: "fits when node capacity >= new pod's Cinder volumes",765 },766 {767 newPod: oneVolCinderPod,768 existingPods: []*v1.Pod{twoVolCinderPod},769 filterName: CinderVolumeFilterType,770 maxVols: 2,771 fits: false,772 test: "not fit when node capacity < new pod's Cinder volumes",773 },774 }775 expectedFailureReasons := []PredicateFailureReason{ErrMaxVolumeCountExceeded}776 // running attachable predicate tests without feature gate and no limit present on nodes777 for _, test := range tests {778 os.Setenv(KubeMaxPDVols, strconv.Itoa(test.maxVols))779 pred := NewMaxPDVolumeCountPredicate(test.filterName, getFakePVInfo(test.filterName), getFakePVCInfo(test.filterName))780 fits, reasons, err := pred(test.newPod, GetPredicateMetadata(test.newPod, nil), schedulernodeinfo.NewNodeInfo(test.existingPods...))781 if err != nil {782 t.Errorf("[%s]%s: unexpected error: %v", test.filterName, test.test, err)783 }784 if !fits && !reflect.DeepEqual(reasons, expectedFailureReasons) {785 t.Errorf("[%s]%s: unexpected failure reasons: %v, want: %v", test.filterName, test.test, reasons, expectedFailureReasons)786 }787 if fits != test.fits {788 t.Errorf("[%s]%s: expected %v, got %v", test.filterName, test.test, test.fits, fits)789 }790 }791 defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.AttachVolumeLimit, true)()792 // running attachable predicate tests with feature gate and limit present on nodes793 for _, test := range tests {794 node := getNodeWithPodAndVolumeLimits(test.existingPods, int64(test.maxVols), test.filterName)795 pred := NewMaxPDVolumeCountPredicate(test.filterName, getFakePVInfo(test.filterName), getFakePVCInfo(test.filterName))796 fits, reasons, err := pred(test.newPod, GetPredicateMetadata(test.newPod, nil), node)797 if err != nil {798 t.Errorf("Using allocatable [%s]%s: unexpected error: %v", test.filterName, test.test, err)799 }800 if !fits && !reflect.DeepEqual(reasons, expectedFailureReasons) {801 t.Errorf("Using allocatable [%s]%s: unexpected failure reasons: %v, want: %v", test.filterName, test.test, reasons, expectedFailureReasons)802 }803 if fits != test.fits {804 t.Errorf("Using allocatable [%s]%s: expected %v, got %v", test.filterName, test.test, test.fits, fits)805 }806 }807}808func getFakePVInfo(filterName string) FakePersistentVolumeInfo {809 return FakePersistentVolumeInfo{810 {811 ObjectMeta: metav1.ObjectMeta{Name: "some" + filterName + "Vol"},812 Spec: v1.PersistentVolumeSpec{813 PersistentVolumeSource: v1.PersistentVolumeSource{814 AWSElasticBlockStore: &v1.AWSElasticBlockStoreVolumeSource{VolumeID: strings.ToLower(filterName) + "Vol"},815 },816 },817 },818 {819 ObjectMeta: metav1.ObjectMeta{Name: "someNon" + filterName + "Vol"},820 Spec: v1.PersistentVolumeSpec{821 PersistentVolumeSource: v1.PersistentVolumeSource{},822 },823 },824 }825}826func getFakePVCInfo(filterName string) FakePersistentVolumeClaimInfo {827 return FakePersistentVolumeClaimInfo{828 {829 ObjectMeta: metav1.ObjectMeta{Name: "some" + filterName + "Vol"},830 Spec: v1.PersistentVolumeClaimSpec{VolumeName: "some" + filterName + "Vol"},831 },832 {833 ObjectMeta: metav1.ObjectMeta{Name: "someNon" + filterName + "Vol"},834 Spec: v1.PersistentVolumeClaimSpec{VolumeName: "someNon" + filterName + "Vol"},835 },836 {837 ObjectMeta: metav1.ObjectMeta{Name: "pvcWithDeletedPV"},838 Spec: v1.PersistentVolumeClaimSpec{VolumeName: "pvcWithDeletedPV"},839 },840 {841 ObjectMeta: metav1.ObjectMeta{Name: "anotherPVCWithDeletedPV"},842 Spec: v1.PersistentVolumeClaimSpec{VolumeName: "anotherPVCWithDeletedPV"},843 },844 {845 ObjectMeta: metav1.ObjectMeta{Name: "unboundPVC"},846 Spec: v1.PersistentVolumeClaimSpec{VolumeName: ""},847 },848 {849 ObjectMeta: metav1.ObjectMeta{Name: "anotherUnboundPVC"},850 Spec: v1.PersistentVolumeClaimSpec{VolumeName: ""},851 },852 }853}854func TestMaxVolumeFuncM5(t *testing.T) {855 node := &v1.Node{856 ObjectMeta: metav1.ObjectMeta{857 Name: "node-for-m5-instance",858 Labels: map[string]string{859 v1.LabelInstanceType: "m5.large",860 },861 },862 }863 os.Unsetenv(KubeMaxPDVols)864 maxVolumeFunc := getMaxVolumeFunc(EBSVolumeFilterType)865 maxVolume := maxVolumeFunc(node)866 if maxVolume != volumeutil.DefaultMaxEBSNitroVolumeLimit {867 t.Errorf("Expected max volume to be %d got %d", volumeutil.DefaultMaxEBSNitroVolumeLimit, maxVolume)868 }869}870func TestMaxVolumeFuncT3(t *testing.T) {871 node := &v1.Node{872 ObjectMeta: metav1.ObjectMeta{873 Name: "node-for-t3-instance",874 Labels: map[string]string{875 v1.LabelInstanceType: "t3.medium",876 },877 },878 }879 os.Unsetenv(KubeMaxPDVols)880 maxVolumeFunc := getMaxVolumeFunc(EBSVolumeFilterType)881 maxVolume := maxVolumeFunc(node)882 if maxVolume != volumeutil.DefaultMaxEBSNitroVolumeLimit {883 t.Errorf("Expected max volume to be %d got %d", volumeutil.DefaultMaxEBSNitroVolumeLimit, maxVolume)884 }885}886func TestMaxVolumeFuncR5(t *testing.T) {887 node := &v1.Node{888 ObjectMeta: metav1.ObjectMeta{889 Name: "node-for-r5-instance",890 Labels: map[string]string{891 v1.LabelInstanceType: "r5d.xlarge",892 },893 },894 }895 os.Unsetenv(KubeMaxPDVols)896 maxVolumeFunc := getMaxVolumeFunc(EBSVolumeFilterType)897 maxVolume := maxVolumeFunc(node)898 if maxVolume != volumeutil.DefaultMaxEBSNitroVolumeLimit {899 t.Errorf("Expected max volume to be %d got %d", volumeutil.DefaultMaxEBSNitroVolumeLimit, maxVolume)900 }901}902func TestMaxVolumeFuncM4(t *testing.T) {903 node := &v1.Node{904 ObjectMeta: metav1.ObjectMeta{905 Name: "node-for-m4-instance",906 Labels: map[string]string{907 v1.LabelInstanceType: "m4.2xlarge",908 },909 },910 }911 os.Unsetenv(KubeMaxPDVols)912 maxVolumeFunc := getMaxVolumeFunc(EBSVolumeFilterType)913 maxVolume := maxVolumeFunc(node)914 if maxVolume != volumeutil.DefaultMaxEBSVolumes {915 t.Errorf("Expected max volume to be %d got %d", volumeutil.DefaultMaxEBSVolumes, maxVolume)916 }917}918func getNodeWithPodAndVolumeLimits(pods []*v1.Pod, limit int64, driverNames ...string) *schedulernodeinfo.NodeInfo {919 nodeInfo := schedulernodeinfo.NewNodeInfo(pods...)920 node := &v1.Node{921 ObjectMeta: metav1.ObjectMeta{Name: "node-for-max-pd-test-1"},922 Status: v1.NodeStatus{923 Allocatable: v1.ResourceList{},924 },925 }926 for _, driver := range driverNames {927 node.Status.Allocatable[getVolumeLimitKey(driver)] = *resource.NewQuantity(limit, resource.DecimalSI)928 }929 nodeInfo.SetNode(node)930 return nodeInfo931}932func getVolumeLimitKey(filterType string) v1.ResourceName {933 switch filterType {934 case EBSVolumeFilterType:935 return v1.ResourceName(volumeutil.EBSVolumeLimitKey)936 case GCEPDVolumeFilterType:937 return v1.ResourceName(volumeutil.GCEVolumeLimitKey)938 case AzureDiskVolumeFilterType:939 return v1.ResourceName(volumeutil.AzureVolumeLimitKey)940 case CinderVolumeFilterType:941 return v1.ResourceName(volumeutil.CinderVolumeLimitKey)942 default:943 return v1.ResourceName(volumeutil.GetCSIAttachLimitKey(filterType))944 }945}...
consumer_test.go
Source:consumer_test.go
1package sourcemap_test2import (3 "encoding/json"4 "fmt"5 "io/ioutil"6 "net/http"7 "strings"8 "testing"9 "github.com/nanzm/sourcemap"10)11const jqSourceMapURL = "http://code.jquery.com/jquery-2.0.3.min.map"12var jqSourceMapBytes []byte13func init() {14 resp, err := http.Get(jqSourceMapURL)15 if err != nil {16 panic(err)17 }18 defer resp.Body.Close()19 jqSourceMapBytes, err = ioutil.ReadAll(resp.Body)20 if err != nil {21 panic(err)22 }23}24type sourceMapTest struct {25 genLine int26 genColumn int27 wantedSource string28 wantedName string29 wantedLine int30 wantedColumn int31}32func (test *sourceMapTest) String() string {33 return fmt.Sprintf("line=%d col=%d in file=%s", test.genLine, test.genColumn, test.wantedSource)34}35func (test *sourceMapTest) assert(t *testing.T, smap *sourcemap.Consumer) {36 source, name, line, col, ok := smap.Source(test.genLine, test.genColumn)37 if !ok {38 if test.wantedSource == "" &&39 test.wantedName == "" &&40 test.wantedLine == 0 &&41 test.wantedColumn == 0 {42 return43 }44 t.Fatalf("Source not found for %s", test)45 }46 if source != test.wantedSource {47 t.Fatalf("file: got %q, wanted %q (%s)", source, test.wantedSource, test)48 }49 if name != test.wantedName {50 t.Fatalf("func: got %q, wanted %q (%s)", name, test.wantedName, test)51 }52 if line != test.wantedLine {53 t.Fatalf("line: got %d, wanted %d (%s)", line, test.wantedLine, test)54 }55 if col != test.wantedColumn {56 t.Fatalf("column: got %d, wanted %d (%s)", col, test.wantedColumn, test)57 }58}59func TestSourceMap(t *testing.T) {60 testSourceMap(t, sourceMapJSON)61}62func TestOriginSource(t *testing.T) {63 file, err := ioutil.ReadFile("assets/SdkTest.1db18e51.js.map")64 if err != nil {65 panic(err)66 return67 }68 parse, err := sourcemap.Parse("", file)69 if err != nil {70 panic(err)71 }72 source, name, line, column, ok := parse.Source(1, 201)73 fmt.Println(source, name, line, column, ok)74 codes := parse.OriginSource(source, line, column)75 //for _, code := range codes {76 // fmt.Println(code.Code)77 //}78 marshal, err := json.MarshalIndent(codes, "", " ")79 if err != nil {80 t.Fatal(err)81 }82 fmt.Println(string(marshal))83}84func TestIndexedSourceMap(t *testing.T) {85 testSourceMap(t, indexedSourceMapJSON)86}87func testSourceMap(t *testing.T, json string) {88 smap, err := sourcemap.Parse("", []byte(json))89 if err != nil {90 t.Fatal(err)91 }92 tests := []sourceMapTest{93 {1, 1, "/the/root/one.js", "", 1, 1},94 {1, 5, "/the/root/one.js", "", 1, 5},95 {1, 9, "/the/root/one.js", "", 1, 11},96 {1, 18, "/the/root/one.js", "bar", 1, 21},97 {1, 21, "/the/root/one.js", "", 2, 3},98 {1, 28, "/the/root/one.js", "baz", 2, 10},99 {1, 32, "/the/root/one.js", "bar", 2, 14},100 {2, 1, "/the/root/two.js", "", 1, 1},101 {2, 5, "/the/root/two.js", "", 1, 5},102 {2, 9, "/the/root/two.js", "", 1, 11},103 {2, 18, "/the/root/two.js", "n", 1, 21},104 {2, 21, "/the/root/two.js", "", 2, 3},105 {2, 28, "/the/root/two.js", "n", 2, 10},106 // Fuzzy match.107 {1, 20, "/the/root/one.js", "bar", 1, 21},108 {1, 30, "/the/root/one.js", "baz", 2, 10},109 {2, 12, "/the/root/two.js", "", 1, 11},110 }111 for i := range tests {112 tests[i].assert(t, smap)113 }114 content := smap.SourceContent("/the/root/one.js")115 if content != oneSourceContent {116 t.Fatalf("%q != %q", content, oneSourceContent)117 }118 content = smap.SourceContent("/the/root/two.js")119 if content != twoSourceContent {120 t.Fatalf("%q != %q", content, twoSourceContent)121 }122 _, _, _, _, ok := smap.Source(3, 0)123 if ok {124 t.Fatal("source must not exist")125 }126}127func TestSourceRootURL(t *testing.T) {128 jsonStr := sourceMapJSON129 jsonStr = strings.Replace(jsonStr, "/the/root", "http://the/root", 1)130 jsonStr = strings.Replace(jsonStr, "one.js", "../one.js", 1)131 smap, err := sourcemap.Parse("", []byte(jsonStr))132 if err != nil {133 t.Fatal(err)134 }135 tests := []*sourceMapTest{136 {1, 1, "http://the/one.js", "", 1, 1},137 {2, 1, "http://the/root/two.js", "", 1, 1},138 }139 for _, test := range tests {140 test.assert(t, smap)141 }142}143func TestEmptySourceRootURL(t *testing.T) {144 jsonStr := sourceMapJSON145 jsonStr = strings.Replace(jsonStr, "/the/root", "", 1)146 jsonStr = strings.Replace(jsonStr, "one.js", "../one.js", 1)147 smap, err := sourcemap.Parse("http://the/root/app.min.map", []byte(jsonStr))148 if err != nil {149 t.Fatal(err)150 }151 tests := []*sourceMapTest{152 {1, 1, "http://the/one.js", "", 1, 1},153 {2, 1, "http://the/root/two.js", "", 1, 1},154 }155 for _, test := range tests {156 test.assert(t, smap)157 }158}159func TestAbsSourceURL(t *testing.T) {160 jsonStr := sourceMapJSON161 jsonStr = strings.Replace(jsonStr, "/the/root", "", 1)162 jsonStr = strings.Replace(jsonStr, "one.js", "http://the/root/one.js", 1)163 jsonStr = strings.Replace(jsonStr, "two.js", "/another/root/two.js", 1)164 testAbsSourceURL(t, "", jsonStr)165 testAbsSourceURL(t, "http://path/to/map", jsonStr)166}167func testAbsSourceURL(t *testing.T, mapURL, jsonStr string) {168 smap, err := sourcemap.Parse(mapURL, []byte(jsonStr))169 if err != nil {170 t.Fatal(err)171 }172 tests := []*sourceMapTest{173 {1, 1, "http://the/root/one.js", "", 1, 1},174 {2, 1, "/another/root/two.js", "", 1, 1},175 }176 for _, test := range tests {177 test.assert(t, smap)178 }179}180func TestJQuerySourceMap(t *testing.T) {181 smap, err := sourcemap.Parse(jqSourceMapURL, jqSourceMapBytes)182 if err != nil {183 t.Fatal(err)184 }185 tests := []*sourceMapTest{186 {1, 1, "", "", 0, 0},187 {4, 0, "", "", 0, 0},188 {4, 1, "http://code.jquery.com/jquery-2.0.3.js", "", 14, 0},189 {4, 10, "http://code.jquery.com/jquery-2.0.3.js", "window", 14, 11},190 {5, 6789, "http://code.jquery.com/jquery-2.0.3.js", "apply", 4360, 27},191 {5, 10006, "http://code.jquery.com/jquery-2.0.3.js", "apply", 4676, 8},192 {4, 553, "http://code.jquery.com/jquery-2.0.3.js", "ready", 93, 9},193 {999999, 0, "", "", 0, 0},194 }195 for _, test := range tests {196 test.assert(t, smap)197 }198}199// https://github.com/mozilla/source-map/blob/master/test/util.js200//201// This is a test mapping which maps functions from two different files202// (one.js and two.js) to a minified generated source.203//204// Here is one.js:205//206// ONE.foo = function (bar) {207// return baz(bar);208// };209//210// Here is two.js:211//212// TWO.inc = function (n) {213// return n + 1;214// };215//216// And here is the generated code (min.js):217//218// ONE.foo=function(a){return baz(a);};219// TWO.inc=function(a){return a+1;};220const genCode = `exports.testGeneratedCode = "ONE.foo=function(a){return baz(a);};221TWO.inc=function(a){return a+1;};`222var oneSourceContent = `ONE.foo = function (bar) {223 return baz(bar);224};`225var twoSourceContent = `TWO.inc = function (n) {226 return n + 1;227};`228var sourceMapJSON = `{229 "version": 3,230 "file": "min.js",231 "sources": ["one.js", "two.js"],232 "sourcesContent": ` + j([]string{oneSourceContent, twoSourceContent}) + `,233 "sourceRoot": "/the/root",234 "names": ["bar", "baz", "n"],235 "mappings": "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA"236}`237func j(v interface{}) string {238 b, _ := json.Marshal(v)239 return string(b)240}241var indexedSourceMapJSON = `{242 "version": 3,243 "file": "min.js",244 "sections": [{245 "offset": {"line": 0, "column": 0},246 "map": {247 "version": 3,248 "file": "min.js",249 "sources": ["one.js"],250 "sourcesContent": ` + j([]string{oneSourceContent}) + `,251 "sourceRoot": "/the/root",252 "names": ["bar", "baz"],253 "mappings": "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID"254 }255 }, {256 "offset": {"line": 1, "column": 0},257 "map": {258 "version": 3,259 "file": "min.js",260 "sources": ["two.js"],261 "sourcesContent": ` + j([]string{twoSourceContent}) + `,262 "sourceRoot": "/the/root",263 "names": ["n"],264 "mappings": "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA"265 }266 }]267}`...
mutate_test.go
Source:mutate_test.go
...19)20const (21 namespace = "test"22 bindingNameOne = "binding-test-one"23 bindingNameTwo = "binding-test-two"24 bindingNameThree = "binding-test-three"25 secretNameOne = "secret-test-one"26 secretNameTwo = "secret-test-two"27 configMapName = "config-map-test"28 secretEnvOneKey = "PASSWORD"29 secretEnvTwoKey = "TOKEN"30 configMapEnvKey = "CONFIG"31)32func TestMutationHandler_Handle(t *testing.T) {33 // given34 sch, err := v1alpha1.SchemeBuilder.Build()35 require.NoError(t, err)36 err = scheme.AddToScheme(sch)37 require.NoError(t, err)38 request := admission.Request{39 AdmissionRequest: v1beta1.AdmissionRequest{40 UID: "1234-abcd",41 Operation: v1beta1.Create,42 Name: "test-pod",43 Namespace: namespace,44 Kind: metav1.GroupVersionKind{45 Kind: "Pod",46 Version: "v1",47 Group: "",48 },49 Object: runtime.RawExtension{Raw: rawPod()},50 },51 }52 fakeClient := fake.NewFakeClientWithScheme(sch, fixBindingOne(), fixBindingTwo(), fixBindingThree(), fixSecretOne(), fixSecretTwo(), fixConfigMap())53 decoder, err := admission.NewDecoder(scheme.Scheme)54 require.NoError(t, err)55 handler := NewMutationHandler(webhook.NewClient(fakeClient), logrus.New())56 err = handler.InjectDecoder(decoder)57 require.NoError(t, err)58 // when59 response := handler.Handle(context.TODO(), request)60 // then61 assert.True(t, response.Allowed)62 // filtering out status cause k8s api-server will discard this too63 patches := filterOutStatusPatch(response.Patches)64 assert.Len(t, patches, 2)65 for _, patch := range patches {66 assert.Equal(t, "add", patch.Operation)67 assert.Contains(t, []string{"/spec/containers/0/env", "/spec/containers/1/env"}, patch.Path)68 assert.Len(t, patch.Value, 3)69 assert.ElementsMatch(t, patch.Value, []interface{}{70 map[string]interface{}{71 "name": secretEnvOneKey,72 "valueFrom": map[string]interface{}{73 "secretKeyRef": map[string]interface{}{74 "key": secretEnvOneKey,75 "name": secretNameOne,76 },77 },78 },79 map[string]interface{}{80 "name": secretEnvTwoKey,81 "valueFrom": map[string]interface{}{82 "secretKeyRef": map[string]interface{}{83 "key": secretEnvTwoKey,84 "name": secretNameTwo,85 },86 },87 },88 map[string]interface{}{89 "name": configMapEnvKey,90 "valueFrom": map[string]interface{}{91 "configMapKeyRef": map[string]interface{}{92 "key": configMapEnvKey,93 "name": configMapName,94 },95 },96 },97 })98 }99}100func fixBindingOne() *v1alpha1.Binding {101 return &v1alpha1.Binding{102 ObjectMeta: metav1.ObjectMeta{103 Name: bindingNameOne,104 Namespace: namespace,105 },106 Spec: v1alpha1.BindingSpec{107 Source: v1alpha1.Source{108 Kind: v1alpha1.SourceKindSecret,109 Name: secretNameOne,110 },111 },112 Status: v1alpha1.BindingStatus{113 Phase: v1alpha1.BindingReady,114 Message: "la loza lorem ipsum dolores sit onface",115 Source: fmt.Sprintf("%s/%s", v1alpha1.SourceKindSecret, secretNameOne),116 },117 }118}119func fixBindingTwo() *v1alpha1.Binding {120 return &v1alpha1.Binding{121 ObjectMeta: metav1.ObjectMeta{122 Name: bindingNameTwo,123 Namespace: namespace,124 },125 Spec: v1alpha1.BindingSpec{126 Source: v1alpha1.Source{127 Kind: v1alpha1.SourceKindSecret,128 Name: secretNameTwo,129 },130 },131 Status: v1alpha1.BindingStatus{132 Phase: v1alpha1.BindingReady,133 Message: "lorem ipsum dolor sit amet",134 Source: fmt.Sprintf("%s/%s", v1alpha1.SourceKindSecret, secretNameTwo),135 },136 }137}138func fixBindingThree() *v1alpha1.Binding {139 return &v1alpha1.Binding{140 ObjectMeta: metav1.ObjectMeta{141 Name: bindingNameThree,142 Namespace: namespace,143 },144 Spec: v1alpha1.BindingSpec{145 Source: v1alpha1.Source{146 Kind: v1alpha1.SourceKindConfigMap,147 Name: configMapName,148 },149 },150 Status: v1alpha1.BindingStatus{151 Phase: v1alpha1.BindingReady,152 Message: "consectetur adipiscing elit, sed do eiusmod tempor incididunt",153 Source: fmt.Sprintf("%s/%s", v1alpha1.SourceKindConfigMap, configMapName),154 },155 }156}157func fixSecretOne() *corev1.Secret {158 return &corev1.Secret{159 ObjectMeta: metav1.ObjectMeta{160 Name: secretNameOne,161 Namespace: namespace,162 },163 Data: map[string][]byte{164 secretEnvOneKey: []byte("superSecretPassword"),165 },166 }167}168func fixSecretTwo() *corev1.Secret {169 return &corev1.Secret{170 ObjectMeta: metav1.ObjectMeta{171 Name: secretNameTwo,172 Namespace: namespace,173 },174 Data: map[string][]byte{175 secretEnvTwoKey: []byte("superSecretToken"),176 },177 }178}179func fixConfigMap() *corev1.ConfigMap {180 return &corev1.ConfigMap{181 ObjectMeta: metav1.ObjectMeta{182 Name: configMapName,183 Namespace: namespace,184 },185 Data: map[string]string{186 configMapEnvKey: "configForPod",187 },188 }189}190func rawPod() []byte {191 return []byte(fmt.Sprintf(`{192 "apiVersion": "v1",193 "kind": "Pod",194 "metadata": {195 "creationTimestamp": null,196 "name": "test-pod",197 "labels": {198 "%s/%s": "1234",199 "%s/%s": "4567",200 "%s/%s": "9875"201 }202 },203 "spec": {204 "containers": [205 {206 "name": "test",207 "image": "test",208 "resources": {}209 },210 {211 "name": "test2",212 "image": "test2",213 "resources": {}214 }215 ]216 }217 }`, v1alpha1.BindingLabelKey, bindingNameOne, v1alpha1.BindingLabelKey, bindingNameTwo, v1alpha1.BindingLabelKey, bindingNameThree))218}219func filterOutStatusPatch(operations []jsonpatch.JsonPatchOperation) []jsonpatch.JsonPatchOperation {220 var filtered []jsonpatch.JsonPatchOperation221 for _, op := range operations {222 if op.Path != "/status" {223 filtered = append(filtered, op)224 }225 }226 return filtered227}...
Two
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 source.Two()5}6import (7func main() {8 fmt.Println("Hello, playground")9 source.One()10}11import "fmt"12func One() {13 fmt.Println("One")14}15func Two() {16 fmt.Println("Two")17}18import "testing"19func TestOne(t *testing.T) {20 One()21}22func TestTwo(t *testing.T) {23 Two()24}
Two
Using AI Code Generation
1import (2func main() {3 fmt.Printf("Hello, world.\n")4 source.Two()5}6import (7func main() {8 fmt.Printf("Hello, world.\n")9 source.One()10}11import "fmt"12func One() {13 fmt.Printf("One\n")14}15func Two() {16 fmt.Printf("Two\n")17}18import (19func main() {20 fmt.Printf("Hello, world.\n")21 source.One()22}23import (24func main() {25 fmt.Printf("Hello, world.\n")26 source.Two()27}28import (29func main() {30 fmt.Printf("Hello, world.\n")31 source.One()32}33import (34func main() {35 fmt.Printf("Hello, world.\n")36 source.Two()37}
Two
Using AI Code Generation
1import "fmt"2import "myPackage"3func main() {4 fmt.Println("Hello, World!")5 myPackage.Two()6}7import "fmt"8import "myPackage"9func main() {10 fmt.Println("Hello, World!")11 myPackage.One()12}13import "fmt"14import "myPackage"15func main() {16 fmt.Println("Hello, World!")17 myPackage.Two()18}19import "fmt"20import "myPackage"21func main() {22 fmt.Println("Hello, World!")23 myPackage.One()24}25import "fmt"26import "myPackage"27func main() {28 fmt.Println("Hello, World!")29 myPackage.Two()30}31import "fmt"32import "myPackage"33func main() {34 fmt.Println("Hello, World!")35 myPackage.One()36}37import "fmt"38import "myPackage"39func main() {40 fmt.Println("Hello, World!")41 myPackage.Two()42}43import "fmt"44import "myPackage"45func main() {46 fmt.Println("Hello, World!")47 myPackage.One()48}49import "fmt"50import "myPackage"51func main() {52 fmt.Println("Hello, World!")53 myPackage.Two()54}55import "fmt"56import "myPackage"57func main() {58 fmt.Println("Hello, World!")59 myPackage.One()60}61import "fmt"62import "myPackage"63func main() {64 fmt.Println("Hello, World
Two
Using AI Code Generation
1import (2func main() {3 source.Two()4 fmt.Println("Hello World")5}6import (7func main() {8 source.One()9 fmt.Println("Hello World")10}
Two
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello World")4 source := source.NewSource()5 source.One()6 source.Two()7}8import (9func main() {10 fmt.Println("Hello World")11 source := source.NewSource()12 source.One()13}14type Source struct {15}16func NewSource() *Source {17 return &Source{}18}19func (s *Source) One() {20}21func (s *Source) Two() {22}
Two
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, World!")4 src := pkg.Source{}5 fmt.Println(src.Two())6}
Two
Using AI Code Generation
1import (2func main() {3 fmt.Println(source.Two())4}5import (6func main() {7 fmt.Println(source.two())8}9./1.go:12:6: source.two undefined (type source has no field or method two)
Two
Using AI Code Generation
1import (2func main() {3 s := source.NewSource()4 s.Two()5}6import (7func main() {8 s := source.NewSource()9 s.One()10}11import (12func main() {13 s := source.NewSource()14 s.Two()15}16import (17func main() {18 s := source.NewSource()19 s.One()20}21import (22func main() {23 s := source.NewSource()24 s.Two()25}26import (27func main() {28 s := source.NewSource()29 s.One()30}31import (32func main() {33 s := source.NewSource()34 s.Two()35}36import (37func main() {
Two
Using AI Code Generation
1import (2func main() {3 fmt.Println(source.Two())4}5import (6func main() {7 fmt.Println(ohoh.Ohoh())8}9Traceback (most recent call last):10 import os
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!