From 1129f571437ece60b66faee22875e3bac80a4ad0 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Tue, 18 Oct 2022 15:22:55 +0300 Subject: [PATCH] unittests: Skip test if not on GCE The test in pkg/credentialprovider/gcp/metadata_test.go is meant to run only on GCE, which means that it will fail in any other case. We should skip the test if we're not testing in GCE or Windows in GCE. --- pkg/credentialprovider/gcp/metadata_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/credentialprovider/gcp/metadata_test.go b/pkg/credentialprovider/gcp/metadata_test.go index 30b1bb4204c..5e469f3e1cf 100644 --- a/pkg/credentialprovider/gcp/metadata_test.go +++ b/pkg/credentialprovider/gcp/metadata_test.go @@ -26,6 +26,7 @@ import ( "net/url" "os" "reflect" + "runtime" "strings" "testing" @@ -47,6 +48,12 @@ func createProductNameFile() (string, error) { // referenced by gceProductNameFile being removed, which is the opposite of // the other tests func TestMetadata(t *testing.T) { + // This test requires onGCEVM to return True. On Linux, this can be faked by creating a + // Product Name File. But on Windows, onGCEVM makes the following syscall instead: + // wmic computersystem get model + if runtime.GOOS == "windows" && !onGCEVM() { + t.Skip("Skipping test on Windows, not on GCE.") + } var err error gceProductNameFile, err = createProductNameFile() if err != nil {