• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

shogo82148 / cfn-mackerel-macro / 25243787820

02 May 2026 04:30AM UTC coverage: 56.566% (+0.05%) from 56.515%
25243787820

Pull #571

github

shogo82148
go mod tidy
Pull Request #571: bump Go 1.26.2

78 of 124 new or added lines in 23 files covered. (62.9%)

2 existing lines in 1 file now uncovered.

2201 of 3891 relevant lines covered (56.57%)

4.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.8
/dproxy/value.go
1
package dproxy
2

3
import (
4
        "math"
5
        "strconv"
6
)
7

8
type valueProxy struct {
9
        value  any
10
        parent frame
11
        label  string
12
}
13

14
// valueProxy implements Proxy.
15
var _ Proxy = (*valueProxy)(nil)
16

17
func (p *valueProxy) Nil() bool {
×
18
        return p.value == nil
×
19
}
×
20

21
func (p *valueProxy) Value() (any, error) {
21✔
22
        return p.value, nil
21✔
23
}
21✔
24

25
func (p *valueProxy) Bool() (bool, error) {
30✔
26
        switch v := p.value.(type) {
30✔
27
        case bool:
6✔
28
                return v, nil
6✔
29
        case int:
2✔
30
                return v != 0, nil
2✔
31
        case int8:
2✔
32
                return v != 0, nil
2✔
33
        case int16:
2✔
34
                return v != 0, nil
2✔
35
        case int32:
2✔
36
                return v != 0, nil
2✔
37
        case int64:
2✔
38
                return v != 0, nil
2✔
39
        case uint:
2✔
40
                return v != 0, nil
2✔
41
        case uint8:
2✔
42
                return v != 0, nil
2✔
43
        case uint16:
2✔
44
                return v != 0, nil
2✔
45
        case uint32:
2✔
46
                return v != 0, nil
2✔
47
        case uint64:
2✔
48
                return v != 0, nil
2✔
49
        case string:
3✔
50
                w, err := strconv.ParseBool(v)
3✔
51
                if err != nil {
4✔
52
                        return false, &errorProxy{
1✔
53
                                errorCode: ErrorCodeConvertFailure,
1✔
54
                                parent:    p,
1✔
55
                                infoStr:   err.Error(),
1✔
56
                        }
1✔
57
                }
1✔
58
                return w, nil
2✔
59
        default:
1✔
60
                return false, typeError(p, Tbool, v)
1✔
61
        }
62
}
63

64
func (p *valueProxy) OptionalBool() (*bool, error) {
×
65
        v, err := p.Bool()
×
66
        if err, ok := err.(Error); ok && err.ErrorCode() == ErrorCodeNotFound {
×
67
                return nil, nil
×
68
        }
×
69
        if err != nil {
×
70
                return nil, err
×
71
        }
×
72
        return &v, nil
×
73
}
74

75
type int64er interface {
76
        Int64() (int64, error)
77
}
78

79
func (p *valueProxy) Int64() (int64, error) {
25✔
80
        switch v := p.value.(type) {
25✔
81
        case int:
2✔
82
                return int64(v), nil
2✔
83
        case int8:
2✔
84
                return int64(v), nil
2✔
85
        case int16:
2✔
86
                return int64(v), nil
2✔
87
        case int32:
2✔
88
                return int64(v), nil
2✔
89
        case int64:
2✔
90
                return v, nil
2✔
91
        case float32:
2✔
92
                if v < -(1<<63) || v >= 1<<63 {
4✔
93
                        return 0, &errorProxy{
2✔
94
                                errorCode: ErrorCodeConvertFailure,
2✔
95
                                parent:    p,
2✔
96
                                infoStr:   "overflow",
2✔
97
                        }
2✔
98
                }
2✔
99
                return int64(v), nil
×
100
        case float64:
3✔
101
                if v < -(1<<63) || v >= 1<<63 {
5✔
102
                        return 0, &errorProxy{
2✔
103
                                errorCode: ErrorCodeConvertFailure,
2✔
104
                                parent:    p,
2✔
105
                                infoStr:   "overflow",
2✔
106
                        }
2✔
107
                }
2✔
108
                return int64(v), nil
1✔
109
        case uint:
1✔
110
                return int64(v), nil
1✔
111
        case uint8:
1✔
112
                return int64(v), nil
1✔
113
        case uint16:
1✔
114
                return int64(v), nil
1✔
115
        case uint32:
1✔
116
                return int64(v), nil
1✔
117
        case uint64:
2✔
118
                if v > math.MaxInt64 {
3✔
119
                        return 0, &errorProxy{
1✔
120
                                errorCode: ErrorCodeConvertFailure,
1✔
121
                                parent:    p,
1✔
122
                                infoStr:   "overflow",
1✔
123
                        }
1✔
124
                }
1✔
125
                return int64(v), nil
1✔
126
        case int64er:
×
127
                w, err := v.Int64()
×
128
                if err != nil {
×
129
                        return 0, &errorProxy{
×
130
                                errorCode: ErrorCodeConvertFailure,
×
131
                                parent:    p,
×
132
                                infoStr:   err.Error(),
×
133
                        }
×
134
                }
×
135
                return w, nil
×
136
        case string:
3✔
137
                w, err := strconv.ParseInt(v, 10, 64)
3✔
138
                if err != nil {
4✔
139
                        return 0, &errorProxy{
1✔
140
                                errorCode: ErrorCodeConvertFailure,
1✔
141
                                parent:    p,
1✔
142
                                infoStr:   err.Error(),
1✔
143
                        }
1✔
144
                }
1✔
145
                return w, nil
2✔
146
        default:
1✔
147
                return 0, typeError(p, Tint64, v)
1✔
148
        }
149
}
150

