Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ replace github.com/docker/secrets-engine/secrets => ../secrets
require (
github.com/docker/secrets-engine/secrets v1.0.0
github.com/stretchr/testify v1.12.1
golang.org/x/mod v0.41.0
google.golang.org/protobuf v1.36.11
)

Expand Down
2 changes: 0 additions & 2 deletions client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWD
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c=
golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
9 changes: 9 additions & 0 deletions client/version/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@ func Test_Name(t *testing.T) {
assert.ErrorIs(t, err, ErrEmptyName)
})
}

func TestMustNewName(t *testing.T) {
t.Parallel()

assert.Equal(t, "foo", MustNewName("foo").String())
assert.PanicsWithError(t, "parsing name: empty name", func() {
MustNewName("")
})
}
181 changes: 139 additions & 42 deletions client/version/semver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,90 +15,187 @@
package version

import (
"cmp"
"testing"

"github.com/stretchr/testify/assert"
xsemver "golang.org/x/mod/semver"
)

var semverVectors = []string{
var invalidVersions = []string{
"",
"v",
"1.0.0",
"v1",
"v1.0",
"v1.0.0",
"v1.2.3",
"v10.20.30",
"v01",
"v1.02",
"v1.2.03",
"v1.2.3.4",
"v1.",
"v1..2",
"v1.2.",
"v0",
"v0.0.0",
"v1-pre",
"v1.2-pre",
"v1+meta",
"v1.2+meta",
"v1.2.3-",
"v1.2.3+",
"v1.2.3-alpha",
"v1.2.3-alpha.1",
"v1.2.3-alpha.beta",
"v1.2.3-alpha.01",
"v1.2.3-0",
"v1.2.3-00",
"v1.2.3-0a",
"v1.2.3-01a",
"v1.2.3-1",
"v1.2.3-2",
"v1.2.3-10",
"v1.2.3-a-b",
"v1.2.3--",
"v1.2.3-alpha..1",
"v1.2.3-alpha.",
"v1.2.3-beta",
"v1.2.3-beta.2",
"v1.2.3-beta.11",
"v1.2.3-rc.1",
"v1.2.3+build",
"v1.2.3+build.01",
"v1.2.3+build+x",
"v1.2.3-rc.1+build.5",
"v1.2.3-rc_1",
"v1.2.3+b_1",
"v2.0.0",
"v2.0.0-0.3.7",
"v1.0.0-x.7.z.92",
"V1.0.0",
"v1.0.0 ",
"v-1",
"v1.-1.0",

// Empty identifiers.
"v1.2.3-.alpha",
"v1.2.3+.build",
"v1.2.3+build..1",
"v1.2.3+build.",

// Invalid characters.
"v1.2.3-α",
"v1.2.3+α",
"v1.2.3",
"v1.2.3\n",
"v1.2.3\t",
"v1.2.3\x00",
" v1.2.3",
}

// orderedVersions contains groups of valid versions in ascending
// precedence order. Versions within each group compare equal.
var orderedVersions = [][]string{
// Abbreviated versions compare equal to their expanded forms.
{"v0", "v0.0", "v0.0.0"},
{"v1.0.0-x.7.z.92"},
{"v1", "v1.0", "v1.0.0"},

// Numeric pre-release identifiers are compared numerically.
{"v1.2.3-0"},
{"v1.2.3-1"},
{"v1.2.3-2"},
{"v1.2.3-10"},

// Numeric identifiers are not limited to uint64.
{"v1.2.3-18446744073709551615"},
{"v1.2.3-18446744073709551616"},

// Non-numeric identifiers sort after numeric identifiers
// and are compared in ASCII order.
{"v1.2.3--"},
{"v1.2.3-01a"},
{"v1.2.3-0a"},
{"v1.2.3-A"},
{"v1.2.3-a"},
{"v1.2.3-a-b"},

// Pre-release identifiers are compared individually.
{"v1.2.3-alpha"},
{"v1.2.3-alpha.1"},
{"v1.2.3-alpha.beta"},
{"v1.2.3-beta"},
{"v1.2.3-beta.2"},
{"v1.2.3-beta.11"},

// Build metadata does not affect precedence.
{"v1.2.3-rc.1", "v1.2.3-rc.1+build.5", "v1.2.3-rc.1+other"},
{"v1.2.3", "v1.2.3+build", "v1.2.3+build.01", "v1.2.3+other"},

// Major, minor, and patch versions are compared numerically.
{"v1.2.9"},
{"v1.2.10"},
{"v1.9.0"},
{"v1.10.0"},
{"v2.0.0-0.3.7"},
{"v2.0.0"},
{"v10.20.30"},

// Version numbers are not limited to uint64.
{"v18446744073709551615.0.0"},
{"v18446744073709551616.0.0"},
}

func TestSemverMatchesXMod(t *testing.T) {
func TestParseSemver(t *testing.T) {
t.Parallel()
for _, v := range semverVectors {

for _, v := range invalidVersions {
_, ok := parseSemver(v)
assert.Equal(t, xsemver.IsValid(v), ok, "valid(%q)", v)
assert.False(t, ok, "parseSemver(%q)", v)
}
for _, a := range semverVectors {
for _, b := range semverVectors {
assert.Equal(t, xsemver.Compare(a, b), compareSemver(a, b), "compare(%q, %q)", a, b)

for _, group := range orderedVersions {
for _, v := range group {
_, ok := parseSemver(v)
assert.True(t, ok, "parseSemver(%q)", v)
}
}
}

func FuzzSemverMatchesXMod(f *testing.F) {
for _, v := range semverVectors {
f.Add(v, "v1.2.3-rc.1")
func TestCompareSemver(t *testing.T) {
t.Parallel()

// Invalid versions compare equal to each other and less than
// any valid version.
groups := append([][]string{invalidVersions}, orderedVersions...)

for i, groupA := range groups {
for j, groupB := range groups {
want := cmp.Compare(i, j)
for _, a := range groupA {
for _, b := range groupB {
assert.Equal(t, want, compareSemver(a, b),
"compareSemver(%q, %q)", a, b)
}
}
}
}
}

func FuzzCompareSemver(f *testing.F) {
for _, v := range invalidVersions {
f.Add(v, "v1.2.3-rc.1", "v1.2.3")
}
f.Fuzz(func(t *testing.T, a, b string) {

for _, group := range orderedVersions {
for _, v := range group {
f.Add(v, "v1.2.3-rc.1", "v1.2.3")
}
}

f.Fuzz(func(t *testing.T, a, b, c string) {
ab := compareSemver(a, b)
ba := compareSemver(b, a)
bc := compareSemver(b, c)
ac := compareSemver(a, c)

// Reflexivity.
assert.Zero(t, compareSemver(a, a))

// Antisymmetry.
assert.Equal(t, -ab, ba)

// Transitivity.
if ab <= 0 && bc <= 0 {
assert.LessOrEqual(t, ac, 0)
}
if ab >= 0 && bc >= 0 {
assert.GreaterOrEqual(t, ac, 0)
}

// Valid versions sort after invalid versions.
_, okA := parseSemver(a)
assert.Equal(t, xsemver.IsValid(a), okA, "valid(%q)", a)
assert.Equal(t, xsemver.Compare(a, b), compareSemver(a, b), "compare(%q, %q)", a, b)
_, okB := parseSemver(b)
switch {
case okA && !okB:
assert.Equal(t, 1, ab)
case !okA && okB:
assert.Equal(t, -1, ab)
case !okA && !okB:
assert.Zero(t, ab)
}
})
}
53 changes: 53 additions & 0 deletions client/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,57 @@ func Test_Version(t *testing.T) {
_, err := NewVersion("")
assert.ErrorIs(t, err, ErrEmptyVersion)
})
t.Run("invalid semver", func(t *testing.T) {
v, err := NewVersion("v1.2.3.4")
assert.EqualError(t, err, "parsing version: invalid version: v1.2.3.4")
assert.Nil(t, v)
})
}

func TestMustNewVersion(t *testing.T) {
t.Parallel()

assert.Equal(t, "v1.0", MustNewVersion("v1.0").String())
assert.PanicsWithError(t, "parsing version: empty version", func() {
MustNewVersion("")
})
}

func TestCompare(t *testing.T) {
t.Parallel()

tests := []struct {
a, b string
want int
}{
{"v1.0.0", "v2.0.0", -1},
{"v2.0.0", "v1.0.0", 1},
{"v1.0.0", "v1.0.0", 0},
{"v1", "v1.0.0", 0},
{"v1.0.0-rc.1", "v1.0.0", -1},
{"v1.0.0+foo", "v1.0.0+bar", 0},
}

for _, tc := range tests {
assert.Equal(t, tc.want,
Compare(MustNewVersion(tc.a), MustNewVersion(tc.b)),
"Compare(%q, %q)", tc.a, tc.b)
}
}

type testVersion string

func (v testVersion) String() string {
return string(v)
}

func TestCompareInvalid(t *testing.T) {
t.Parallel()

validVer := MustNewVersion("v1.0.0")
invalid := testVersion("invalid")

assert.Equal(t, -1, Compare(invalid, validVer))
assert.Equal(t, 1, Compare(validVer, invalid))
assert.Zero(t, Compare(invalid, testVersion("also-invalid")))
}
2 changes: 0 additions & 2 deletions plugin/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWD
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c=
golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
Expand Down
2 changes: 0 additions & 2 deletions plugins/credentialhelper/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWD
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c=
golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
Expand Down
2 changes: 0 additions & 2 deletions plugins/pass/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWD
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c=
golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
Expand Down
Loading