Skip to content

Commit

Permalink
Merge pull request #1985 from jsternberg/integration-test/version
Browse files Browse the repository at this point in the history
  • Loading branch information
jedevc authored Aug 4, 2023
2 parents 1f61de0 + 1d12c1f commit 50fbdd8
Show file tree
Hide file tree
Showing 8 changed files with 1,230 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ jobs:
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require (
github.com/zclconf/go-cty v1.10.0
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/trace v1.14.0
golang.org/x/mod v0.9.0
golang.org/x/sync v0.2.0
golang.org/x/term v0.8.0
google.golang.org/grpc v1.53.0
Expand Down Expand Up @@ -156,7 +157,6 @@ require (
go.opentelemetry.io/otel/sdk v1.14.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
golang.org/x/crypto v0.2.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.8.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestIntegration(t *testing.T) {
tests = append(tests, inspectTests...)
tests = append(tests, lsTests...)
tests = append(tests, imagetoolsTests...)
tests = append(tests, versionTests...)
testIntegration(t, tests...)
}

Expand Down
55 changes: 55 additions & 0 deletions tests/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package tests

import (
"strings"
"testing"

"github.com/moby/buildkit/util/testutil/integration"
"github.com/stretchr/testify/require"
"golang.org/x/mod/module"
"golang.org/x/mod/semver"
)

var versionTests = []func(t *testing.T, sb integration.Sandbox){
testVersion,
}

func testVersion(t *testing.T, sb integration.Sandbox) {
cmd := buildxCmd(sb, withArgs("version"))
out, err := cmd.CombinedOutput()
require.NoError(t, err, string(out))

// There should be at least one newline and the first line
// of output should contain the name, version, and possibly a revision.
firstLine, _, hasNewline := strings.Cut(string(out), "\n")
require.True(t, hasNewline, "At least one newline is required in the output")

// Log the output to make debugging easier.
t.Log(firstLine)

// Split by spaces into at least 2 fields.
fields := strings.Fields(firstLine)
require.GreaterOrEqual(t, len(fields), 2, "Expected at least 2 fields in the first line")

// First field should be an import path.
// This can be any valid import path for Go
// so don't set too many restrictions here.
// Just checking if the import path is a valid Go
// path should be suitable enough to make sure this is ok.
// Using CheckImportPath instead of CheckPath as it is less
// restrictive.
importPath := fields[0]
require.NoError(t, module.CheckImportPath(importPath), "First field was not a valid import path: %+v", importPath)

// Second field should be a version.
// This defaults to something that's still compatible
// with semver.
version := fields[1]
require.True(t, semver.IsValid(version), "Second field was not valid semver: %+v", version)

// Revision should be empty or should look like a git hash.
if len(fields) > 2 && len(fields[2]) > 0 {
revision := fields[2]
require.Regexp(t, `[0-9a-f]{40}`, revision, "Third field was not a git revision: %+v", revision)
}
}
78 changes: 78 additions & 0 deletions vendor/golang.org/x/mod/internal/lazyregexp/lazyre.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 50fbdd8

Please sign in to comment.