@@ -10,8 +10,14 @@ import (
1010
1111func TestUpdateDescription (t * testing.T ) {
1212 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
13- if r .Method != http .MethodPost {
14- t .Errorf ("expected POST, got %s" , r .Method )
13+ if r .Method == http .MethodGet {
14+ propsJSON := `{"description":"old desc",` +
15+ `"created":{"actor":"urn:li:corpuser:admin","time":1000},` +
16+ `"lastModified":{"actor":"urn:li:corpuser:admin","time":2000}}`
17+ resp := aspectResponse {Value : json .RawMessage (propsJSON )}
18+ w .Header ().Set ("Content-Type" , "application/json" )
19+ _ = json .NewEncoder (w ).Encode (resp )
20+ return
1521 }
1622
1723 proposal , aspectJSON := extractProposalWireFormat (t , r .Body )
@@ -23,12 +29,18 @@ func TestUpdateDescription(t *testing.T) {
2329 t .Errorf ("expected aspect 'editableDatasetProperties', got %v" , proposal ["aspectName" ])
2430 }
2531
26- var aspectMap map [ string ] any
27- if err := json .Unmarshal ([]byte (aspectJSON ), & aspectMap ); err != nil {
32+ var props editablePropertiesAspect
33+ if err := json .Unmarshal ([]byte (aspectJSON ), & props ); err != nil {
2834 t .Fatalf ("failed to unmarshal inner aspect: %v" , err )
2935 }
30- if aspectMap ["description" ] != "new description" {
31- t .Errorf ("expected description 'new description', got %v" , aspectMap ["description" ])
36+ if props .Description != "new description" {
37+ t .Errorf ("expected 'new description', got %q" , props .Description )
38+ }
39+ if props .Created == nil || props .Created .Actor != "urn:li:corpuser:admin" {
40+ t .Error ("expected created audit stamp to be preserved" )
41+ }
42+ if props .LastModified == nil || props .LastModified .Time != 2000 {
43+ t .Error ("expected lastModified audit stamp to be preserved" )
3244 }
3345
3446 w .WriteHeader (http .StatusOK )
@@ -50,6 +62,102 @@ func TestUpdateDescription(t *testing.T) {
5062 }
5163}
5264
65+ func TestUpdateDescription_NoExistingProperties (t * testing.T ) {
66+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
67+ if r .Method == http .MethodGet {
68+ w .WriteHeader (http .StatusNotFound )
69+ return
70+ }
71+ _ , aspectJSON := extractProposalWireFormat (t , r .Body )
72+ var props editablePropertiesAspect
73+ if err := json .Unmarshal ([]byte (aspectJSON ), & props ); err != nil {
74+ t .Fatalf ("failed to unmarshal inner aspect: %v" , err )
75+ }
76+ if props .Description != "first description" {
77+ t .Errorf ("expected 'first description', got %q" , props .Description )
78+ }
79+ w .WriteHeader (http .StatusOK )
80+ }))
81+ defer server .Close ()
82+
83+ c := & Client {
84+ endpoint : server .URL + "/api/graphql" ,
85+ token : "test-token" ,
86+ httpClient : server .Client (),
87+ logger : NopLogger {},
88+ }
89+
90+ err := c .UpdateDescription (context .Background (),
91+ "urn:li:dataset:(urn:li:dataPlatform:hive,testdb.table,PROD)" ,
92+ "first description" )
93+ if err != nil {
94+ t .Fatalf ("unexpected error: %v" , err )
95+ }
96+ }
97+
98+ func TestUpdateDescription_MarkdownContent (t * testing.T ) {
99+ mdDesc := "## Overview\n \n **bold** and _italic_\n \n - item 1\n - item 2\n \n `code`"
100+
101+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
102+ if r .Method == http .MethodGet {
103+ propsJSON := `{"description":"old",` +
104+ `"created":{"actor":"urn:li:corpuser:datahub","time":0},` +
105+ `"lastModified":{"actor":"urn:li:corpuser:datahub","time":0}}`
106+ resp := aspectResponse {Value : json .RawMessage (propsJSON )}
107+ w .Header ().Set ("Content-Type" , "application/json" )
108+ _ = json .NewEncoder (w ).Encode (resp )
109+ return
110+ }
111+ _ , aspectJSON := extractProposalWireFormat (t , r .Body )
112+ var props editablePropertiesAspect
113+ if err := json .Unmarshal ([]byte (aspectJSON ), & props ); err != nil {
114+ t .Fatalf ("failed to unmarshal inner aspect: %v" , err )
115+ }
116+ if props .Description != mdDesc {
117+ t .Errorf ("markdown not preserved:\n got: %q\n want: %q" ,
118+ props .Description , mdDesc )
119+ }
120+ w .WriteHeader (http .StatusOK )
121+ }))
122+ defer server .Close ()
123+
124+ c := & Client {
125+ endpoint : server .URL + "/api/graphql" ,
126+ token : "test-token" ,
127+ httpClient : server .Client (),
128+ logger : NopLogger {},
129+ }
130+
131+ err := c .UpdateDescription (context .Background (),
132+ "urn:li:dataset:(urn:li:dataPlatform:hive,testdb.table,PROD)" ,
133+ mdDesc )
134+ if err != nil {
135+ t .Fatalf ("unexpected error: %v" , err )
136+ }
137+ }
138+
139+ func TestReadEditableProperties_InvalidJSON (t * testing.T ) {
140+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
141+ resp := aspectResponse {Value : json .RawMessage (`not valid json` )}
142+ w .Header ().Set ("Content-Type" , "application/json" )
143+ _ = json .NewEncoder (w ).Encode (resp )
144+ }))
145+ defer server .Close ()
146+
147+ c := & Client {
148+ endpoint : server .URL + "/api/graphql" ,
149+ token : "test-token" ,
150+ httpClient : server .Client (),
151+ logger : NopLogger {},
152+ }
153+
154+ _ , err := c .readEditableProperties (context .Background (),
155+ "urn:li:dataset:(urn:li:dataPlatform:hive,testdb.table,PROD)" )
156+ if err == nil {
157+ t .Fatal ("expected error for invalid JSON" )
158+ }
159+ }
160+
53161func TestUpdateDescription_InvalidURN (t * testing.T ) {
54162 c := & Client {logger : NopLogger {}}
55163 err := c .UpdateDescription (context .Background (), "not-a-urn" , "desc" )
0 commit comments