Skip to content

Commit

Permalink
fix supervisor test
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaasman00 committed Oct 7, 2024
1 parent 5a94c0c commit e548ca2
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cmd/opampsupervisor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@ func TestSupervisorAgentDescriptionConfigApplies(t *testing.T) {
host, err := os.Hostname()
require.NoError(t, err)

description := getOSDescription(t)

// Get the binary name and version from the Collector binary
// using the `components` command that prints a YAML-encoded
// map of information about the Collector build. Some of this
Expand Down Expand Up @@ -748,6 +750,7 @@ func TestSupervisorAgentDescriptionConfigApplies(t *testing.T) {
stringKeyValue("env", "prod"),
stringKeyValue(semconv.AttributeHostArch, runtime.GOARCH),
stringKeyValue(semconv.AttributeHostName, host),
stringKeyValue(semconv.AttributeOSDescription, description),
stringKeyValue(semconv.AttributeOSType, runtime.GOOS),
},
}
Expand Down Expand Up @@ -1459,3 +1462,38 @@ func findRandomPort() (int, error) {

return port, nil
}

func getOSDescription(t *testing.T) string {
switch runtime.GOOS {
case "linux":
output, err := exec.Command("lsb_release", "-a").Output()
require.NoError(t, err)
for _, line := range strings.Split(string(output), "\n") {
if raw, ok := strings.CutPrefix(line, "Description:"); ok {
return strings.TrimSpace(raw)
}
}
case "darwin":
output, err := exec.Command("sw_vers").Output()
require.NoError(t, err)
var productName string
var productVersion string
for _, line := range strings.Split(string(output), "\n") {
if raw, ok := strings.CutPrefix(line, "ProductName:"); ok {
productName = strings.TrimSpace(raw)
} else if raw, ok = strings.CutPrefix(line, "ProductVersion:"); ok {
productVersion = strings.TrimSpace(raw)
}
}
if productName != "" && productVersion != "" {
return productName + " " + productVersion
}
case "windows":
output, err := exec.Command("cmd", "/c", "ver").Output()
require.NoError(t, err)
if string(output) != "" {
return strings.TrimSpace(string(output))
}
}
return ""
}

0 comments on commit e548ca2

Please sign in to comment.