Skip to content

Commit bcedab8

Browse files
committed
Added the option to test only certain test functions.
This commit introduces a development mode that allows the test suite itself to create a Kubernetes cluster for testing Signed-off-by: Toni Finger <[email protected]>
1 parent 304ae16 commit bcedab8

File tree

10 files changed

+95
-399
lines changed

10 files changed

+95
-399
lines changed

Tests/kaas/kaas-sonobuoy-tests/Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ PLUGIN_NAME="scs-conformance-sonobuoy-plugin"
1616
PLUGIN_FILE="${PLUGIN_NAME}.yaml"
1717
KIND_CONFIG_FILE="kind_config.yaml"
1818

19-
SONO_WAIT= 30
19+
SONO_WAIT= 10
2020

2121
###############################################################################
2222
## Helpers: ##
@@ -69,7 +69,6 @@ dev-build: container-init
6969
dev-run:
7070
@echo "[Running sonobuoy...]"
7171
@sonobuoy run -p ${PLUGIN_FILE} --wait=${SONO_WAIT}
72-
@sonobuoy status
7372

7473

7574
dev-run-background:
@@ -85,14 +84,23 @@ dev-result: dev-clean-result
8584
mkdir results
8685
tar -xf *.tar.gz -C results
8786
cat results/plugins/scs-kaas-conformance/sonobuoy_results.yaml | yq
88-
cat results/plugins/scs-kaas-conformance/results/global/out.json | jq
87+
cat results/plugins/scs-kaas-conformance/results/global/out.json | jq '.Output'
8988
@echo "[Displaying results...]"
9089
sonobuoy results *.tar.gz
9190

9291

9392
dev-rerun: dev-clean-sonobuoy dev-build dev-run dev-result
9493

9594

95+
test-function:
96+
@echo "only run tests for: $${TESTFUNCTION_CODE}"
97+
DEVELOPMENT_MODE=createcluster go test -run=$${TESTFUNCTION_CODE} ./... || true
98+
99+
100+
lint:
101+
@echo "NOT YET IMPLEMENTED"
102+
103+
96104
dev-clean-result:
97105
@rm -rf *.tar.gz || true
98106
@rm -rf results || true
@@ -101,7 +109,6 @@ dev-clean-result:
101109
dev-clean-sonobuoy: dev-clean-result
102110
@echo "[Cleanup sonobuoy environment from cluster...]"
103111
@sonobuoy delete --all --wait || true
104-
@sonobuoy status || true
105112

106113

107114
dev-purge: kind-init dev-clean-sonobuoy

