mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-11 23:50:05 +01:00
feat(spec): version field (#85)
Adds a `version` field to the `jsonnetfile.json`, so that `jb` can automatically recognize too old / too new schema versions, instead of panicking.
This commit is contained in:
parent
efe0c9e864
commit
bcd89fd33d
23 changed files with 454 additions and 102 deletions
|
|
@ -24,12 +24,11 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile"
|
||||
"github.com/jsonnet-bundler/jsonnet-bundler/spec"
|
||||
"github.com/jsonnet-bundler/jsonnet-bundler/spec/deps"
|
||||
v1 "github.com/jsonnet-bundler/jsonnet-bundler/spec/v1"
|
||||
"github.com/jsonnet-bundler/jsonnet-bundler/spec/v1/deps"
|
||||
)
|
||||
|
||||
// TODO: Change legacyImports to false eventually
|
||||
const initContents = `{"dependencies": [], "legacyImports": true}`
|
||||
const initContents = `{"version": 1, "dependencies": [], "legacyImports": false}`
|
||||
|
||||
func TestInstallCommand(t *testing.T) {
|
||||
testInstallCommandWithJsonnetHome(t, "vendor")
|
||||
|
|
@ -60,15 +59,15 @@ func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) {
|
|||
Name: "OneURL",
|
||||
URIs: []string{"github.com/jsonnet-bundler/jsonnet-bundler@v0.1.0"},
|
||||
ExpectedCode: 0,
|
||||
ExpectedJsonnetFile: []byte(`{"dependencies": [{"source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "v0.1.0"}], "legacyImports": true}`),
|
||||
ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "080f157c7fb85ad0281ea78f6c641eaa570a582f", "sum": "W1uI550rQ66axRpPXA2EZDquyPg/5PHZlvUz1NEzefg="}], "legacyImports": false}`),
|
||||
ExpectedJsonnetFile: []byte(`{"version": 1, "dependencies": [{"source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "v0.1.0"}], "legacyImports": false}`),
|
||||
ExpectedJsonnetLockFile: []byte(`{"version": 1, "dependencies": [{"source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "080f157c7fb85ad0281ea78f6c641eaa570a582f", "sum": "W1uI550rQ66axRpPXA2EZDquyPg/5PHZlvUz1NEzefg="}], "legacyImports": false}`),
|
||||
},
|
||||
{
|
||||
Name: "Local",
|
||||
URIs: []string{"jsonnet/foobar"},
|
||||
ExpectedCode: 0,
|
||||
ExpectedJsonnetFile: []byte(`{"dependencies": [{"source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}], "legacyImports": true}`),
|
||||
ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}], "legacyImports": false}`),
|
||||
ExpectedJsonnetFile: []byte(`{"version": 1, "dependencies": [{"source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}], "legacyImports": false}`),
|
||||
ExpectedJsonnetLockFile: []byte(`{"version": 1, "dependencies": [{"source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}], "legacyImports": false}`),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -118,19 +117,19 @@ func TestWriteChangedJsonnetFile(t *testing.T) {
|
|||
testcases := []struct {
|
||||
Name string
|
||||
JsonnetFileBytes []byte
|
||||
NewJsonnetFile spec.JsonnetFile
|
||||
NewJsonnetFile v1.JsonnetFile
|
||||
ExpectWrite bool
|
||||
}{
|
||||
{
|
||||
Name: "NoDiffEmpty",
|
||||
JsonnetFileBytes: []byte(`{}`),
|
||||
NewJsonnetFile: spec.New(),
|
||||
NewJsonnetFile: v1.New(),
|
||||
ExpectWrite: false,
|
||||
},
|
||||
{
|
||||
Name: "NoDiffNotEmpty",
|
||||
JsonnetFileBytes: []byte(`{"dependencies": [{"version": "master"}]}`),
|
||||
NewJsonnetFile: spec.JsonnetFile{
|
||||
NewJsonnetFile: v1.JsonnetFile{
|
||||
Dependencies: map[string]deps.Dependency{
|
||||
"": {
|
||||
Version: "master",
|
||||
|
|
@ -142,7 +141,7 @@ func TestWriteChangedJsonnetFile(t *testing.T) {
|
|||
{
|
||||
Name: "DiffVersion",
|
||||
JsonnetFileBytes: []byte(`{"dependencies": [{"version": "1.0"}]}`),
|
||||
NewJsonnetFile: spec.JsonnetFile{
|
||||
NewJsonnetFile: v1.JsonnetFile{
|
||||
Dependencies: map[string]deps.Dependency{
|
||||
"": {
|
||||
Version: "2.0",
|
||||
|
|
@ -154,7 +153,7 @@ func TestWriteChangedJsonnetFile(t *testing.T) {
|
|||
{
|
||||
Name: "Diff",
|
||||
JsonnetFileBytes: []byte(`{}`),
|
||||
NewJsonnetFile: spec.JsonnetFile{
|
||||
NewJsonnetFile: v1.JsonnetFile{
|
||||
Dependencies: map[string]deps.Dependency{
|
||||
"github.com/foobar/foobar": {
|
||||
Source: deps.Source{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue