mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-12 08:00:05 +01:00
Fix install integration tests
This commit is contained in:
parent
a2cf8f6412
commit
f994e4644e
1 changed files with 21 additions and 19 deletions
|
|
@ -19,7 +19,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile"
|
"github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile"
|
||||||
|
|
@ -47,37 +46,40 @@ func TestInstallCommand(t *testing.T) {
|
||||||
ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "jsonnet-bundler", "source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "080f157c7fb85ad0281ea78f6c641eaa570a582f"}]}`),
|
ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "jsonnet-bundler", "source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "080f157c7fb85ad0281ea78f6c641eaa570a582f"}]}`),
|
||||||
}, {
|
}, {
|
||||||
Name: "Relative",
|
Name: "Relative",
|
||||||
URIs: []string{"test/jsonnet/foobar"},
|
URIs: []string{"jsonnet/foobar"},
|
||||||
ExpectedCode: 0,
|
ExpectedCode: 0,
|
||||||
ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "test/jsonnet/foobar"}}, "version": ""}]}`),
|
ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}]}`),
|
||||||
ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "test/jsonnet/foobar"}}, "version": ""}]}`),
|
ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}]}`),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localDependency := "jsonnet/foobar"
|
||||||
|
|
||||||
|
cleanup := func() {
|
||||||
|
os.Remove(jsonnetfile.File)
|
||||||
|
os.Remove(jsonnetfile.LockFile)
|
||||||
|
os.RemoveAll("vendor")
|
||||||
|
os.RemoveAll("jsonnet")
|
||||||
|
}
|
||||||
|
|
||||||
for _, tc := range testcases {
|
for _, tc := range testcases {
|
||||||
_ = t.Run(tc.Name, func(t *testing.T) {
|
_ = t.Run(tc.Name, func(t *testing.T) {
|
||||||
tempDir, err := ioutil.TempDir("", "jb-install")
|
cleanup()
|
||||||
assert.NoError(t, err)
|
|
||||||
err = os.MkdirAll(filepath.Join(tempDir, "test/jsonnet/foobar"), os.ModePerm)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
defer os.Remove(tempDir)
|
|
||||||
defer os.RemoveAll("vendor") // cloning jsonnet-bundler will create this folder
|
|
||||||
|
|
||||||
jsonnetFile := filepath.Join(tempDir, jsonnetfile.File)
|
os.MkdirAll(localDependency, os.ModePerm)
|
||||||
jsonnetLockFile := filepath.Join(tempDir, jsonnetfile.LockFile)
|
|
||||||
|
|
||||||
code := initCommand(tempDir)
|
initCommand("")
|
||||||
assert.Equal(t, 0, code)
|
|
||||||
|
|
||||||
jsonnetFileContent(t, jsonnetFile, []byte(`{}`))
|
jsonnetFileContent(t, jsonnetfile.File, []byte(`{}`))
|
||||||
|
|
||||||
code = installCommand(tempDir, "vendor", tc.URIs...)
|
installCommand("", "vendor", tc.URIs...)
|
||||||
assert.Equal(t, tc.ExpectedCode, code)
|
|
||||||
|
|
||||||
jsonnetFileContent(t, jsonnetFile, tc.ExpectedJsonnetFile)
|
jsonnetFileContent(t, jsonnetfile.File, tc.ExpectedJsonnetFile)
|
||||||
jsonnetFileContent(t, jsonnetLockFile, tc.ExpectedJsonnetLockFile)
|
jsonnetFileContent(t, jsonnetfile.LockFile, tc.ExpectedJsonnetLockFile)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func jsonnetFileContent(t *testing.T, filename string, content []byte) {
|
func jsonnetFileContent(t *testing.T, filename string, content []byte) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue