mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-12 08:00:05 +01:00
test: jsonnetfile marshalling
This commit is contained in:
parent
1caefa556e
commit
6e283c5310
4 changed files with 137 additions and 15 deletions
13
spec/spec.go
13
spec/spec.go
|
|
@ -19,14 +19,26 @@ import (
|
|||
"sort"
|
||||
)
|
||||
|
||||
// JsonnetFile is the structure of a `.json` file describing a set of jsonnet
|
||||
// dependencies. It is used for both, the jsonnetFile and the lockFile.
|
||||
type JsonnetFile struct {
|
||||
Dependencies map[string]Dependency
|
||||
}
|
||||
|
||||
// New returns a new JsonnetFile with the dependencies map initialized
|
||||
func New() JsonnetFile {
|
||||
return JsonnetFile{
|
||||
Dependencies: make(map[string]Dependency),
|
||||
}
|
||||
}
|
||||
|
||||
// jsonFile is the json representation of a JsonnetFile, which is different for
|
||||
// compatibility reasons.
|
||||
type jsonFile struct {
|
||||
Dependencies []Dependency `json:"dependencies"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON unmarshals a `jsonFile`'s json into a JsonnetFile
|
||||
func (jf *JsonnetFile) UnmarshalJSON(data []byte) error {
|
||||
var s jsonFile
|
||||
if err := json.Unmarshal(data, &s); err != nil {
|
||||
|
|
@ -40,6 +52,7 @@ func (jf *JsonnetFile) UnmarshalJSON(data []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON serializes a JsonnetFile into json of the format of a `jsonFile`
|
||||
func (jf JsonnetFile) MarshalJSON() ([]byte, error) {
|
||||
var s jsonFile
|
||||
for _, d := range jf.Dependencies {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue