diff --git a/integration/dir_presenters_test.go b/integration/dir_presenters_test.go new file mode 100644 index 000000000..b9233c8cd --- /dev/null +++ b/integration/dir_presenters_test.go @@ -0,0 +1,77 @@ +// +build integration + +package integration + +import ( + "bytes" + "flag" + "testing" + + "github.com/anchore/go-testutils" + "github.com/anchore/imgbom/imgbom" + "github.com/anchore/imgbom/imgbom/presenter" + "github.com/anchore/imgbom/imgbom/scope" + "github.com/sergi/go-diff/diffmatchpatch" +) + +var update = flag.Bool("update", false, "update the *.golden files for json presenters") + +func TestDirTextPresenter(t *testing.T) { + var buffer bytes.Buffer + protocol := imgbom.NewProtocol("dir://test-fixtures") + if protocol.Type != imgbom.DirProtocol { + t.Errorf("unexpected protocol returned: %v != %v", protocol.Type, imgbom.DirProtocol) + } + + catalog, err := imgbom.CatalogDir(protocol.Value, scope.AllLayersScope) + if err != nil { + t.Errorf("could not produce catalog: %w", err) + } + presenterOpt := presenter.ParseOption("text") + dirPresenter := presenter.GetDirPresenter(presenterOpt, protocol.Value, catalog) + + dirPresenter.Present(&buffer) + actual := buffer.Bytes() + if *update { + testutils.UpdateGoldenFileContents(t, actual) + } + + var expected = testutils.GetGoldenFileContents(t) + + if !bytes.Equal(expected, actual) { + dmp := diffmatchpatch.New() + diffs := dmp.DiffMain(string(actual), string(expected), true) + t.Errorf("mismatched output:\n%s", dmp.DiffPrettyText(diffs)) + } + +} + +func TestDirJsonPresenter(t *testing.T) { + var buffer bytes.Buffer + protocol := imgbom.NewProtocol("dir://test-fixtures") + if protocol.Type != imgbom.DirProtocol { + t.Errorf("unexpected protocol returned: %v != %v", protocol.Type, imgbom.DirProtocol) + } + + catalog, err := imgbom.CatalogDir(protocol.Value, scope.AllLayersScope) + if err != nil { + t.Errorf("could not produce catalog: %w", err) + } + presenterOpt := presenter.ParseOption("json") + dirPresenter := presenter.GetDirPresenter(presenterOpt, protocol.Value, catalog) + + dirPresenter.Present(&buffer) + actual := buffer.Bytes() + if *update { + testutils.UpdateGoldenFileContents(t, actual) + } + + var expected = testutils.GetGoldenFileContents(t) + + if !bytes.Equal(expected, actual) { + dmp := diffmatchpatch.New() + diffs := dmp.DiffMain(string(actual), string(expected), true) + t.Errorf("mismatched output:\n%s", dmp.DiffPrettyText(diffs)) + } + +} diff --git a/integration/test-fixtures/snapshot/TestDirJsonPresenter.golden b/integration/test-fixtures/snapshot/TestDirJsonPresenter.golden new file mode 100644 index 000000000..9406dbebc --- /dev/null +++ b/integration/test-fixtures/snapshot/TestDirJsonPresenter.golden @@ -0,0 +1 @@ +{"artifacts":[{"name":"actionmailer","version":"4.1.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"actionpack","version":"4.1.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"actionview","version":"4.1.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"activemodel","version":"4.1.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"activerecord","version":"4.1.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"activesupport","version":"4.1.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"arel","version":"5.0.1.20140414130214","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"bootstrap-sass","version":"3.1.1.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"builder","version":"3.2.2","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"coffee-rails","version":"4.0.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"coffee-script","version":"2.2.0","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"coffee-script-source","version":"1.7.0","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"erubis","version":"2.7.0","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"execjs","version":"2.0.2","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"hike","version":"1.2.3","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"i18n","version":"0.6.9","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"jbuilder","version":"2.0.7","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"jquery-rails","version":"3.1.0","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"json","version":"1.8.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"kgio","version":"2.9.2","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"libv8","version":"3.16.14.3","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"mail","version":"2.5.4","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"mime-types","version":"1.25.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"minitest","version":"5.3.4","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"multi_json","version":"1.10.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"mysql2","version":"0.3.16","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"polyglot","version":"0.3.4","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"rack","version":"1.5.2","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"rack-test","version":"0.6.2","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"rails","version":"4.1.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"railties","version":"4.1.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"raindrops","version":"0.13.0","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"rake","version":"10.3.2","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"rdoc","version":"4.1.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"ref","version":"1.0.5","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"sass","version":"3.2.19","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"sass-rails","version":"4.0.3","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"sdoc","version":"0.4.0","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"spring","version":"1.1.3","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"sprockets","version":"2.11.0","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"sprockets-rails","version":"2.1.3","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"sqlite3","version":"1.3.9","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"therubyracer","version":"0.12.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"thor","version":"0.19.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"thread_safe","version":"0.3.3","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"tilt","version":"1.4.1","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"treetop","version":"1.4.15","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"turbolinks","version":"2.2.2","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"tzinfo","version":"1.2.0","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"uglifier","version":"2.5.0","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null},{"name":"unicorn","version":"4.8.3","type":"bundle","cataloger":"","sources":[{"foundBy":"bundler-cataloger","effects":[]}],"metadata":null}],"Source":"test-fixtures"} \ No newline at end of file diff --git a/integration/test-fixtures/snapshot/TestDirTextPresenter.golden b/integration/test-fixtures/snapshot/TestDirTextPresenter.golden new file mode 100644 index 000000000..de5364a32 --- /dev/null +++ b/integration/test-fixtures/snapshot/TestDirTextPresenter.golden @@ -0,0 +1,256 @@ +[Path: test-fixtures] +[actionmailer] + Version: 4.1.1 + Type: bundle + Found by: bundler-cataloger + +[actionpack] + Version: 4.1.1 + Type: bundle + Found by: bundler-cataloger + +[actionview] + Version: 4.1.1 + Type: bundle + Found by: bundler-cataloger + +[activemodel] + Version: 4.1.1 + Type: bundle + Found by: bundler-cataloger + +[activerecord] + Version: 4.1.1 + Type: bundle + Found by: bundler-cataloger + +[activesupport] + Version: 4.1.1 + Type: bundle + Found by: bundler-cataloger + +[arel] + Version: 5.0.1.20140414130214 + Type: bundle + Found by: bundler-cataloger + +[bootstrap-sass] + Version: 3.1.1.1 + Type: bundle + Found by: bundler-cataloger + +[builder] + Version: 3.2.2 + Type: bundle + Found by: bundler-cataloger + +[coffee-rails] + Version: 4.0.1 + Type: bundle + Found by: bundler-cataloger + +[coffee-script] + Version: 2.2.0 + Type: bundle + Found by: bundler-cataloger + +[coffee-script-source] + Version: 1.7.0 + Type: bundle + Found by: bundler-cataloger + +[erubis] + Version: 2.7.0 + Type: bundle + Found by: bundler-cataloger + +[execjs] + Version: 2.0.2 + Type: bundle + Found by: bundler-cataloger + +[hike] + Version: 1.2.3 + Type: bundle + Found by: bundler-cataloger + +[i18n] + Version: 0.6.9 + Type: bundle + Found by: bundler-cataloger + +[jbuilder] + Version: 2.0.7 + Type: bundle + Found by: bundler-cataloger + +[jquery-rails] + Version: 3.1.0 + Type: bundle + Found by: bundler-cataloger + +[json] + Version: 1.8.1 + Type: bundle + Found by: bundler-cataloger + +[kgio] + Version: 2.9.2 + Type: bundle + Found by: bundler-cataloger + +[libv8] + Version: 3.16.14.3 + Type: bundle + Found by: bundler-cataloger + +[mail] + Version: 2.5.4 + Type: bundle + Found by: bundler-cataloger + +[mime-types] + Version: 1.25.1 + Type: bundle + Found by: bundler-cataloger + +[minitest] + Version: 5.3.4 + Type: bundle + Found by: bundler-cataloger + +[multi_json] + Version: 1.10.1 + Type: bundle + Found by: bundler-cataloger + +[mysql2] + Version: 0.3.16 + Type: bundle + Found by: bundler-cataloger + +[polyglot] + Version: 0.3.4 + Type: bundle + Found by: bundler-cataloger + +[rack] + Version: 1.5.2 + Type: bundle + Found by: bundler-cataloger + +[rack-test] + Version: 0.6.2 + Type: bundle + Found by: bundler-cataloger + +[rails] + Version: 4.1.1 + Type: bundle + Found by: bundler-cataloger + +[railties] + Version: 4.1.1 + Type: bundle + Found by: bundler-cataloger + +[raindrops] + Version: 0.13.0 + Type: bundle + Found by: bundler-cataloger + +[rake] + Version: 10.3.2 + Type: bundle + Found by: bundler-cataloger + +[rdoc] + Version: 4.1.1 + Type: bundle + Found by: bundler-cataloger + +[ref] + Version: 1.0.5 + Type: bundle + Found by: bundler-cataloger + +[sass] + Version: 3.2.19 + Type: bundle + Found by: bundler-cataloger + +[sass-rails] + Version: 4.0.3 + Type: bundle + Found by: bundler-cataloger + +[sdoc] + Version: 0.4.0 + Type: bundle + Found by: bundler-cataloger + +[spring] + Version: 1.1.3 + Type: bundle + Found by: bundler-cataloger + +[sprockets] + Version: 2.11.0 + Type: bundle + Found by: bundler-cataloger + +[sprockets-rails] + Version: 2.1.3 + Type: bundle + Found by: bundler-cataloger + +[sqlite3] + Version: 1.3.9 + Type: bundle + Found by: bundler-cataloger + +[therubyracer] + Version: 0.12.1 + Type: bundle + Found by: bundler-cataloger + +[thor] + Version: 0.19.1 + Type: bundle + Found by: bundler-cataloger + +[thread_safe] + Version: 0.3.3 + Type: bundle + Found by: bundler-cataloger + +[tilt] + Version: 1.4.1 + Type: bundle + Found by: bundler-cataloger + +[treetop] + Version: 1.4.15 + Type: bundle + Found by: bundler-cataloger + +[turbolinks] + Version: 2.2.2 + Type: bundle + Found by: bundler-cataloger + +[tzinfo] + Version: 1.2.0 + Type: bundle + Found by: bundler-cataloger + +[uglifier] + Version: 2.5.0 + Type: bundle + Found by: bundler-cataloger + +[unicorn] + Version: 4.8.3 + Type: bundle + Found by: bundler-cataloger +