Control: tags -1 + patch
Please consider this backport of Canonical's already-merged
tests: fix json error assertions for Go 1.27
https://github.com/canonical/snapd/commit/d9bd57060dc92080989432219fabfae4726255f9
https://github.com/canonical/snapd/pull/17472
Verified with sbuild on unstable amd64, golang-1.27 1.27.1-2,
tests enabled, GOEXPERIMENT/GOFLAGS/GODEBUG unset.
The patch only relaxes JSON error assertions in six test files so
they match both Go 1.26 and Go 1.27 messages.
From d9bd57060dc92080989432219fabfae4726255f9 Mon Sep 17 00:00:00 2001
From: Anshul Singh <[email protected]>
Date: Wed, 19 Aug 2026 00:05:55 +0900
Subject: tests: fix json error assertions for Go 1.27
Origin: upstream, https://github.com/canonical/snapd/commit/d9bd57060dc92080989432219fabfae4726255f9
Bug-Debian: https://bugs.debian.org/1146230
Forwarded: not-needed
Go 1.27's encoding/json changed several error message formats:
- unmarshal type errors drop the 'Go struct field <T>'/'Go value'
type prefix ('cannot unmarshal number into Go struct field ...' ->
'cannot unmarshal number into .path of type ...')
- syntax errors drop the 'literal' suffix ('in string literal' ->
'in string')
- invalid escape errors are reworded ('invalid character ... in
string escape code' / 'in \u hexadecimal character escape' ->
'invalid escape sequence ... in string')
- base64 errors are now wrapped
Relax the affected test assertions so they match both the Go 1.26
and Go 1.27 message formats (verified against go1.26.5 and
go1.27rc3).
---
daemon/api_prompting_test.go | 2 +-
interfaces/prompting/patterns/patterns_test.go | 2 +-
jsonutil/safejson/safejson_test.go | 10 +++++-----
overlord/devicestate/devicestate_test.go | 2 +-
overlord/install/install_test.go | 6 +++---
usersession/client/client_test.go | 2 +-
6 files changed, 12 insertions(+), 12 deletions(-)
Index: snapd-2.76.3/daemon/api_prompting_test.go
===================================================================
--- snapd-2.76.3.orig/daemon/api_prompting_test.go
+++ snapd-2.76.3/daemon/api_prompting_test.go
@@ -1305,7 +1305,7 @@ func (s *promptingSuite) TestPostPromptE
rspe = s.errorReq(c, req, nil, actionIsExpected)
c.Check(rspe.Status, Equals, 400)
c.Check(rspe.Kind, Equals, client.ErrorKind(""))
- c.Check(rspe.Message, Matches, "cannot decode request body into prompt reply:.*cannot unmarshal number into Go struct field.*")
+ c.Check(rspe.Message, Matches, "cannot decode request body into prompt reply:.*cannot unmarshal number into.*")
// Invalid outcome (action) or lifespan
for _, testCase := range []struct {
Index: snapd-2.76.3/interfaces/prompting/patterns/patterns_test.go
===================================================================
--- snapd-2.76.3.orig/interfaces/prompting/patterns/patterns_test.go
+++ snapd-2.76.3/interfaces/prompting/patterns/patterns_test.go
@@ -376,7 +376,7 @@ func (s *patternsSuite) TestPathPatternU
},
{
[]byte{'"', 0x00, '"'},
- `invalid character '\\x00' in string literal`,
+ `invalid character '\\x00' in string.*`,
},
} {
pathPattern := patterns.PathPattern{}
Index: snapd-2.76.3/jsonutil/safejson/safejson_test.go
===================================================================
--- snapd-2.76.3.orig/jsonutil/safejson/safejson_test.go
+++ snapd-2.76.3/jsonutil/safejson/safejson_test.go
@@ -86,11 +86,11 @@ func (escapeSuite) TestBadStrings(c *che
table := map[string][][]byte{
// these are from json itself (so we're not checking them):
- "invalid character '.+' in string literal": cc0,
- "invalid character '.+' in string escape code": badesc,
- `invalid character '.+' in \\u .*`: {[]byte(`"\u02"`), []byte(`"\u02zz"`)},
- "invalid character '\"' after top-level value": {[]byte(`"""`)},
- "unexpected end of JSON input": {[]byte(`"\"`)},
+ "invalid character '.+' in string.*": cc0,
+ "(invalid character '.+' in string escape code|invalid escape sequence .+ in string)": badesc,
+ `(invalid character '.+' in \\u hexadecimal character escape|invalid escape sequence .+ in string)`: {[]byte(`"\u02"`), []byte(`"\u02zz"`)},
+ "invalid character '\"' after top-level value": {[]byte(`"""`)},
+ "unexpected end of JSON input": {[]byte(`"\"`)},
}
for e, js := range table {
Index: snapd-2.76.3/overlord/devicestate/devicestate_test.go
===================================================================
--- snapd-2.76.3.orig/overlord/devicestate/devicestate_test.go
+++ snapd-2.76.3/overlord/devicestate/devicestate_test.go
@@ -2073,7 +2073,7 @@ func (s *deviceMgrSuite) TestRunFDESetup
st.Lock()
_, err := devicestate.DeviceManagerRunFDESetupHook(s.mgr, req)
st.Unlock()
- c.Assert(err, ErrorMatches, `cannot get result from fde-setup hook "op": cannot unmarshal context value for "fde-setup-result": illegal base64 data at input byte 3`)
+ c.Assert(err, ErrorMatches, `cannot get result from fde-setup hook "op": cannot unmarshal context value for "fde-setup-result": .*illegal base64 data at input byte 3`)
}
type startOfOperationTimeSuite struct {
Index: snapd-2.76.3/overlord/install/install_test.go
===================================================================
--- snapd-2.76.3.orig/overlord/install/install_test.go
+++ snapd-2.76.3/overlord/install/install_test.go
@@ -1580,9 +1580,9 @@ func (s *installSuite) TestInstallCheckE
{`{"features":["a"]}`, "", device.EncryptionTypeLUKS},
{`{"features":["a","b"]}`, "", device.EncryptionTypeLUKS},
// features must be list of strings
- {`{"features":[1]}`, `cannot parse hook output ".*": json: cannot unmarshal number into Go struct.*`, device.EncryptionTypeNone},
- {`{"features":1}`, `cannot parse hook output ".*": json: cannot unmarshal number into Go struct.*`, device.EncryptionTypeNone},
- {`{"features":"1"}`, `cannot parse hook output ".*": json: cannot unmarshal string into Go struct.*`, device.EncryptionTypeNone},
+ {`{"features":[1]}`, `cannot parse hook output ".*": json: cannot unmarshal number into.*`, device.EncryptionTypeNone},
+ {`{"features":1}`, `cannot parse hook output ".*": json: cannot unmarshal number into.*`, device.EncryptionTypeNone},
+ {`{"features":"1"}`, `cannot parse hook output ".*": json: cannot unmarshal string into.*`, device.EncryptionTypeNone},
// valid and uses ice
{`{"features":["a","inline-crypto-engine","b"]}`, "", device.EncryptionTypeLUKSWithICE},
} {
Index: snapd-2.76.3/usersession/client/client_test.go
===================================================================
--- snapd-2.76.3.orig/usersession/client/client_test.go
+++ snapd-2.76.3/usersession/client/client_test.go
@@ -665,7 +665,7 @@ func (s *clientSuite) TestServiceStatusW
})
_, failures, err := s.cli.ServiceStatus(context.Background(), []string{"snap.foo.service"})
c.Check(failures, DeepEquals, map[int][]client.ServiceFailure{})
- c.Check(err, ErrorMatches, `json: cannot unmarshal string into Go value of type client.ServiceUnitStatus`)
+ c.Check(err, ErrorMatches, `json: cannot unmarshal string into .* of type client.ServiceUnitStatus`)
}
func (s *clientSuite) TestServiceStatusFailure(c *C) {