From c053088a103a861429e70016914923692bc30291 Mon Sep 17 00:00:00 2001 From: LandonTClipp <11232769+LandonTClipp@users.noreply.github.com> Date: Wed, 2 Oct 2024 10:53:22 -0500 Subject: [PATCH] Fix test on windows --- plugins/inputs/nvidia_smi/nvidia_smi_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/nvidia_smi/nvidia_smi_test.go b/plugins/inputs/nvidia_smi/nvidia_smi_test.go index 3061b368a365d..b30673666f3fe 100644 --- a/plugins/inputs/nvidia_smi/nvidia_smi_test.go +++ b/plugins/inputs/nvidia_smi/nvidia_smi_test.go @@ -4,6 +4,7 @@ import ( "errors" "os" "path/filepath" + "runtime" "testing" "time" @@ -16,6 +17,16 @@ import ( ) func TestOnStartupError(t *testing.T) { + var binPath string + var nvidiaSMIArgs []string + if runtime.GOOS == "windows" { + binPath = `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe` + nvidiaSMIArgs = []string{"-Command", "exit 1"} + } else { + binPath = "/bin/bash" + nvidiaSMIArgs = []string{"-c", "exit 1"} + } + tests := []struct { ProbeOnStartup bool }{ @@ -28,11 +39,11 @@ func TestOnStartupError(t *testing.T) { } for _, tt := range tests { plugin := &NvidiaSMI{ - BinPath: "/bin/bash", + BinPath: binPath, ProbeOnStartup: tt.ProbeOnStartup, Timeout: config.Duration(time.Second), Log: &testutil.Logger{}, - nvidiaSMIArgs: []string{"-c", "exit 9"}, + nvidiaSMIArgs: nvidiaSMIArgs, } model := models.NewRunningInput(plugin, &models.InputConfig{ Name: "nvidia_smi",