diff --git a/tests/framework/ngf.go b/tests/framework/ngf.go index 48863a23e7..f5ad42e12e 100644 --- a/tests/framework/ngf.go +++ b/tests/framework/ngf.go @@ -5,6 +5,7 @@ import ( "fmt" "os/exec" "path/filepath" + "runtime/debug" "strings" "time" @@ -144,6 +145,31 @@ func UninstallNGF(cfg InstallationConfig, k8sClient client.Client) ([]byte, erro return nil, nil } +// GetBuildInfo returns the build information. +func GetBuildInfo() (commitHash string, commitTime string, dirtyBuild string) { + commitHash = "unknown" + commitTime = "unknown" + dirtyBuild = "unknown" + + info, ok := debug.ReadBuildInfo() + if !ok { + return + } + + for _, kv := range info.Settings { + switch kv.Key { + case "vcs.revision": + commitHash = kv.Value + case "vcs.time": + commitTime = kv.Value + case "vcs.modified": + dirtyBuild = kv.Value + } + } + + return +} + func setImageArgs(cfg InstallationConfig) []string { var args []string diff --git a/tests/framework/results.go b/tests/framework/results.go index ac65569d11..0c5bee3a85 100644 --- a/tests/framework/results.go +++ b/tests/framework/results.go @@ -49,10 +49,13 @@ func WriteSystemInfoToFile(file *os.File, ci ClusterInfo, plus bool) error { if ci.IsGKE { clusterType = "GKE" } + + commit, date, dirty := GetBuildInfo() + + //nolint:lll text := fmt.Sprintf( - //nolint:lll - "# Results\n\n## Test environment\n\nNGINX Plus: %v\n\n%s Cluster:\n\n- Node count: %d\n- k8s version: %s\n- vCPUs per node: %d\n- RAM per node: %s\n- Max pods per node: %d\n", - plus, clusterType, ci.NodeCount, ci.K8sVersion, ci.CPUCountPerNode, ci.MemoryPerNode, ci.MaxPodsPerNode, + "# Results\n\n## Test environment\n\nNGINX Plus: %v\n\n NGINX Gateway Fabric:\n\n- Commit: %s\n- Date: %s\n- Dirty: %v\n\n%s Cluster:\n\n- Node count: %d\n- k8s version: %s\n- vCPUs per node: %d\n- RAM per node: %s\n- Max pods per node: %d\n", + plus, commit, date, dirty, clusterType, ci.NodeCount, ci.K8sVersion, ci.CPUCountPerNode, ci.MemoryPerNode, ci.MaxPodsPerNode, ) if _, err := fmt.Fprint(file, text); err != nil { return err diff --git a/tests/suite/client_settings_test.go b/tests/suite/client_settings_test.go index 26ef6fc4f8..baffadb0ef 100644 --- a/tests/suite/client_settings_test.go +++ b/tests/suite/client_settings_test.go @@ -1,4 +1,4 @@ -package suite +package main import ( "bytes" diff --git a/tests/suite/dataplane_perf_test.go b/tests/suite/dataplane_perf_test.go index a1c3a6fb4f..703dbc3a21 100644 --- a/tests/suite/dataplane_perf_test.go +++ b/tests/suite/dataplane_perf_test.go @@ -1,4 +1,4 @@ -package suite +package main import ( "fmt" diff --git a/tests/suite/graceful_recovery_test.go b/tests/suite/graceful_recovery_test.go index a9edbbe2d8..b7360175c1 100644 --- a/tests/suite/graceful_recovery_test.go +++ b/tests/suite/graceful_recovery_test.go @@ -1,4 +1,4 @@ -package suite +package main import ( "context" diff --git a/tests/suite/longevity_test.go b/tests/suite/longevity_test.go index d42ebc8b26..4054ddb99c 100644 --- a/tests/suite/longevity_test.go +++ b/tests/suite/longevity_test.go @@ -1,4 +1,4 @@ -package suite +package main import ( "fmt" diff --git a/tests/suite/sample_test.go b/tests/suite/sample_test.go index d573c5903c..62d482edb2 100644 --- a/tests/suite/sample_test.go +++ b/tests/suite/sample_test.go @@ -1,4 +1,4 @@ -package suite +package main import ( "fmt" diff --git a/tests/suite/scale_test.go b/tests/suite/scale_test.go index e5737ad210..7fffdfbee9 100644 --- a/tests/suite/scale_test.go +++ b/tests/suite/scale_test.go @@ -1,4 +1,4 @@ -package suite +package main import ( "bytes" diff --git a/tests/suite/system_suite_test.go b/tests/suite/system_suite_test.go index f6913935ac..203f9aa2e6 100644 --- a/tests/suite/system_suite_test.go +++ b/tests/suite/system_suite_test.go @@ -1,4 +1,6 @@ -package suite +// This package needs to be named main to get build info +// because of https://github.com/golang/go/issues/33976 +package main import ( "context" diff --git a/tests/suite/telemetry_test.go b/tests/suite/telemetry_test.go index c6a8b65fc0..3ce1ec6669 100644 --- a/tests/suite/telemetry_test.go +++ b/tests/suite/telemetry_test.go @@ -1,4 +1,4 @@ -package suite +package main import ( "fmt" diff --git a/tests/suite/tracing_test.go b/tests/suite/tracing_test.go index 9876792c18..4e4519e3c5 100644 --- a/tests/suite/tracing_test.go +++ b/tests/suite/tracing_test.go @@ -1,4 +1,4 @@ -package suite +package main import ( "context" diff --git a/tests/suite/upgrade_test.go b/tests/suite/upgrade_test.go index 66c87922e8..1de1f45118 100644 --- a/tests/suite/upgrade_test.go +++ b/tests/suite/upgrade_test.go @@ -1,4 +1,4 @@ -package suite +package main import ( "bytes"