This is an automated email from the ASF dual-hosted git repository.

chia7712 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 02f3170b [YUNIKORN-2499] MockResponseWriter.write() should append new 
bytes instead of rewrite it (#826)
02f3170b is described below

commit 02f3170bf2ef9ff932977c36714f8b1d921f1af7
Author: targetoee <target...@gmail.com>
AuthorDate: Mon Mar 25 14:06:47 2024 +0800

    [YUNIKORN-2499] MockResponseWriter.write() should append new bytes instead 
of rewrite it (#826)
    
    Closes: #826
    
    Signed-off-by: Chia-Ping Tsai <chia7...@gmail.com>
---
 pkg/webservice/handler_mock_test.go | 2 +-
 pkg/webservice/handlers_test.go     | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/pkg/webservice/handler_mock_test.go 
b/pkg/webservice/handler_mock_test.go
index 439efe4f..8f09b807 100644
--- a/pkg/webservice/handler_mock_test.go
+++ b/pkg/webservice/handler_mock_test.go
@@ -43,7 +43,7 @@ func (trw *MockResponseWriter) Header() http.Header {
 }
 
 func (trw *MockResponseWriter) Write(bytes []byte) (int, error) {
-       trw.outputBytes = bytes
+       trw.outputBytes = append(trw.outputBytes, bytes...)
        return len(bytes), nil
 }
 
diff --git a/pkg/webservice/handlers_test.go b/pkg/webservice/handlers_test.go
index 16ac0cc8..dd264d28 100644
--- a/pkg/webservice/handlers_test.go
+++ b/pkg/webservice/handlers_test.go
@@ -501,6 +501,7 @@ func TestGetConfigYAML(t *testing.T) {
 
        // check that we return yaml by default, unmarshal will error when we 
don't
        req.Header.Set("Accept", "unknown")
+       resp = &MockResponseWriter{}
        getClusterConfig(resp, req)
        err = yaml.Unmarshal(resp.outputBytes, conf)
        assert.NilError(t, err, unmarshalError)
@@ -532,6 +533,7 @@ func TestGetConfigJSON(t *testing.T) {
        assert.NilError(t, err, "Error when updating clusterInfo from config")
        configs.SetConfigMap(updatedExtraConf)
 
+       resp = &MockResponseWriter{}
        getClusterConfig(resp, req)
        err = json.Unmarshal(resp.outputBytes, conf)
        assert.NilError(t, err, unmarshalError)
@@ -728,6 +730,7 @@ func TestGetNodeUtilisation(t *testing.T) {
        node2 := addNode(t, partition, node2ID, 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10, 
"second": 5}))
 
        // get nodes utilization
+       resp = &MockResponseWriter{}
        getNodeUtilisation(resp, req)
        utilisation = &dao.NodesUtilDAOInfo{}
        err = json.Unmarshal(resp.outputBytes, utilisation)
@@ -744,6 +747,7 @@ func TestGetNodeUtilisation(t *testing.T) {
        err = rootQ.IncAllocatedResource(resAlloc, false)
        assert.NilError(t, err, "unexpected error returned setting allocated 
resource on queue")
        // get nodes utilization
+       resp = &MockResponseWriter{}
        getNodeUtilisation(resp, req)
        utilisation = &dao.NodesUtilDAOInfo{}
        err = json.Unmarshal(resp.outputBytes, utilisation)
@@ -760,6 +764,7 @@ func TestGetNodeUtilisation(t *testing.T) {
        err = rootQ.IncAllocatedResource(resAlloc, false)
        assert.NilError(t, err, "unexpected error returned setting allocated 
resource on queue")
        // get nodes utilization
+       resp = &MockResponseWriter{}
        getNodeUtilisation(resp, req)
        utilisation = &dao.NodesUtilDAOInfo{}
        err = json.Unmarshal(resp.outputBytes, utilisation)
@@ -879,6 +884,7 @@ func TestGetNodeUtilisations(t *testing.T) {
        addAllocatedResource(t, node4, "alloc-1", "app-1", 
map[string]resources.Quantity{"gpu": 1})
 
        // get nodes utilizations
+       resp = &MockResponseWriter{}
        getNodeUtilisations(resp, req)
        err = json.Unmarshal(resp.outputBytes, &partitionNodesUtilDAOInfo)
        assert.NilError(t, err, "should decode a list of 
*dao.PartitionNodesUtilDAOInfo")
@@ -1958,6 +1964,7 @@ func TestUsersAndGroupsResourceUsage(t *testing.T) {
        assert.NilError(t, err, "Get Groups Resource Usage Handler request 
failed")
 
        var groupsResourceUsageDao []*dao.GroupResourceUsageDAOInfo
+       resp = &MockResponseWriter{}
        getGroupsResourceUsage(resp, req)
        err = json.Unmarshal(resp.outputBytes, &groupsResourceUsageDao)
        assert.NilError(t, err, unmarshalError)


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@yunikorn.apache.org
For additional commands, e-mail: issues-h...@yunikorn.apache.org

Reply via email to