@@ -41,32 +41,25 @@ func createTestApplyResult() sts.DashboardReadFullSchema {
4141
4242func TestShouldApplyDashboardCreate (t * testing.T ) {
4343 // Create a temporary file with dashboard JSON
44- file , err := os .CreateTemp (os .TempDir (), "test_dashboard_*.json " )
44+ file , err := os .CreateTemp (os .TempDir (), "test_dashboard_*.yaml " )
4545 if err != nil {
4646 panic (err )
4747 }
4848 defer os .Remove (file .Name ())
4949
50- dashboardJSON := `{
51- "name": "applied-dashboard",
52- "description": "Dashboard created via apply",
53- "scope": "publicDashboard",
54- "dashboard": {
55- "spec": {
56- "layouts": [
57- {
58- "kind": "Grid",
59- "spec": {
60- "items": []
61- }
62- }
63- ],
64- "panels": {}
65- }
66- }
67- }`
68-
69- _ , err = file .WriteString (dashboardJSON )
50+ dashboardYAML := `name: applied-dashboard
51+ description: Dashboard created via apply
52+ scope: publicDashboard
53+ dashboard:
54+ spec:
55+ layouts:
56+ - kind: Grid
57+ spec:
58+ items: []
59+ panels: {}
60+ `
61+
62+ _ , err = file .WriteString (dashboardYAML )
7063 assert .Nil (t , err )
7164 file .Close ()
7265
@@ -86,20 +79,19 @@ func TestShouldApplyDashboardCreate(t *testing.T) {
8679
8780func TestShouldApplyDashboardUpdate (t * testing.T ) {
8881 // Create a temporary file with dashboard update JSON (includes ID)
89- file , err := os .CreateTemp (os .TempDir (), "test_dashboard_*.json " )
82+ file , err := os .CreateTemp (os .TempDir (), "test_dashboard_*.yaml " )
9083 if err != nil {
9184 panic (err )
9285 }
9386 defer os .Remove (file .Name ())
9487
95- updateJSON := `{
96- "id": 1234,
97- "name": "updated-dashboard",
98- "description": "Updated dashboard description",
99- "scope": "privateDashboard"
100- }`
88+ updateYAML := `id: 1234
89+ name: updated-dashboard
90+ description: Updated dashboard description
91+ scope: privateDashboard
92+ `
10193
102- _ , err = file .WriteString (updateJSON )
94+ _ , err = file .WriteString (updateYAML )
10395 assert .Nil (t , err )
10496 file .Close ()
10597
@@ -125,25 +117,22 @@ func TestShouldApplyDashboardUpdate(t *testing.T) {
125117}
126118
127119func TestShouldApplyDashboardWithJson (t * testing.T ) {
128- file , err := os .CreateTemp (os .TempDir (), "test_dashboard_*.json " )
120+ file , err := os .CreateTemp (os .TempDir (), "test_dashboard_*.yaml " )
129121 if err != nil {
130122 panic (err )
131123 }
132124 defer os .Remove (file .Name ())
133125
134- dashboardJSON := `{
135- "name": "json-output-dashboard",
136- "description": "Dashboard for JSON output test",
137- "scope": "publicDashboard",
138- "dashboard": {
139- "spec": {
140- "layouts": [],
141- "panels": {}
142- }
143- }
144- }`
145-
146- _ , err = file .WriteString (dashboardJSON )
126+ dashboardYAML := `name: yaml-output-dashboard
127+ description: Dashboard for JSON output test
128+ scope: publicDashboard
129+ dashboard:
130+ spec:
131+ layouts: []
132+ panels: {}
133+ `
134+
135+ _ , err = file .WriteString (dashboardYAML )
147136 assert .Nil (t , err )
148137 file .Close ()
149138
@@ -174,28 +163,30 @@ func TestApplyDashboardInvalidFileType(t *testing.T) {
174163 _ , err = di .ExecuteCommandWithContext (& cli .Deps , cmd , "--file" , file .Name ())
175164
176165 assert .NotNil (t , err )
177- assert .Contains (t , err .Error (), "unsupported file type: .txt. Only .json files are supported" )
166+ assert .Contains (t , err .Error (), "unsupported file type: .txt. Only .yaml files are supported" )
178167}
179168
180169func TestApplyDashboardMissingFile (t * testing.T ) {
181170 cli , cmd := setDashboardApplyCmd (t )
182171
183- _ , err := di .ExecuteCommandWithContext (& cli .Deps , cmd , "--file" , "/nonexistent/file.json " )
172+ _ , err := di .ExecuteCommandWithContext (& cli .Deps , cmd , "--file" , "/nonexistent/file.yaml " )
184173
185174 assert .NotNil (t , err )
186175 assert .Contains (t , err .Error (), "cannot read file" )
187176}
188177
189178func TestApplyDashboardInvalidJSON (t * testing.T ) {
190- file , err := os .CreateTemp (os .TempDir (), "test_dashboard_*.json " )
179+ file , err := os .CreateTemp (os .TempDir (), "test_dashboard_*.yaml " )
191180 if err != nil {
192181 panic (err )
193182 }
194183 defer os .Remove (file .Name ())
195184
196- invalidJSON := `{"name": "test", "invalid": json}`
185+ invalidYAML := `name: test
186+ invalid yaml
187+ `
197188
198- _ , err = file .WriteString (invalidJSON )
189+ _ , err = file .WriteString (invalidYAML )
199190 assert .Nil (t , err )
200191 file .Close ()
201192
@@ -204,20 +195,19 @@ func TestApplyDashboardInvalidJSON(t *testing.T) {
204195 _ , err = di .ExecuteCommandWithContext (& cli .Deps , cmd , "--file" , file .Name ())
205196
206197 assert .NotNil (t , err )
207- assert .Contains (t , err .Error (), "failed to parse JSON " )
198+ assert .Contains (t , err .Error (), "failed to parse YAML " )
208199}
209200
210201func TestApplyDashboardMissingName (t * testing.T ) {
211- file , err := os .CreateTemp (os .TempDir (), "test_dashboard_*.json " )
202+ file , err := os .CreateTemp (os .TempDir (), "test_dashboard_*.yaml " )
212203 if err != nil {
213204 panic (err )
214205 }
215206 defer os .Remove (file .Name ())
216207
217- invalidDashboard := `{
218- "description": "Dashboard without name",
219- "scope": "publicDashboard"
220- }`
208+ invalidDashboard := `description: Dashboard without name
209+ scope: publicDashboard
210+ `
221211
222212 _ , err = file .WriteString (invalidDashboard )
223213 assert .Nil (t , err )
0 commit comments