Skip to content

Commit

Permalink
fix(installer): Properly support DD_AGENT_MINOR_VERSION when it's not…
Browse files Browse the repository at this point in the history
… in the minor.patch format (#30754)
  • Loading branch information
BaptisteFoy authored Nov 5, 2024
1 parent 5918f4e commit 59d8056
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/fleet/installer/default_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ func packageToLanguage(packageName string) env.ApmLibLanguage {
}

func agentVersion(_ Package, e *env.Env) string {
if e.AgentMajorVersion != "" && e.AgentMinorVersion != "" {
return e.AgentMajorVersion + "." + e.AgentMinorVersion + "-1"
minorVersion := e.AgentMinorVersion
if strings.Contains(minorVersion, ".") && !strings.HasSuffix(minorVersion, "-1") {
minorVersion = minorVersion + "-1"
}
if e.AgentMinorVersion != "" {
return "7." + e.AgentMinorVersion + "-1"
if e.AgentMajorVersion != "" && minorVersion != "" {
return e.AgentMajorVersion + "." + minorVersion
}
if minorVersion != "" {
return "7." + minorVersion
}
return "latest"
}
61 changes: 61 additions & 0 deletions pkg/fleet/installer/default_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,64 @@ func TestDefaultPackages(t *testing.T) {
})
}
}

func TestAgentVersion(t *testing.T) {
type testCase struct {
name string
majorVersion string
minorVersions string
expectedResult string
}

tests := []testCase{
{
name: "No version",
majorVersion: "",
minorVersions: "",
expectedResult: "latest",
},
{
name: "Major version only",
majorVersion: "7",
minorVersions: "",
expectedResult: "latest",
},
{
name: "Major, minor+patch version",
majorVersion: "7",
minorVersions: "42.0",
expectedResult: "7.42.0-1",
},
{
name: "Major, minor version",
majorVersion: "7",
minorVersions: "42",
expectedResult: "7.42",
},
{
name: "minor+patch",
minorVersions: "42.0",
expectedResult: "7.42.0-1",
},
{
name: "minor+patch-1",
minorVersions: "42.0-1",
expectedResult: "7.42.0-1",
},
{
name: "minor only",
minorVersions: "42",
expectedResult: "7.42",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := &env.Env{
AgentMajorVersion: tt.majorVersion,
AgentMinorVersion: tt.minorVersions,
}
res := agentVersion(Package{}, e)
assert.Equal(t, tt.expectedResult, res)
})
}
}

0 comments on commit 59d8056

Please sign in to comment.