func TestWildcardRangeBounds(t *testing.T) { img := NewFromString("docker.io/tools/dockerize:1.2.*") assert.Equal(t, "docker.io", img.Registry) assert.Equal(t, "tools/dockerize", img.Name) assert.False(t, img.IsStrict()) v, _ := semver.NewVersion("1.2.8") assert.True(t, img.Version.Contains(v)) v, _ = semver.NewVersion("1.2.0") assert.True(t, img.Version.Contains(v)) }
func getVersionType(version string) (typ string) { _, err := semver.NewVersion(version) if err != nil && err.Error() == "Given string does not resemble a Version." { semver.NewRange(version) return "range" } return "version" }
func NewVersion(s string) (*V, error) { s = strings.TrimPrefix(s, "v") s = strings.Replace(s, "x", "0", -1) s = strings.Replace(s, "X", "0", -1) v, err := semver.NewVersion(s) if err != nil { return nil, err } return &V{v, s}, nil }
func TestRangeContainsPlainVersion(t *testing.T) { img := NewFromString("docker.io/tools/dockerize:0.0.1") expected, _ := semver.NewRange("0.0.1") assert.Equal(t, "docker.io", img.Registry) assert.Equal(t, "tools/dockerize", img.Name) assert.Equal(t, "0.0.1", img.Tag) assert.Equal(t, expected, img.Version) v, _ := semver.NewVersion("0.0.1") assert.True(t, img.Version.Contains(v)) }
func TestWildcardContains(t *testing.T) { img1 := NewFromString("docker.io/tools/dockerize:1.2.*") img2 := NewFromString("docker.io/tools/dockerize:1.2.1") assert.False(t, img1.IsStrict()) assert.True(t, img1.HasVersionRange()) assert.True(t, img2.IsStrict()) v, _ := semver.NewVersion("1.2.1") assert.Equal(t, v, img2.TagAsVersion()) assert.True(t, img1.Contains(img2)) assert.False(t, img2.Contains(img1)) }
// TagAsVersion return semver.Version of the current image tag in case it's in semver format func (img ImageName) TagAsVersion() (ver *semver.Version) { ver, _ = semver.NewVersion(strings.TrimPrefix(img.Tag, "v")) return }