diff --git a/internal/config/config_test.go b/internal/config/config_test.go index e8b0f7cf..8dd197d0 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -18,6 +18,7 @@ import ( "io" "os" "path/filepath" + "runtime" "strings" "testing" @@ -474,7 +475,13 @@ func TestInvalidConfigFile(t *testing.T) { os.Setenv("SW_APM_SERVICE_KEY", "ae38315f6116585d64d82ec2455aa3ec61e02fee25d286f74ace9e4fea189217:go") os.Setenv("SW_APM_CONFIG_FILE", "/tmp/file-not-exist.yaml") _ = NewConfig() - assert.Contains(t, buf.String(), "no such file or directory") + var exp string + if runtime.GOOS == "windows" { + exp = "The system cannot find the path specified." + } else { + exp = "no such file or directory" + } + assert.Contains(t, buf.String(), exp) } func TestInvalidConfig(t *testing.T) { diff --git a/internal/host/k8s/k8s_test.go b/internal/host/k8s/k8s_test.go index 20cd531f..da3db919 100644 --- a/internal/host/k8s/k8s_test.go +++ b/internal/host/k8s/k8s_test.go @@ -96,7 +96,7 @@ func TestRequestMetadataFromEnv(t *testing.T) { md, err := requestMetadata() require.Error(t, err) require.Nil(t, md) - require.Equal(t, "open /run/secrets/kubernetes.io/serviceaccount/namespace: no such file or directory", err.Error()) + require.True(t, os.IsNotExist(err)) defer testutils.Setenv(t, "SW_K8S_POD_NAMESPACE", "my env namespace")() md, err = requestMetadata() @@ -124,7 +124,7 @@ func TestRequestMetadataNoNamespace(t *testing.T) { md, err := requestMetadata() require.Error(t, err) require.Nil(t, md) - require.Equal(t, fmt.Sprintf("open %s: no such file or directory", determineNamspaceFileForOS()), err.Error()) + require.True(t, os.IsNotExist(err)) } func TestMetadata_ToPB(t *testing.T) { @@ -159,9 +159,8 @@ func TestGetNamespaceNoneFound(t *testing.T) { require.NoError(t, os.Unsetenv("SW_K8S_POD_NAMESPACE")) ns, err := getNamespaceFromFile("this file does not exist and should not be opened") require.Error(t, err) - require.Equal(t, "open this file does not exist and should not be opened: no such file or directory", err.Error()) + require.True(t, os.IsNotExist(err)) require.Equal(t, "", ns) - } // Test getPodName diff --git a/internal/uams/file_test.go b/internal/uams/file_test.go index 0c4d9fa5..fe2d8f83 100644 --- a/internal/uams/file_test.go +++ b/internal/uams/file_test.go @@ -15,9 +15,11 @@ package uams import ( + "errors" "fmt" "github.com/google/uuid" "github.com/stretchr/testify/require" + "io/fs" "os" "testing" ) @@ -29,7 +31,7 @@ func TestReadFromFileNoExists(t *testing.T) { uid, err := ReadFromFile(testfile) require.Equal(t, uuid.Nil, uid) require.Error(t, err) - require.Equal(t, "could not stat uams client file: stat /tmp/foobarbaz: no such file or directory", err.Error()) + require.True(t, errors.Is(err, fs.ErrNotExist)) } func TestReadFromFileDirectory(t *testing.T) {