test: jsonnetfile marshalling

This commit is contained in:
sh0rez 2019-10-29 22:09:03 +01:00
parent 1caefa556e
commit 6e283c5310
No known key found for this signature in database
GPG key ID: 87C71DF9F8181FF1
4 changed files with 137 additions and 15 deletions

View file

@ -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) {

View file

@ -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: "",
}},
}
{