151
func (p *valueProxy) OptionalInt64() (*int64, error) {
×
152
        if IsError(p, ErrorCodeNotFound) {
×
153
                return nil, nil
×
154
        }
×
155
        v, err := p.Int64()
×
156
        if err != nil {
×
157
                return nil, err
×
158
        }
×
159
        return &v, nil
×
160
}
161

162
type uint64er interface {
163
        Uint64() (uint64, error)
164
}
165

166
func (p *valueProxy) Uint64() (uint64, error) {
22✔
167
        switch v := p.value.(type) {
22✔
168
        case int:
2✔
169
                if v < 0 {
3✔
170
                        return 0, &errorProxy{
1✔
171
                                errorCode: ErrorCodeConvertFailure,
1✔
172
                                parent:    p,
1✔
173
                                infoStr:   "overflow",
1✔
174
                        }
1✔
175
                }
1✔
176
                return uint64(v), nil
1✔
177
        case int8:
2✔
178
                if v < 0 {
3✔
179
                        return 0, &errorProxy{
1✔
180
                                errorCode: ErrorCodeConvertFailure,
1✔
181
                                parent:    p,
1✔
182
                                infoStr:   "overflow",
1✔
183
                        }
1✔
184
                }
1✔
185
                return uint64(v), nil
1✔
186
        case int16:
2✔
187
                if v < 0 {
3✔
188
                        return 0, &errorProxy{
1✔
189
                                errorCode: ErrorCodeConvertFailure,
1✔
190
                                parent:    p,
1✔
191
                                infoStr:   "overflow",
1✔
192
                        }
1✔
193
                }
1✔
194
                return uint64(v), nil
1✔
195
        case int32:
2✔
196
                if v < 0 {
3✔
197
                        return 0, &errorProxy{
1✔
198
                                errorCode: ErrorCodeConvertFailure,
1✔
199
                                parent:    p,
1✔
200
                                infoStr:   "overflow",
1✔
201
                        }
1✔
202
                }
1✔
203
                return uint64(v), nil
1✔
204
        case int64:
2✔
205
                if v < 0 {
3✔
206
                        return 0, &errorProxy{
1✔
207
                                errorCode: ErrorCodeConvertFailure,
1✔
208
                                parent:    p,
1✔
209
                                infoStr:   "overflow",
1✔
210
                        }
1✔
211
                }
1✔
212
                return uint64(v), nil
1✔
213
        case float32:
×
214
                if v < 0 || v >= 1<<64 {
×
215
                        return 0, &errorProxy{
×
216
                                errorCode: ErrorCodeConvertFailure,
×
217
                                parent:    p,
×
218
                                infoStr:   "overflow",
×
219
                        }
×
220
                }
×
221
                return uint64(v), nil
×
222
        case float64:
3✔
223
                if v < 0 || v >= 1<<64 {
5✔
224
                        return 0, &errorProxy{
2✔
225
                                errorCode: ErrorCodeConvertFailure,
2✔
226
                                parent:    p,
2✔
227
                                infoStr:   "overflow",
2✔
228
                        }
2✔
229
                }
2✔
230
                return uint64(v), nil
1✔
231
        case uint:
1✔
232
                return uint64(v), nil
1✔
233
        case uint8:
1✔
234
                return uint64(v), nil
1✔
235
        case uint16:
1✔
236
                return uint64(v), nil
1✔
237
        case uint32:
1✔
238
                return uint64(v), nil
1✔
239
        case uint64:
1✔
240
                return uint64(v), nil
1✔
241
        case uint64er:
×
242
                w, err := v.Uint64()
×
243
                if err != nil {
×
244
                        return 0, &errorProxy{
×
245
                                errorCode: ErrorCodeConvertFailure,
×
246
                                parent:    p,
×
247
                                infoStr:   err.Error(),
×
248
                        }
×
249
                }
×
250
                return w, nil
×
251
        case string:
3✔
252
                w, err := strconv.ParseUint(v, 10, 64)
3✔
253
                if err != nil {
5✔
254
                        return 0, &errorProxy{
2✔
255
                                errorCode: ErrorCodeConvertFailure,
2✔
256
                                parent:    p,
2✔
257
                                infoStr:   err.Error(),
2✔
258
                        }
2✔
259
                }
2✔
260
                return w, nil
1✔
261
        default:
1✔
262
                return 0, typeError(p, Tint64, v)
1✔
263
        }
264
}
265

