Skip to content

Commit

Permalink
feat: add float_always field to component specification
Browse files Browse the repository at this point in the history
Co-authored-by: Steve Taylor <sttaylor@vmware.com>
Co-authored-by: Claire Tinati <ctinati@vmware.com
  • Loading branch information
crhntr and staylor14 committed Jun 28, 2023
1 parent afe2fa4 commit a574a21
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pkg/cargo/kilnfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func (kf *Kilnfile) ComponentSpec(name string) (ComponentSpec, error) {
func (kf *Kilnfile) Glaze(kl KilnfileLock) error {
kf.Stemcell.Version = kl.Stemcell.Version
for index, spec := range kf.Releases {
if spec.FloatAlways {
continue
}
lock, err := kl.FindReleaseWithName(spec.Name)
if err != nil {
return fmt.Errorf("release with name %q not found in Kilnfile.lock: %w", spec.Name, err)
Expand Down Expand Up @@ -107,7 +110,11 @@ type ComponentSpec struct {
GitHubRepository string `yaml:"github_repository,omitempty"`

// DeGlazeBehavior changes how version filed changes when de-glaze is run.
DeGlazeBehavior DeGlazeBehavior `yaml:"glaze_behavior"`
DeGlazeBehavior DeGlazeBehavior `yaml:"maintenance_version_bump_policy"`

// FloatAlways when does not override version constraint.
// It skips locking it during Kilnfile.Glaze.
FloatAlways bool `yaml:"float_always,omitempty"`

// TeamSlackChannel slack channel for team that maintains this bosh release
TeamSlackChannel string `yaml:"slack,omitempty"`
Expand Down
57 changes: 55 additions & 2 deletions pkg/cargo/kilnfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestKilnfileLock_UpdateReleaseLockWithName(t *testing.T) {
}

func TestKilnfile_Glaze(t *testing.T) {
t.Run("it updates the Kilnfile", func(t *testing.T) {
t.Run("locks versions to the value in the lock", func(t *testing.T) {
kf := Kilnfile{
Releases: []ComponentSpec{
{Name: "banana"},
Expand Down Expand Up @@ -109,10 +109,42 @@ func TestKilnfile_Glaze(t *testing.T) {
},
}, kf)
})

t.Run("when float always is true", func(t *testing.T) {
kf := Kilnfile{
Releases: []ComponentSpec{
{Name: "orange", Version: "<3", FloatAlways: true},
},
Stemcell: Stemcell{
OS: "alpine",
},
}
kl := KilnfileLock{
Releases: []ComponentLock{
{Name: "orange", Version: "2.3.4"},
},
Stemcell: Stemcell{
OS: "alpine",
Version: "42.0",
},
}

require.NoError(t, kf.Glaze(kl))

assert.Equal(t, Kilnfile{
Releases: []ComponentSpec{
{Name: "orange", Version: "<3", FloatAlways: true},
},
Stemcell: Stemcell{
OS: "alpine",
Version: "42.0",
},
}, kf, "it does not alter the versio constraint")
})
}

func TestKilnfile_DeGlaze(t *testing.T) {
t.Run("it updates the Kilnfile", func(t *testing.T) {
t.Run("when de glazing", func(t *testing.T) {
kf := Kilnfile{
Releases: []ComponentSpec{
{Name: "mango", Version: "1.2.3", DeGlazeBehavior: LockMajor},
Expand Down Expand Up @@ -141,6 +173,27 @@ func TestKilnfile_DeGlaze(t *testing.T) {
},
}, kf)
})

t.Run("when float_always is true", func(t *testing.T) {
kf := Kilnfile{
Releases: []ComponentSpec{
{Name: "mango", Version: "1.2.3", DeGlazeBehavior: LockMajor, FloatAlways: true},
},
}
kl := KilnfileLock{
Releases: []ComponentLock{
{Name: "mango", Version: "1.2.3"},
},
}

require.NoError(t, kf.DeGlaze(kl))

assert.Equal(t, Kilnfile{
Releases: []ComponentSpec{
{Name: "mango", Version: "~1", DeGlazeBehavior: LockMajor, FloatAlways: true},
},
}, kf, "it should change the constraint")
})
}

func TestDeGlazeBehavior_TextUnmarshalMarshaller(t *testing.T) {
Expand Down

0 comments on commit a574a21

Please sign in to comment.