Skip to content

Commit 483043c

Browse files
authored
fix: parsing empty whiteboard (#1391)
Change-Id: I10082f89c36ed77e77e1d016be263e0f7369b7b3
1 parent 6d8dc40 commit 483043c

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

shortcuts/whiteboard/whiteboard_query.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,7 @@ func fetchWhiteboardNodes(runtime *common.RuntimeContext, wbToken string) (*wbNo
184184
return nil, err
185185
}
186186
var nodes wbNodesResp
187-
rawNodes, ok := data["nodes"]
188-
if !ok {
189-
return nil, wbInvalidResponse("get whiteboard nodes failed: missing data.nodes")
190-
}
187+
rawNodes, _ := data["nodes"]
191188
if rawNodes != nil {
192189
var ok bool
193190
nodes.Data.Nodes, ok = rawNodes.([]interface{})

shortcuts/whiteboard/whiteboard_query_test.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -848,11 +848,6 @@ func TestFetchWhiteboardNodes_InvalidResponseTypedError(t *testing.T) {
848848
token string
849849
data map[string]interface{}
850850
}{
851-
{
852-
name: "missing nodes",
853-
token: "test-token-missing-nodes",
854-
data: map[string]interface{}{},
855-
},
856851
{
857852
name: "nodes not array",
858853
token: "test-token-bad-nodes",
@@ -880,6 +875,32 @@ func TestFetchWhiteboardNodes_InvalidResponseTypedError(t *testing.T) {
880875
}
881876
}
882877

878+
// TestFetchWhiteboardNodes_MissingNodesIsEmpty verifies that a response with
879+
// missing nodes field is treated as an empty whiteboard (success), not an error.
880+
// This matches the behavior introduced in commit 4b39b037.
881+
func TestFetchWhiteboardNodes_MissingNodesIsEmpty(t *testing.T) {
882+
factory, stdout, reg := newExecuteFactory(t)
883+
884+
reg.Register(&httpmock.Stub{
885+
Method: "GET",
886+
URL: "/open-apis/board/v1/whiteboards/test-token-missing-nodes/nodes",
887+
Body: map[string]interface{}{
888+
"code": 0,
889+
"msg": "success",
890+
"data": map[string]interface{}{},
891+
},
892+
})
893+
894+
args := []string{"+query", "--whiteboard-token", "test-token-missing-nodes", "--output_as", "raw"}
895+
if err := runShortcut(t, WhiteboardQuery, args, factory, stdout); err != nil {
896+
t.Fatalf("expected success for missing nodes (empty whiteboard), got err=%v", err)
897+
}
898+
899+
if !strings.Contains(stdout.String(), "whiteboard is empty") {
900+
t.Fatalf("stdout missing empty whiteboard message: %s", stdout.String())
901+
}
902+
}
903+
883904
func assertInvalidResponse(t *testing.T, err error) {
884905
t.Helper()
885906
if err == nil {

0 commit comments

Comments
 (0)