зеркало из https://github.com/golang/dep.git
Converting analyzer_test.go to golden-file pattern
This commit is contained in:
Родитель
45bfd674ea
Коммит
026ac7fd1c
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"github.com/pkg/errors": {
|
||||
"version": ">=0.8.0, <1.0.0"
|
||||
},
|
||||
"github.com/sdboyer/gps": {
|
||||
"version": ">=0.12.0, <1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,34 +9,21 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/dep/test"
|
||||
)
|
||||
|
||||
func TestDeriveManifestAndLock(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "dep")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
h := test.NewHelper(t)
|
||||
defer h.Cleanup()
|
||||
|
||||
contents := `{
|
||||
"dependencies": {
|
||||
"github.com/pkg/errors": {
|
||||
"version": ">=0.8.0, <1.0.0"
|
||||
},
|
||||
"github.com/sdboyer/gps": {
|
||||
"version": ">=0.12.0, <1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
if err := ioutil.WriteFile(filepath.Join(dir, ManifestName), []byte(contents), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h.TempDir("dep")
|
||||
contents := h.GetTestFileString("analyzer/manifest.json")
|
||||
h.TempCopy(filepath.Join("dep", ManifestName), "analyzer/manifest.json")
|
||||
|
||||
a := analyzer{}
|
||||
|
||||
m, l, err := a.DeriveManifestAndLock(dir, "my/fake/project")
|
||||
m, l, err := a.DeriveManifestAndLock(h.Path("dep"), "my/fake/project")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -46,7 +33,8 @@ func TestDeriveManifestAndLock(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if (string(b)) != contents {
|
||||
if exp, err := test.AreEqualJSON(contents, string(b)); !exp {
|
||||
h.Must(err)
|
||||
t.Fatalf("expected %s\n got %s", contents, string(b))
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ import (
|
|||
|
||||
func TestReadLock(t *testing.T) {
|
||||
h := test.NewHelper(t)
|
||||
defer h.Cleanup()
|
||||
|
||||
_, err := readLock(h.GetTestFileReader("lock/error.json"))
|
||||
if err == nil {
|
||||
t.Error("Reading lock with invalid props should have caused error, but did not")
|
||||
|
@ -47,6 +49,8 @@ func TestReadLock(t *testing.T) {
|
|||
|
||||
func TestWriteLock(t *testing.T) {
|
||||
h := test.NewHelper(t)
|
||||
defer h.Cleanup()
|
||||
|
||||
lg := h.GetTestFileString("lock/golden.json")
|
||||
memo, _ := hex.DecodeString("2252a285ab27944a4d7adcba8dbd03980f59ba652f12db39fa93b927c345593e")
|
||||
l := &Lock{
|
||||
|
|
|
@ -15,6 +15,8 @@ import (
|
|||
|
||||
func TestReadManifest(t *testing.T) {
|
||||
h := test.NewHelper(t)
|
||||
defer h.Cleanup()
|
||||
|
||||
_, err := readManifest(h.GetTestFileReader("manifest/error.json"))
|
||||
if err == nil {
|
||||
t.Error("Reading manifest with invalid props should have caused error, but did not")
|
||||
|
@ -59,6 +61,8 @@ func TestReadManifest(t *testing.T) {
|
|||
|
||||
func TestWriteManifest(t *testing.T) {
|
||||
h := test.NewHelper(t)
|
||||
defer h.Cleanup()
|
||||
|
||||
jg := h.GetTestFileString("manifest/golden.json")
|
||||
c, _ := gps.NewSemverConstraint("^v0.12.0")
|
||||
m := &Manifest{
|
||||
|
|
|
@ -60,6 +60,8 @@ func TestTxnWriter(t *testing.T) {
|
|||
test.NeedsGit(t)
|
||||
|
||||
h := test.NewHelper(t)
|
||||
defer h.Cleanup()
|
||||
|
||||
h.TempDir("")
|
||||
defer h.Cleanup()
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче