integration: add tests for dir-based presenters

Signed-off-by: Alfredo Deza <adeza@anchore.com>
This commit is contained in:
Alfredo Deza 2020-07-02 15:39:26 -04:00
parent 3548c7b132
commit 9baae90c0b
3 changed files with 334 additions and 0 deletions

View File

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

File diff suppressed because one or more lines are too long

View File

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