Add more content trust tests

Importing from moby's DockerTrustSuite tests.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester
2018-03-06 11:15:18 +01:00
parent 2731c71c99
commit 8b00c5cfd8
40 changed files with 1261 additions and 186 deletions

View File

@ -0,0 +1,44 @@
package output
import (
"strings"
"testing"
"github.com/pkg/errors"
)
// Assert checks wether the output contains the specified lines
func Assert(t *testing.T, actual string, expectedLines map[int]func(string) error) {
for i, line := range strings.Split(actual, "\n") {
cmp, ok := expectedLines[i]
if !ok {
continue
}
if err := cmp(line); err != nil {
t.Errorf("line %d: %s", i, err)
}
}
if t.Failed() {
t.Log(actual)
}
}
// Prefix returns whether if the line has the specified string as prefix
func Prefix(expected string) func(string) error {
return func(actual string) error {
if strings.HasPrefix(actual, expected) {
return nil
}
return errors.Errorf("expected %s to start with %s", actual, expected)
}
}
// Equals returns wether the line is the same as the specified string
func Equals(expected string) func(string) error {
return func(actual string) error {
if expected == actual {
return nil
}
return errors.Errorf("got %s, expected %s", actual, expected)
}
}