Skip to content

Commit 0a643a7

Browse files
author
Paulo Janotti
authored
Make perf testbed OS agnostic (#55) (#64)
Leveraging GOOS to make the tests run seamless in multiple OSes. There will be separate work to establish different baselines for different platforms, this first change is just to make it runs without manual adaptations on multiple OSes.
1 parent b4c9671 commit 0a643a7

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

testbed/testbed/test_bed.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525
package testbed
2626

2727
import (
28+
"bytes"
2829
"errors"
2930
"log"
3031
"os"
3132
"path"
3233
"path/filepath"
34+
"runtime"
35+
"text/template"
3336

3437
"github.com/spf13/viper"
3538
)
@@ -64,10 +67,28 @@ func LoadConfig() error {
6467

6568
testBedConfigDir := path.Dir(testBedConfigFile)
6669

70+
// Use templates to expand some selected content on the config file.
71+
cfgTemplate, err := template.ParseFiles(testBedConfigFile)
72+
if err != nil {
73+
log.Fatalf("Template failed to parse config file %q: %s",
74+
testBedConfigFile, err.Error())
75+
}
76+
77+
templateVars := struct {
78+
GOOS string
79+
}{
80+
GOOS: runtime.GOOS,
81+
}
82+
var buf bytes.Buffer
83+
if err := cfgTemplate.Execute(&buf, templateVars); err != nil {
84+
log.Fatalf("Configuration template failed to run on file %q: %s",
85+
testBedConfigFile, err.Error())
86+
}
87+
6788
// Read the config.
6889
v := viper.New()
69-
v.SetConfigFile(testBedConfigFile)
70-
if err = v.ReadInConfig(); err != nil {
90+
v.SetConfigType("yaml")
91+
if err = v.ReadConfig(bytes.NewBuffer(buf.Bytes())); err != nil {
7192
log.Fatalf("Cannot load test bed config from %q: %s",
7293
testBedConfigFile, err.Error())
7394
}
@@ -78,7 +99,6 @@ func LoadConfig() error {
7899
}
79100

80101
// Convert relative paths to absolute.
81-
82102
testBedConfig.Agent, err = filepath.Abs(path.Join(testBedConfigDir, testBedConfig.Agent))
83103
if err != nil {
84104
log.Fatalf("Cannot resolve file name %q: %s",

testbed/tests/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

testbed/tests/local.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
agent: ../../bin/otelsvc_linux
1+
agent: ../../bin/otelsvc_{{.GOOS}}

0 commit comments

Comments
 (0)