Skip to content

Commit

Permalink
Make linux distro test generic
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Engelbert <[email protected]>
  • Loading branch information
pmengelbert authored and cpuguy83 committed May 1, 2024
1 parent 71a5dc3 commit 007e28e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 47 deletions.
74 changes: 27 additions & 47 deletions test/mariner2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"os"
"strings"
"testing"

"github.com/Azure/dalec"
Expand Down Expand Up @@ -315,60 +314,41 @@ echo "$BAR" > bar.txt

t.Run("test mariner2 signing", func(t *testing.T) {
t.Parallel()
runTest(t, func(ctx context.Context, gwc gwclient.Client) (*gwclient.Result, error) {
spec := dalec.Spec{
Name: "foo",
Version: "v0.0.1",
Description: "foo bar baz",
Website: "https://foo.bar.baz",
Revision: "1",
PackageConfig: &dalec.PackageConfig{
Signer: &dalec.Frontend{
Image: phonySignerRef,
},
spec := dalec.Spec{
Name: "foo",
Version: "v0.0.1",
Description: "foo bar baz",
Website: "https://foo.bar.baz",
Revision: "1",
PackageConfig: &dalec.PackageConfig{
Signer: &dalec.Frontend{
Image: phonySignerRef,
},
Sources: map[string]dalec.Source{
"foo": {
Inline: &dalec.SourceInline{
File: &dalec.SourceInlineFile{
Contents: "#!/usr/bin/env bash\necho \"hello, world!\"\n",
},
},
Sources: map[string]dalec.Source{
"foo": {
Inline: &dalec.SourceInline{
File: &dalec.SourceInlineFile{
Contents: "#!/usr/bin/env bash\necho \"hello, world!\"\n",
},
},
},
Build: dalec.ArtifactBuild{
Steps: []dalec.BuildStep{
{
Command: "/bin/true",
},
},
Build: dalec.ArtifactBuild{
Steps: []dalec.BuildStep{
{
Command: "/bin/true",
},
},
Artifacts: dalec.Artifacts{
Binaries: map[string]dalec.ArtifactConfig{
"foo": {},
},
},
Artifacts: dalec.Artifacts{
Binaries: map[string]dalec.ArtifactConfig{
"foo": {},
},
}

sr := newSolveRequest(withSpec(ctx, t, &spec), withBuildTarget("mariner2/rpm"))
res, err := gwc.Solve(ctx, sr)
if err != nil {
t.Fatal(err)
}

tgt := readFile(ctx, t, "/target", res)
cfg := readFile(ctx, t, "/config.json", res)

if string(tgt) != "mariner2" {
t.Fatal(fmt.Errorf("target incorrect; either not sent to signer or not received back from signer"))
}

if !strings.Contains(string(cfg), "linux") {
t.Fatal(fmt.Errorf("configuration incorrect"))
}
},
}

return gwclient.NewResult(), nil
})
runTest(t, distroSigningTest(t, &spec, "mariner2/rpm"))
})
}

Expand Down
36 changes: 36 additions & 0 deletions test/signing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package test

import (
"context"
"fmt"
"strings"
"testing"

"github.com/Azure/dalec"
gwclient "github.com/moby/buildkit/frontend/gateway/client"
)

func distroSigningTest(t *testing.T, spec *dalec.Spec, buildTarget string) func(ctx context.Context, gwc gwclient.Client) (*gwclient.Result, error) {
return func(ctx context.Context, gwc gwclient.Client) (*gwclient.Result, error) {
topTgt, _, _ := strings.Cut(buildTarget, "/")

sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(buildTarget))
res, err := gwc.Solve(ctx, sr)
if err != nil {
t.Fatal(err)
}

tgt := readFile(ctx, t, "/target", res)
cfg := readFile(ctx, t, "/config.json", res)

if string(tgt) != topTgt {
t.Fatal(fmt.Errorf("target incorrect; either not sent to signer or not received back from signer"))
}

if !strings.Contains(string(cfg), "linux") {
t.Fatal(fmt.Errorf("configuration incorrect"))
}

return gwclient.NewResult(), nil
}
}

0 comments on commit 007e28e

Please sign in to comment.