Tests/kaas/kaas-sonobuoy-tests/README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ For test development with Sonobuoy, [KinD](https://kind.sigs.k8s.io/) is used as
3434
make dev-setup
3535
```
3636

37-
* (Optional): Set env
38-
39-
```bash
40-
export TEST_STANDARD=<standard number code>
41-
```
42-
43-
4437
1. Build the image and upload it to the KinD cluster
4538

4639
```bash
@@ -87,3 +80,13 @@ Finnaly to remove the kind cluster simply use:
8780
```bash
8881
make dev-purge
8982
```
83+
84+
## Execution of only certain test functions for development purposes
85+
86+
```bash
87+
export TESTFUNCTION_CODE=<standard number code>
88+
make test-function
89+
```
90+
91+
92+

Tests/kaas/kaas-sonobuoy-tests/go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module kaas/kaas-sonobuoy-go-example-2
1+
module kaas/kaas-sonobuoy-tests
22

3-
go 1.17
3+
go 1.21
44

55
require (
66
github.com/vmware-tanzu/sonobuoy-plugins/plugin-helper v0.0.0-20211029183731-1d6848b67eec
@@ -27,6 +27,7 @@ require (
2727
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
2828
github.com/sirupsen/logrus v1.7.0 // indirect
2929
github.com/spf13/pflag v1.0.5 // indirect
30+
github.com/vladimirvivien/gexe v0.1.1 // indirect
3031
github.com/vmware-tanzu/sonobuoy v1.11.5-prerelease.1.0.20211004145628-b633b4fefcdc // indirect
3132
golang.org/x/net v0.23.0 // indirect
3233
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect

Tests/kaas/kaas-sonobuoy-tests/go.sum

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
413413
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
414414
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
415415
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
416-
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
417416
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
418417
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
419418
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
@@ -444,9 +443,6 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
444443
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
445444
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
446445
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
447-
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
448-
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
449-
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
450446
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
451447
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
452448
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -478,8 +474,6 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB
478474
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
479475
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
480476
golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
481-
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
482-
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
483477
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
484478
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
485479
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -511,12 +505,7 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/
511505
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
512506
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
513507
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
514-
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
515508
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
516-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
517-
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
518-
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
519-
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
520509
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
521510
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
522511
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -533,8 +522,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
533522
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
534523
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
535524
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
536-
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
537-
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
538525
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
539526
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
540527
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -583,21 +570,12 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
583570
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
584571
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
585572
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
586-
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
587-
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
588-
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
589-
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
590-
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
591573
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
592574
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
593575
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
594576
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
595577
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
596578
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
597-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
598-
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
599-
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
600-
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
601579
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
602580
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
603581
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -607,9 +585,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
607585
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
608586
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
609587
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
610-
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
611-
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
612-
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
613588
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
614589
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
615590
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@@ -659,8 +634,6 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
659634
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
660635
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
661636
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
662-
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
663-
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
664637
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
665638
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
666639
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -783,7 +756,6 @@ k8s.io/code-generator v0.21.1/go.mod h1:hUlps5+9QaTrKx+jiM4rmq7YmH8wPOIko64uZCHD
783756
k8s.io/component-base v0.21.1/go.mod h1:NgzFZ2qu4m1juby4TnrmpR8adRk6ka62YdH5DkIIyKA=
784757
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
785758
k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
786-
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
787759
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
788760
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
789761
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=

Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ import (
55
"fmt"
66
"os"
77
"testing"
8-
8+
"log"
99
plugin_helper "github.com/vmware-tanzu/sonobuoy-plugins/plugin-helper"
1010
v1 "k8s.io/api/core/v1"
1111
"sigs.k8s.io/e2e-framework/pkg/env"
1212
"sigs.k8s.io/e2e-framework/pkg/envconf"
13+
"sigs.k8s.io/e2e-framework/pkg/envfuncs"
1314
)
1415

1516

1617
const (
1718
ProgressReporterCtxKey = "SONOBUOY_PROGRESS_REPORTER"
1819
NamespacePrefixKey = "NS_PREFIX"
20+
DevelopmentModeKey = "DEVELOPMENT_MODE"
1921
)
2022

2123
var testenv env.Environment
2224

2325
func TestMain(m *testing.M) {
24-
// Assume we are running in the cluster as a Sonobuoy plugin.
25-
testenv = env.NewInClusterConfig()
2626

2727
// Specifying a run ID so that multiple runs wouldn't collide. Allow a prefix to be set via env var
2828
// so that a plugin configuration (yaml file) can easily set that without code changes.
@@ -32,21 +32,65 @@ func TestMain(m *testing.M) {
3232
// Create updateReporter; will also place into context during Setup for use in features.
3333
updateReporter := plugin_helper.NewProgressReporter(0)
3434

35-
testenv.Setup(func(ctx context.Context, config *envconf.Config) (context.Context, error) {
36-
// Try and create the client; doing it before all the tests allows the tests to assume
37-
// it can be created without error and they can just use config.Client().
38-
_,err:=config.NewClient()
39-
return context.WithValue(ctx,ProgressReporterCtxKey,updateReporter) ,err
40-
})
35+
developmentMode := os.Getenv(DevelopmentModeKey)
36+
log.Printf("Setup test enviornment for: %#v", developmentMode )
37+
38+
switch KubernetesEnviornment := developmentMode; KubernetesEnviornment {
39+
40+
case "createcluster":
41+
log.Println("Create kind cluster for test")
42+
testenv = env.New()
43+
kindClusterName := envconf.RandomName("gotestcluster", 16)
44+
//~ namespace := envconf.RandomName("testnamespace", 16)
45+
46+
testenv.Setup(
47+
envfuncs.CreateKindCluster(kindClusterName),
48+
)
49+
50+
testenv.Finish(
51+
//~ envfuncs.DeleteNamespace(namespace),
52+
envfuncs.DestroyKindCluster(kindClusterName),
53+
)
54+
55+
case "usecluster":
56+
log.Println("Use existing k8s cluster for the test")
57+
log.Println("TO_BE_IMPLEMENTED")
58+
//~ testenv = env.NewFromFlags()
59+
//~ KubeConfig:= os.Getenv(KUBECONFIGFILE)
60+
//~ testenv = env.NewWithKubeConfig(KubeConfig)
61+
62+
default:
63+
// Assume we are running in the cluster as a Sonobuoy plugin.
64+
log.Println("Running tests inside k8s cluster")
65+
testenv = env.NewInClusterConfig()
66+
67+
testenv.Setup(func(ctx context.Context, config *envconf.Config) (context.Context, error) {
68+
// Try and create the client; doing it before all the tests allows the tests to assume
69+
// it can be created without error and they can just use config.Client().
70+
_,err:=config.NewClient()
71+
return context.WithValue(ctx,ProgressReporterCtxKey,updateReporter) ,err
72+
})
73+
74+
testenv.Finish(
75+
func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
76+
log.Println("Finished go test suite")
77+
//~ if err := ???; err != nil{
78+
//~ return ctx, err
79+
//~ }
80+
return ctx, nil
81+
},
82+
)
83+
84+
}
4185

4286
testenv.BeforeEachTest(func(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error) {
43-
fmt.Println("BeforeEachTest")
87+
fmt.Println("BeforeEachTest")
4488
updateReporter.StartTest(t.Name())
4589
return createNSForTest(ctx, cfg, t, runID)
4690
})
4791

4892
testenv.AfterEachTest(func(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error) {
49-
fmt.Println("AfterEachTest")
93+
fmt.Println("AfterEachTest")
5094
updateReporter.StopTest(t.Name(),t.Failed(),t.Skipped(),nil)
5195
return deleteNSForTest(ctx, cfg, t, runID)
5296
})
@@ -67,17 +111,6 @@ func TestMain(m *testing.M) {
67111
})
68112
*/
69113

70-
testenv.Finish(
71-
// Teardown func: delete kind cluster
72-
func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
73-
fmt.Println("Finished go test suite")
74-
//~ if err := ???; err != nil{
75-
//~ return ctx, err
76-
//~ }
77-
return ctx, nil
78-
},
79-
)
80-
81114
os.Exit(testenv.Run(m))
82115
}
83116

0 commit comments

Comments
 (0)