Skip to content

Commit 76675ce

Browse files
committed
Add E2E tests for Propagation Policy/Namespace level in the dashboard
Signed-off-by: SunsetB612 <[email protected]>
1 parent 297ed6c commit 76675ce

File tree

11 files changed

+1025
-6
lines changed

11 files changed

+1025
-6
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,31 @@ jobs:
187187
echo "Testing API connectivity..."
188188
curl -f http://localhost:8000/api/v1/cluster && echo "✓ Cluster API works" || echo "✗ Cluster API failed"
189189
curl -f http://localhost:8000/api/v1/namespace && echo "✓ Namespace API works" || echo "✗ Namespace API failed"
190+
echo ""
191+
echo "========== DEBUG: Testing PropagationPolicy API =========="
192+
echo "Testing GET /api/v1/propagationpolicy..."
193+
echo "Response:"
194+
curl -v http://localhost:8000/api/v1/propagationpolicy 2>&1
195+
echo ""
196+
echo "Testing GET /api/v1/propagationpolicy/default (with namespace)..."
197+
echo "Response:"
198+
curl -v http://localhost:8000/api/v1/propagationpolicy/default 2>&1 | head -50
199+
echo "========== DEBUG: END =========="
200+
echo ""
190201
echo "API tests completed"
191202
- name: Debug working dir
192203
if: ${{ env.DEBUG == 'true' }}
193204
run: |
194205
pwd
195206
ls -al
207+
# - name: Run Playwright tests
208+
# working-directory: karmada-dashboard/ui/apps/dashboard
209+
# run: |
210+
# pnpm exec playwright test
196211
- name: Run Playwright tests
197212
working-directory: karmada-dashboard/ui/apps/dashboard
198213
run: |
199-
pnpm exec playwright test
214+
pnpm test:e2e e2e/policy/*
200215
- name: Cleanup processes
201216
if: always()
202217
run: |

cmd/api/app/routes/propagationpolicy/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func handleGetPropagationPolicyList(c *gin.Context) {
4646
common.Fail(c, err)
4747
return
4848
}
49-
propagationList, err := propagationpolicy.GetPropagationPolicyList(karmadaClient, k8sClient, namespace, dataSelect)
49+
propagationList, err := propagationpolicy.GetPropagationPolicyList(karmadaClient, k8sClient, namespace, dataSelect, c.Request)
5050
if err != nil {
5151
klog.ErrorS(err, "Failed to GetPropagationPolicyList")
5252
common.Fail(c, err)

pkg/resource/propagationpolicy/list.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"log"
23+
"net/http"
2324
"strings"
2425

2526
"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
@@ -56,18 +57,18 @@ type PropagationPolicy struct {
5657
}
5758

5859
// GetPropagationPolicyList returns a list of all propagations in the karmada control-plance.
59-
func GetPropagationPolicyList(client karmadaclientset.Interface, k8sClient kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.DataSelectQuery) (*PropagationPolicyList, error) {
60+
func GetPropagationPolicyList(client karmadaclientset.Interface, k8sClient kubernetes.Interface, nsQuery *common.NamespaceQuery, dsQuery *dataselect.DataSelectQuery, request *http.Request) (*PropagationPolicyList, error) {
6061
log.Println("Getting list of namespaces")
6162
propagationpolicies, err := client.PolicyV1alpha1().PropagationPolicies(nsQuery.ToRequestParam()).List(context.TODO(), helpers.ListEverything)
6263
nonCriticalErrors, criticalError := errors.ExtractErrors(err)
6364
if criticalError != nil {
6465
return nil, criticalError
6566
}
6667

67-
return toPropagationPolicyList(k8sClient, propagationpolicies.Items, nonCriticalErrors, dsQuery), nil
68+
return toPropagationPolicyList(k8sClient, propagationpolicies.Items, nonCriticalErrors, dsQuery, request), nil
6869
}
6970

70-
func toPropagationPolicyList(_ kubernetes.Interface, propagationpolicies []v1alpha1.PropagationPolicy, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *PropagationPolicyList {
71+
func toPropagationPolicyList(_ kubernetes.Interface, propagationpolicies []v1alpha1.PropagationPolicy, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery, request *http.Request) *PropagationPolicyList {
7172
propagationpolicyList := &PropagationPolicyList{
7273
PropagationPolicys: make([]PropagationPolicy, 0),
7374
ListMeta: types.ListMeta{TotalItems: len(propagationpolicies)},
@@ -77,7 +78,7 @@ func toPropagationPolicyList(_ kubernetes.Interface, propagationpolicies []v1alp
7778
propagationpolicyList.ListMeta = types.ListMeta{TotalItems: filteredTotal}
7879
propagationpolicyList.Errors = nonCriticalErrors
7980

80-
verberClient, err := client.VerberClient(nil)
81+
verberClient, err := client.VerberClient(request)
8182
if err != nil {
8283
panic(err)
8384
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright 2025 The Karmada Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { test } from '@playwright/test';
18+
import {
19+
setupDashboardAuthentication,
20+
generateTestPropagationPolicyYaml,
21+
deleteK8sPropagationPolicy,
22+
getPropagationPolicyNameFromYaml,
23+
createPropagationPolicyResourceTest
24+
} from './test-utils';
25+
26+
test.beforeEach(async ({ page }) => {
27+
await setupDashboardAuthentication(page);
28+
});
29+
30+
test('should create a new propagationpolicy', async ({ page }) => {
31+
const testPropagationPolicyYaml = generateTestPropagationPolicyYaml();
32+
33+
await createPropagationPolicyResourceTest(page, {
34+
resourceType: 'propagationpolicy',
35+
tabName: 'Namespace level',
36+
apiEndpoint: '/propagationpolicy',
37+
yamlContent: testPropagationPolicyYaml,
38+
getResourceName: getPropagationPolicyNameFromYaml,
39+
deleteResource: deleteK8sPropagationPolicy,
40+
screenshotName: 'debug-propagationpolicy-create.png'
41+
});
42+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright 2025 The Karmada Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { test } from '@playwright/test';
18+
import {
19+
setupDashboardAuthentication,
20+
generateTestPropagationPolicyYaml,
21+
createK8sPropagationPolicy,
22+
getPropagationPolicyNameFromYaml,
23+
deletePropagationPolicyResourceTest
24+
} from './test-utils';
25+
26+
test.beforeEach(async ({ page }) => {
27+
await setupDashboardAuthentication(page);
28+
});
29+
30+
test('should delete propagationpolicy successfully', async ({ page }) => {
31+
const testPropagationPolicyYaml = generateTestPropagationPolicyYaml();
32+
33+
await deletePropagationPolicyResourceTest(page, {
34+
resourceType: 'propagationpolicy',
35+
tabName: 'Namespace level',
36+
apiEndpointPattern: '/propagationpolicy',
37+
yamlContent: testPropagationPolicyYaml,
38+
getResourceName: getPropagationPolicyNameFromYaml,
39+
createResource: createK8sPropagationPolicy,
40+
screenshotName: 'debug-propagationpolicy-delete-kubectl.png'
41+
});
42+
});

0 commit comments

Comments
 (0)