| 
									
										
										
										
											2024-11-21 13:53:25 +08:00
										 |  |  | package resource | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							|  |  |  | 	"encoding/json" | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							|  |  |  | 	"os" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/stretchr/testify/require" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestStandardDocumentBuilder(t *testing.T) { | 
					
						
							|  |  |  | 	ctx := context.Background() | 
					
						
							| 
									
										
										
										
											2024-11-22 21:44:06 +08:00
										 |  |  | 	builder := StandardDocumentBuilder() | 
					
						
							| 
									
										
										
										
											2024-11-21 13:53:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	body, err := os.ReadFile("testdata/playlist-resource.json") | 
					
						
							|  |  |  | 	require.NoError(t, err) | 
					
						
							|  |  |  | 	doc, err := builder.BuildDocument(ctx, &ResourceKey{ | 
					
						
							|  |  |  | 		Namespace: "default", | 
					
						
							|  |  |  | 		Group:     "playlists.grafana.app", | 
					
						
							|  |  |  | 		Resource:  "playlists", | 
					
						
							|  |  |  | 		Name:      "test1", | 
					
						
							|  |  |  | 	}, 10, body) | 
					
						
							|  |  |  | 	require.NoError(t, err) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	jj, _ := json.MarshalIndent(doc, "", "  ") | 
					
						
							|  |  |  | 	fmt.Printf("%s\n", string(jj)) | 
					
						
							|  |  |  | 	require.JSONEq(t, `{ | 
					
						
							|  |  |  | 		"key": { | 
					
						
							|  |  |  | 			"namespace": "default", | 
					
						
							|  |  |  | 			"group": "playlists.grafana.app", | 
					
						
							|  |  |  | 			"resource": "playlists", | 
					
						
							|  |  |  | 			"name": "test1" | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		"rv": 10, | 
					
						
							| 
									
										
										
										
											2024-12-20 02:21:48 +08:00
										 |  |  | 		"title": "test playlist unified storage", | 
					
						
							| 
									
										
										
										
											2025-01-30 06:31:59 +08:00
										 |  |  | 		"title_phrase": "test playlist unified storage", | 
					
						
							| 
									
										
										
										
											2024-11-21 13:53:25 +08:00
										 |  |  | 		"created": 1717236672000, | 
					
						
							|  |  |  | 		"createdBy": "user:ABC", | 
					
						
							|  |  |  | 		"updatedBy": "user:XYZ", | 
					
						
							| 
									
										
										
										
											2025-01-10 05:45:04 +08:00
										 |  |  | 		"name": "test1", | 
					
						
							| 
									
										
										
										
											2025-01-11 02:27:10 +08:00
										 |  |  | 		"repo": { | 
					
						
							| 
									
										
										
										
											2025-01-21 17:38:14 +08:00
										 |  |  | 			"name": "something", | 
					
						
							|  |  |  | 			"path": "path/in/system.json", | 
					
						
							| 
									
										
										
										
											2024-11-21 13:53:25 +08:00
										 |  |  | 			"hash": "xyz" | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-12-20 02:21:48 +08:00
										 |  |  | 		}`, string(jj)) | 
					
						
							| 
									
										
										
										
											2024-11-21 13:53:25 +08:00
										 |  |  | } |