Skip to content

Commit

Permalink
test buildinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Aug 8, 2024
1 parent 6e26763 commit 6bc535c
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 13 deletions.
26 changes: 26 additions & 0 deletions tests/framework/ngf.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os/exec"
"path/filepath"
"runtime/debug"
"strings"
"time"

Expand Down Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions tests/framework/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/client_settings_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/dataplane_perf_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/graceful_recovery_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/longevity_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/sample_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/scale_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"bytes"
Expand Down
4 changes: 3 additions & 1 deletion tests/suite/system_suite_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/telemetry_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/tracing_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"bytes"
Expand Down

0 comments on commit 6bc535c

Please sign in to comment.