@@ -37,10 +37,6 @@ import (
3737// at this point.
3838// 3) run './kind-cluster-setup.sh deploy' once prior to these tests
3939
40- // TODO (gfichtenholt) currently core server's has broken logic inside plugins.go
41- // createConfigGetterWithParams(...). Refer to my comment in there. I had to make suggested changes
42- // locally to make these tests pass
43-
4440const (
4541 // the only repo these tests use so far. This is local copy of the first few entries
4642 // on "https://stefanprodan.github.io/podinfo/index.yaml" as of Sept 10 2021 with the chart
@@ -51,60 +47,72 @@ const (
5147)
5248
5349type integrationTestCreateSpec struct {
54- testName string
55- repoUrl string
56- request * corev1.CreateInstalledPackageRequest
57- expectedDetail * corev1.InstalledPackageDetail
58- expectedPodPrefix string
50+ testName string
51+ repoUrl string
52+ request * corev1.CreateInstalledPackageRequest
53+ expectedDetail * corev1.InstalledPackageDetail
54+ expectedPodPrefix string
55+ // different from expectedStatusCode due to async nature of install
5956 expectInstallFailure bool
6057 noCleanup bool
61- unauthorized bool
58+ expectedStatusCode codes. Code
6259}
6360
6461func TestKindClusterCreateInstalledPackage (t * testing.T ) {
6562 fluxPluginClient := checkEnv (t )
6663
6764 testCases := []integrationTestCreateSpec {
6865 {
69- testName : "create test (simplest case)" ,
70- repoUrl : podinfo_repo_url ,
71- request : create_request_basic ,
72- expectedDetail : expected_detail_basic ,
73- expectedPodPrefix : "@TARGET_NS@-my-podinfo-" ,
66+ testName : "create test (simplest case)" ,
67+ repoUrl : podinfo_repo_url ,
68+ request : create_request_basic ,
69+ expectedDetail : expected_detail_basic ,
70+ expectedPodPrefix : "@TARGET_NS@-my-podinfo-" ,
71+ expectedStatusCode : codes .OK ,
7472 },
7573 {
76- testName : "create package (semver constraint)" ,
77- repoUrl : podinfo_repo_url ,
78- request : create_request_semver_constraint ,
79- expectedDetail : expected_detail_semver_constraint ,
80- expectedPodPrefix : "@TARGET_NS@-my-podinfo-2-" ,
74+ testName : "create package (semver constraint)" ,
75+ repoUrl : podinfo_repo_url ,
76+ request : create_request_semver_constraint ,
77+ expectedDetail : expected_detail_semver_constraint ,
78+ expectedPodPrefix : "@TARGET_NS@-my-podinfo-2-" ,
79+ expectedStatusCode : codes .OK ,
8180 },
8281 {
83- testName : "create package (reconcile options)" ,
84- repoUrl : podinfo_repo_url ,
85- request : create_request_reconcile_options ,
86- expectedDetail : expected_detail_reconcile_options ,
87- expectedPodPrefix : "@TARGET_NS@-my-podinfo-3-" ,
82+ testName : "create package (reconcile options)" ,
83+ repoUrl : podinfo_repo_url ,
84+ request : create_request_reconcile_options ,
85+ expectedDetail : expected_detail_reconcile_options ,
86+ expectedPodPrefix : "@TARGET_NS@-my-podinfo-3-" ,
87+ expectedStatusCode : codes .OK ,
8888 },
8989 {
90- testName : "create package (with values)" ,
91- repoUrl : podinfo_repo_url ,
92- request : create_request_with_values ,
93- expectedDetail : expected_detail_with_values ,
94- expectedPodPrefix : "@TARGET_NS@-my-podinfo-4-" ,
90+ testName : "create package (with values)" ,
91+ repoUrl : podinfo_repo_url ,
92+ request : create_request_with_values ,
93+ expectedDetail : expected_detail_with_values ,
94+ expectedPodPrefix : "@TARGET_NS@-my-podinfo-4-" ,
95+ expectedStatusCode : codes .OK ,
9596 },
9697 {
9798 testName : "install fails" ,
9899 repoUrl : podinfo_repo_url ,
99100 request : create_request_install_fails ,
100101 expectedDetail : expected_detail_install_fails ,
101102 expectInstallFailure : true ,
103+ expectedStatusCode : codes .OK ,
102104 },
103105 {
104- testName : "unauthorized" ,
105- repoUrl : podinfo_repo_url ,
106- request : create_request_basic ,
107- unauthorized : true ,
106+ testName : "unauthorized" ,
107+ repoUrl : podinfo_repo_url ,
108+ request : create_request_basic ,
109+ expectedStatusCode : codes .Unauthenticated ,
110+ },
111+ {
112+ testName : "wrong cluster" ,
113+ repoUrl : podinfo_repo_url ,
114+ request : create_request_wrong_cluster ,
115+ expectedStatusCode : codes .Unimplemented ,
108116 },
109117 }
110118
@@ -195,6 +203,7 @@ func TestKindClusterUpdateInstalledPackage(t *testing.T) {
195203 request : update_request_6 ,
196204 unauthorized : true ,
197205 },
206+ // TODO (gfichtenholt) test automatic upgrade to new version when it becomes available
198207 }
199208
200209 grpcContext := newGrpcContext (t , "test-update-admin" )
@@ -412,13 +421,13 @@ func createAndWaitForHelmRelease(t *testing.T, tc integrationTestCreateSpec, flu
412421 }
413422
414423 ctx := grpcContext
415- if tc .unauthorized {
424+ if tc .expectedStatusCode == codes . Unauthenticated {
416425 ctx = context .TODO ()
417426 }
418427 resp , err := fluxPluginClient .CreateInstalledPackage (ctx , tc .request )
419- if tc .unauthorized {
420- if status .Code (err ) != codes . Unauthenticated {
421- t .Fatalf ("Expected Unathenticated , got: %v" , err )
428+ if tc .expectedStatusCode != codes . OK {
429+ if status .Code (err ) != tc . expectedStatusCode {
430+ t .Fatalf ("Expected %v , got: %v" , tc . expectedStatusCode , err )
422431 }
423432 return nil // done, nothing more to check
424433 } else if err != nil {
@@ -481,7 +490,7 @@ func createAndWaitForHelmRelease(t *testing.T, tc integrationTestCreateSpec, flu
481490}
482491
483492func waitUntilInstallCompletes (t * testing.T , fluxPluginClient fluxplugin.FluxV2PackagesServiceClient , grpcContext context.Context , installedPackageRef * corev1.InstalledPackageReference , expectInstallFailure bool ) (actualResp * corev1.GetInstalledPackageDetailResponse ) {
484- const maxWait = 25
493+ const maxWait = 30
485494 for i := 0 ; i <= maxWait ; i ++ {
486495 resp2 , err := fluxPluginClient .GetInstalledPackageDetail (
487496 grpcContext ,
@@ -521,6 +530,7 @@ var (
521530 Name : "my-podinfo" ,
522531 TargetContext : & corev1.Context {
523532 Namespace : "test-1" ,
533+ Cluster : KubeappsCluster ,
524534 },
525535 }
526536
@@ -549,6 +559,7 @@ var (
549559 Name : "my-podinfo-2" ,
550560 TargetContext : & corev1.Context {
551561 Namespace : "test-2" ,
562+ Cluster : KubeappsCluster ,
552563 },
553564 PkgVersionReference : & corev1.VersionReference {
554565 Version : "> 5" ,
@@ -580,6 +591,7 @@ var (
580591 Name : "my-podinfo-3" ,
581592 TargetContext : & corev1.Context {
582593 Namespace : "test-3" ,
594+ Cluster : KubeappsCluster ,
583595 },
584596 ReconciliationOptions : & corev1.ReconciliationOptions {
585597 Interval : 60 ,
@@ -615,6 +627,7 @@ var (
615627 Name : "my-podinfo-4" ,
616628 TargetContext : & corev1.Context {
617629 Namespace : "test-4" ,
630+ Cluster : KubeappsCluster ,
618631 },
619632 Values : "{\" ui\" : { \" message\" : \" what we do in the shadows\" } }" ,
620633 }
@@ -645,6 +658,7 @@ var (
645658 Name : "my-podinfo-5" ,
646659 TargetContext : & corev1.Context {
647660 Namespace : "test-5" ,
661+ Cluster : KubeappsCluster ,
648662 },
649663 Values : "{\" replicaCount\" : \" what we do in the shadows\" }" ,
650664 }
@@ -682,6 +696,7 @@ var (
682696 Name : "my-podinfo-6" ,
683697 TargetContext : & corev1.Context {
684698 Namespace : "test-6" ,
699+ Cluster : KubeappsCluster ,
685700 },
686701 PkgVersionReference : & corev1.VersionReference {
687702 Version : "=5.2.1" ,
@@ -733,6 +748,7 @@ var (
733748 Name : "my-podinfo-7" ,
734749 TargetContext : & corev1.Context {
735750 Namespace : "test-7" ,
751+ Cluster : KubeappsCluster ,
736752 },
737753 PkgVersionReference : & corev1.VersionReference {
738754 Version : "=5.2.1" ,
@@ -785,6 +801,7 @@ var (
785801 Name : "my-podinfo-8" ,
786802 TargetContext : & corev1.Context {
787803 Namespace : "test-8" ,
804+ Cluster : KubeappsCluster ,
788805 },
789806 PkgVersionReference : & corev1.VersionReference {
790807 Version : "=5.2.1" ,
@@ -839,6 +856,7 @@ var (
839856 Name : "my-podinfo-9" ,
840857 TargetContext : & corev1.Context {
841858 Namespace : "test-9" ,
859+ Cluster : KubeappsCluster ,
842860 },
843861 PkgVersionReference : & corev1.VersionReference {
844862 Version : "=5.2.1" ,
@@ -892,6 +910,7 @@ var (
892910 Name : "my-podinfo-10" ,
893911 TargetContext : & corev1.Context {
894912 Namespace : "test-10" ,
913+ Cluster : KubeappsCluster ,
895914 },
896915 PkgVersionReference : & corev1.VersionReference {
897916 Version : "=5.2.1" ,
@@ -925,6 +944,7 @@ var (
925944 Name : "my-podinfo-11" ,
926945 TargetContext : & corev1.Context {
927946 Namespace : "test-11" ,
947+ Cluster : KubeappsCluster ,
928948 },
929949 }
930950
@@ -1000,6 +1020,7 @@ var (
10001020 Name : "my-podinfo-12" ,
10011021 TargetContext : & corev1.Context {
10021022 Namespace : "test-12" ,
1023+ Cluster : KubeappsCluster ,
10031024 },
10041025 PkgVersionReference : & corev1.VersionReference {
10051026 Version : "=5.2.1" ,
@@ -1031,6 +1052,7 @@ var (
10311052 Name : "my-podinfo-13" ,
10321053 TargetContext : & corev1.Context {
10331054 Namespace : "test-13" ,
1055+ Cluster : KubeappsCluster ,
10341056 },
10351057 PkgVersionReference : & corev1.VersionReference {
10361058 Version : "=5.2.1" ,
@@ -1056,4 +1078,13 @@ var (
10561078 "kubectl -n @TARGET_NS@ port-forward deploy/@TARGET_NS@-my-podinfo-13 8080:9898\n " ,
10571079 AvailablePackageRef : availableRef ("podinfo-13/podinfo" , "default" ),
10581080 }
1081+
1082+ create_request_wrong_cluster = & corev1.CreateInstalledPackageRequest {
1083+ AvailablePackageRef : availableRef ("podinfo-14/podinfo" , "default" ),
1084+ Name : "my-podinfo" ,
1085+ TargetContext : & corev1.Context {
1086+ Namespace : "test-14" ,
1087+ Cluster : "this is not the cluster you're looking for" ,
1088+ },
1089+ }
10591090)
0 commit comments