266
func (p *valueProxy) OptionalUint64() (*uint64, error) {
×
267
        if IsError(p, ErrorCodeNotFound) {
×
268
                return nil, nil
×
269
        }
×
270
        v, err := p.Uint64()
×
271
        if err != nil {
×
272
                return nil, err
×
273
        }
×
274
        return &v, nil
×
275
}
276

277
type float64er interface {
278
        Float64() (float64, error)
279
}
280

281
func (p *valueProxy) Float64() (float64, error) {
2✔
282
        switch v := p.value.(type) {
2✔
283
        case int:
×
284
                return float64(v), nil
×
285
        case int32:
×
286
                return float64(v), nil
×
287
        case int64:
×
288
                return float64(v), nil
×
289
        case float32:
×
290
                return float64(v), nil
×
291
        case float64:
1✔
292
                return v, nil
1✔
293
        case float64er:
×
294
                w, err := v.Float64()
×
295
                if err != nil {
×
296
                        return 0, &errorProxy{
×
297
                                errorCode: ErrorCodeConvertFailure,
×
298
                                parent:    p,
×
299
                                infoStr:   err.Error(),
×
300
                        }
×
301
                }
×
302
                return w, nil
×
303
        case uint:
×
304
                return float64(v), nil
×
305
        case uint32:
×
306
                return float64(v), nil
×
307
        case uint64:
×
308
                if v > math.MaxInt64 {
×
309
                        return 0, &errorProxy{
×
310
                                errorCode: ErrorCodeConvertFailure,
×
311
                                parent:    p,
×
312
                                infoStr:   "overflow",
×
313
                        }
×
314
                }
×
315
                return float64(v), nil
×
316
        case int64er:
×
317
                w, err := v.Int64()
×
318
                if err != nil {
×
319
                        return 0, &errorProxy{
×
320
                                errorCode: ErrorCodeConvertFailure,
×
321
                                parent:    p,
×
322
                                infoStr:   err.Error(),
×
323
                        }
×
324
                }
×
325
                return float64(w), nil
×
326
        case string:
1✔
327
                w, err := strconv.ParseFloat(v, 64)
1✔
328
                if err != nil {
2✔
329
                        return 0, &errorProxy{
1✔
330
                                errorCode: ErrorCodeConvertFailure,
1✔
331
                                parent:    p,
1✔
332
                                infoStr:   err.Error(),
1✔
333
                        }
1✔
334
                }
1✔
335
                return w, nil
×
336
        default:
×
337
                return 0, typeError(p, Tfloat64, v)
×
338
        }
339
}
340

341
func (p *valueProxy) OptionalFloat64() (*float64, error) {
×
342
        if IsError(p, ErrorCodeNotFound) {
×
343
                return nil, nil
×
344
        }
×
345
        v, err := p.Float64()
×
346
        if err != nil {
×
347
                return nil, err
×
348
        }
×
349
        return &v, nil
×
350
}
351

352
func (p *valueProxy) String() (string, error) {
2✔
353
        switch v := p.value.(type) {
2✔
354
        case string:
2✔
355
                return v, nil
2✔
356
        default:
×
357
                return "", typeError(p, Tstring, v)
×
358
        }
359
}
360

