Merge pull request #1011 from vdemeester/mark-test-helpers

Make testing helpers as such…
This commit is contained in:
Silvin 2018-04-23 11:20:12 +02:00 committed by GitHub
commit c790f387e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -24,6 +24,7 @@ const (
//SetupConfigFile creates a config.json file for testing //SetupConfigFile creates a config.json file for testing
func SetupConfigFile(t *testing.T) fs.Dir { func SetupConfigFile(t *testing.T) fs.Dir {
t.Helper()
dir := fs.NewDir(t, "trust_test", fs.WithMode(0700), fs.WithFile("config.json", ` dir := fs.NewDir(t, "trust_test", fs.WithMode(0700), fs.WithFile("config.json", `
{ {
"auths": { "auths": {
@ -97,12 +98,14 @@ func WithNotaryServer(notaryURL string) func(*icmd.Cmd) {
// CreateMaskedTrustedRemoteImage creates a remote image that is signed with // CreateMaskedTrustedRemoteImage creates a remote image that is signed with
// content trust, then pushes a different untrusted image at the same tag. // content trust, then pushes a different untrusted image at the same tag.
func CreateMaskedTrustedRemoteImage(t *testing.T, registryPrefix, repo, tag string) string { func CreateMaskedTrustedRemoteImage(t *testing.T, registryPrefix, repo, tag string) string {
t.Helper()
image := createTrustedRemoteImage(t, registryPrefix, repo, tag) image := createTrustedRemoteImage(t, registryPrefix, repo, tag)
createNamedUnsignedImageFromBusyBox(t, image) createNamedUnsignedImageFromBusyBox(t, image)
return image return image
} }
func createTrustedRemoteImage(t *testing.T, registryPrefix, repo, tag string) string { func createTrustedRemoteImage(t *testing.T, registryPrefix, repo, tag string) string {
t.Helper()
image := fmt.Sprintf("%s/%s:%s", registryPrefix, repo, tag) image := fmt.Sprintf("%s/%s:%s", registryPrefix, repo, tag)
icmd.RunCommand("docker", "image", "pull", AlpineImage).Assert(t, icmd.Success) icmd.RunCommand("docker", "image", "pull", AlpineImage).Assert(t, icmd.Success)
icmd.RunCommand("docker", "image", "tag", AlpineImage, image).Assert(t, icmd.Success) icmd.RunCommand("docker", "image", "tag", AlpineImage, image).Assert(t, icmd.Success)
@ -115,6 +118,7 @@ func createTrustedRemoteImage(t *testing.T, registryPrefix, repo, tag string) st
} }
func createNamedUnsignedImageFromBusyBox(t *testing.T, image string) { func createNamedUnsignedImageFromBusyBox(t *testing.T, image string) {
t.Helper()
icmd.RunCommand("docker", "image", "pull", BusyboxImage).Assert(t, icmd.Success) icmd.RunCommand("docker", "image", "pull", BusyboxImage).Assert(t, icmd.Success)
icmd.RunCommand("docker", "image", "tag", BusyboxImage, image).Assert(t, icmd.Success) icmd.RunCommand("docker", "image", "tag", BusyboxImage, image).Assert(t, icmd.Success)
icmd.RunCommand("docker", "image", "push", image).Assert(t, icmd.Success) icmd.RunCommand("docker", "image", "push", image).Assert(t, icmd.Success)

View File

@ -9,6 +9,7 @@ import (
// Assert checks wether the output contains the specified lines // Assert checks wether the output contains the specified lines
func Assert(t *testing.T, actual string, expectedLines map[int]func(string) error) { func Assert(t *testing.T, actual string, expectedLines map[int]func(string) error) {
t.Helper()
for i, line := range strings.Split(actual, "\n") { for i, line := range strings.Split(actual, "\n") {
cmp, ok := expectedLines[i] cmp, ok := expectedLines[i]
if !ok { if !ok {