mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-11 23:50:05 +01:00
test: jsonnetfile marshalling
This commit is contained in:
parent
1caefa556e
commit
6e283c5310
4 changed files with 137 additions and 15 deletions
|
|
@ -18,7 +18,6 @@ import (
|
|||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
|
|
@ -32,9 +31,9 @@ const (
|
|||
|
||||
var ErrNoFile = errors.New("no jsonnetfile")
|
||||
|
||||
|
||||
// Load reads a jsonnetfile.(lock).json from disk
|
||||
func Load(filepath string) (spec.JsonnetFile, error) {
|
||||
m := spec.JsonnetFile{}
|
||||
m := spec.New()
|
||||
|
||||
bytes, err := ioutil.ReadFile(filepath)
|
||||
if err != nil {
|
||||
|
|
@ -51,6 +50,7 @@ func Load(filepath string) (spec.JsonnetFile, error) {
|
|||
return m, nil
|
||||
}
|
||||
|
||||
// Exists returns whether the file at the given path exists
|
||||
func Exists(path string) (bool, error) {
|
||||
_, err := os.Stat(path)
|
||||
if os.IsNotExist(err) {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -30,7 +29,7 @@ import (
|
|||
const notExist = "/this/does/not/exist"
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
empty := spec.JsonnetFile{}
|
||||
empty := spec.New()
|
||||
|
||||
jsonnetfileContent := `{
|
||||
"dependencies": [
|
||||
|
|
@ -48,17 +47,18 @@ func TestLoad(t *testing.T) {
|
|||
}
|
||||
`
|
||||
jsonnetFileExpected := spec.JsonnetFile{
|
||||
Dependencies: []spec.Dependency{{
|
||||
Name: "foobar",
|
||||
Source: spec.Source{
|
||||
GitSource: &spec.GitSource{
|
||||
Remote: "https://github.com/foobar/foobar",
|
||||
Subdir: "",
|
||||
Dependencies: map[string]spec.Dependency{
|
||||
"foobar": {
|
||||
Name: "foobar",
|
||||
Source: spec.Source{
|
||||
GitSource: &spec.GitSource{
|
||||
Remote: "https://github.com/foobar/foobar",
|
||||
Subdir: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
Version: "master",
|
||||
DepSource: "",
|
||||
}},
|
||||
Version: "master",
|
||||
DepSource: "",
|
||||
}},
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue