// SetTag sets the new tag for the imagename
func (img *ImageName) SetTag(tag string) {
	img.Version = nil
	if rng, err := semver.NewRange(tag); err == nil && rng != nil {
		img.Version = rng
	}
	img.Tag = tag
}
Exemple #2
0
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"
}
Exemple #3
0
func Range(s string) *R {
	s = strings.Replace(s, "x", "0", -1)
	s = strings.Replace(s, "X", "0", -1)
	r, err := semver.NewRange(s)
	if err != nil {
		cli.Fatalf("unable to parse version range string '%s'; %s", s, err)
	}
	return &R{r, s}
}
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))
}