From 4e57be024864593ded0fbb521ee5b76f700d99db Mon Sep 17 00:00:00 2001 From: Salma Elsoly Date: Wed, 20 Nov 2024 12:27:50 +0200 Subject: [PATCH] refactor: get config file path as a parameter --- grid-proxy/tests/load_testing/load.go | 11 ++++++++--- grid-proxy/tests/load_testing/load_test.go | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/grid-proxy/tests/load_testing/load.go b/grid-proxy/tests/load_testing/load.go index 4efab862..db656bf0 100644 --- a/grid-proxy/tests/load_testing/load.go +++ b/grid-proxy/tests/load_testing/load.go @@ -5,6 +5,8 @@ import ( "log" "net/http" "os" + "path/filepath" + "slices" "time" prometheus_integration "github.com/threefoldtech/tfgrid-sdk-go/grid-proxy/tests/load_testing/prometheus" @@ -14,9 +16,12 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func PerformLoadTesting() error { - - data, err := os.ReadFile("test.yml") +func PerformLoadTesting(path string) error { + extension := filepath.Ext(path) + if !slices.Contains([]string{".yml", ".yaml"}, extension) { + return fmt.Errorf("Unsupported file extension") + } + data, err := os.ReadFile(path) if err != nil { return fmt.Errorf("Failed to read YAML file: %v", err) } diff --git a/grid-proxy/tests/load_testing/load_test.go b/grid-proxy/tests/load_testing/load_test.go index 8426bbbd..4dde1a70 100644 --- a/grid-proxy/tests/load_testing/load_test.go +++ b/grid-proxy/tests/load_testing/load_test.go @@ -3,7 +3,7 @@ package load_test import "testing" func TestLoad(t *testing.T) { - err := PerformLoadTesting() + err := PerformLoadTesting("test.yml") if err != nil { t.Fatalf("Load test failed: %v", err) }