1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2021 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package testutil_test
import (
"gopkg.in/check.v1"
. "github.com/snapcore/snapd/testutil"
)
type jsonCheckerSuite struct{}
var _ = check.Suite(&jsonCheckerSuite{})
func (*jsonCheckerSuite) TestFilePresent(c *check.C) {
testInfo(c, JsonEquals, "JsonEqual", []string{"obtained", "expected"})
type subRef struct {
Foo string `json:"foo"`
Baz []float32 `json:"baz"`
hidden bool
}
type ref struct {
Number int `json:"number"`
String string `json:"string,omitempty"`
List []string `json:"list"`
Map *subRef `json:"map,omitempty"`
hidden bool
}
testCheck(c, JsonEquals, true, "",
map[string]any{
"number": 42,
"string": "foo",
"list": []string{"123", "456"},
"map": map[string]any{
"foo": "bar",
"baz": []any{0.2, 0.3},
},
}, ref{
Number: 42,
String: "foo",
List: []string{"123", "456"},
Map: &subRef{
Foo: "bar",
Baz: []float32{0.2, 0.3},
// this is transparent to the checker
hidden: true,
},
// this is transparent to the checker
hidden: true,
})
testCheck(c, JsonEquals, true, "",
map[string]any{
"number": 42,
"string": "foo",
"list": []any(nil),
}, ref{
Number: 42,
String: "foo",
})
testCheck(c, JsonEquals, true, "",
map[string]any{
"number": 42,
"list": []any(nil),
}, ref{
Number: 42,
})
testCheck(c, JsonEquals, false, "", 12, "12")
testCheck(c, JsonEquals, false, "Difference:\n... [0]: 12 != 24\n", []int{12}, []int{24})
testCheck(c, JsonEquals, false, "Difference:\n... [0]: string != float64\n", []string{"abc"}, []int{24})
}
|