361
func (p *valueProxy) OptionalString() (*string, error) {
×
362
        if IsError(p, ErrorCodeNotFound) {
×
363
                return nil, nil
×
364
        }
×
365
        v, err := p.String()
×
366
        if err != nil {
×
367
                return nil, err
×
368
        }
×
369
        return &v, nil
×
370
}
371

NEW
372
func (p *valueProxy) Array() ([]any, error) {
×
373
        switch v := p.value.(type) {
×
NEW
374
        case []any:
×
375
                return v, nil
×
376
        default:
×
377
                return nil, typeError(p, Tarray, v)
×
378
        }
379
}
380

NEW
381
func (p *valueProxy) Map() (map[string]any, error) {
×
382
        switch v := p.value.(type) {
×
NEW
383
        case map[string]any:
×
384
                return v, nil
×
385
        default:
×
386
                return nil, typeError(p, Tmap, v)
×
387
        }
388
}
389

390
func (p *valueProxy) A(n int) Proxy {
11✔
391
        switch v := p.value.(type) {
11✔
392
        case []any:
11✔
393
                a := "[" + strconv.Itoa(n) + "]"
11✔
394
                if n < 0 || n >= len(v) {
11✔
395
                        return notfoundError(p, a)
×
396
                }
×
397
                return &valueProxy{
11✔
398
                        value:  v[n],
11✔
399
                        parent: p,
11✔
400
                        label:  a,
11✔
401
                }
11✔
402
        default:
×
403
                return typeError(p, Tarray, v)
×
404
        }
405
}
406

407
func (p *valueProxy) M(k string) Proxy {
37✔
408
        switch v := p.value.(type) {
37✔
409
        case map[string]any:
37✔
410
                a := "." + k
37✔
411
                w, ok := v[k]
37✔
412
                if !ok {
44✔
413
                        return notfoundError(p, a)
7✔
414
                }
7✔
415
                return &valueProxy{
30✔
416
                        value:  w,
30✔
417
                        parent: p,
30✔
418
                        label:  a,
30✔
419
                }
30✔
420
        default:
×
421
                return typeError(p, Tmap, v)
×
422
        }
423
}
424

425
func (p *valueProxy) P(q string) Proxy {
×
426
        return pointer(p, q)
×
427
}
×
428

429
func (p *valueProxy) ProxySet() ProxySet {
1✔
430
        switch v := p.value.(type) {
1✔
431
        case []any:
1✔
432
                return &setProxy{
1✔
433
                        values: v,
1✔
434
                        parent: p,
1✔
435
                }
1✔
436
        default:
×
437
                return typeError(p, Tarray, v)
×
438
        }
439
}
440

441
func (p *valueProxy) Q(k string) ProxySet {
2✔
442
        w := findAll(p.value, k)
2✔
443
        return &setProxy{
2✔
444
                values: w,
2✔
445
                parent: p,
2✔
446
                label:  ".." + k,
2✔
447
        }
2✔
448
}
2✔
449

450
func (p *valueProxy) findJPT(t string) Proxy {
27✔
451
        switch v := p.value.(type) {
27✔
452
        case map[string]any:
20✔
453
                return p.M(t)
20✔
454
        case []any:
7✔
455
                n, err := strconv.ParseUint(t, 10, 0)
7✔
456
                if err != nil {
7✔
457
                        return &errorProxy{
×
458
                                errorCode: ErrorCodeInvalidIndex,
×
459
                                parent:    p,
×
460
                                infoStr:   err.Error(),
×
461
                        }
×
462
                }
×
463
                return p.A(int(n))
7✔
464
        default:
×
465
                return &errorProxy{
×
466
                        errorCode: ErrorCodeMapNorArray,
×
467
                        parent:    p,
×
468
                        actual:    detectType(v),
×
469
                }
×
470
        }
471
}
472

473
func (p *valueProxy) parentFrame() frame {
8✔
474
        return p.parent
8✔
475
}
8✔
476

477
func (p *valueProxy) frameLabel() string {
12✔
478
        return p.label
12✔
479
}
12✔
480

481
// Default return the v as default value, if p is not found error.
NEW
482
func Default(p Proxy, v any) Proxy {
×
483
        if err, ok := p.(Error); ok && err.ErrorCode() == ErrorCodeNotFound {
×
484
                return New(v)
×
485
        }
×
486
        return p
×
487
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc