mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
Add caps.Type.MarshalJSON()
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
package caps
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
@@ -68,3 +69,8 @@ func (t *Type) Validate(c *Capability) error {
|
||||
|
||||
// TypeLookupFn aids in looking up a Type by name
|
||||
type TypeLookupFn func(name string) *Type
|
||||
|
||||
// MarshalJSON encodes a Type object as the name of the type.
|
||||
func (t *Type) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(t.Name)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package caps
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
. "gopkg.in/check.v1"
|
||||
@@ -62,3 +63,9 @@ func (s *TypeSuite) TestValidateAttributes(c *C) {
|
||||
err := testType.Validate(cap)
|
||||
c.Assert(err, ErrorMatches, "attributes must be empty for now")
|
||||
}
|
||||
|
||||
func (s *TypeSuite) TestMarhshalJSON(c *C) {
|
||||
b, err := json.Marshal(testType)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(b, DeepEquals, []byte(`"test"`))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user