k8s.io/kubernetes@v1.29.3/pkg/volume/vsphere_volume/vsphere_volume_util_windows_test.go (about)

     1  //go:build !providerless && windows
     2  // +build !providerless,windows
     3  
     4  /*
     5  Copyright 2022 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package vsphere_volume
    21  
    22  import (
    23  	"testing"
    24  
    25  	"github.com/stretchr/testify/assert"
    26  	"github.com/stretchr/testify/require"
    27  )
    28  
    29  func TestFormatIfNotFormatted(t *testing.T) {
    30  	// If this volume has already been mounted then
    31  	// its devicePath will have already been converted to a disk number,
    32  	// meaning that the original path is returned.
    33  	devPath, err := verifyDevicePath("foo")
    34  	require.NoError(t, err)
    35  	assert.Equal(t, "foo", devPath)
    36  
    37  	// Won't match any serial number, meaning that an error will be returned.
    38  	devPath, err = verifyDevicePath(diskByIDPath + diskSCSIPrefix + "fake-serial")
    39  	expectedErrMsg := `unable to find vSphere disk with serial fake-serial`
    40  	if err == nil || err.Error() != expectedErrMsg {
    41  		t.Errorf("expected error message `%s` but got `%v`", expectedErrMsg, err)
    42  	}
    43  }