mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-04 07:49:35 +00:00 
			
		
		
		
	This patch moves the HostUtil functionality from the util/mount package to the volume/util/hostutil package. All `*NewHostUtil*` calls are changed to return concrete types instead of interfaces. All callers are changed to use the `*NewHostUtil*` methods instead of directly instantiating the concrete types.
		
			
				
	
	
		
			75 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			75 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
// +build windows
 | 
						|
 | 
						|
/*
 | 
						|
Copyright 2017 The Kubernetes Authors.
 | 
						|
 | 
						|
Licensed under the Apache License, Version 2.0 (the "License");
 | 
						|
you may not use this file except in compliance with the License.
 | 
						|
You may obtain a copy of the License at
 | 
						|
 | 
						|
    http://www.apache.org/licenses/LICENSE-2.0
 | 
						|
 | 
						|
Unless required by applicable law or agreed to in writing, software
 | 
						|
distributed under the License is distributed on an "AS IS" BASIS,
 | 
						|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
						|
See the License for the specific language governing permissions and
 | 
						|
limitations under the License.
 | 
						|
*/
 | 
						|
 | 
						|
package hostutil
 | 
						|
 | 
						|
import (
 | 
						|
	"io/ioutil"
 | 
						|
	"os"
 | 
						|
	"testing"
 | 
						|
)
 | 
						|
 | 
						|
func TestGetFileType(t *testing.T) {
 | 
						|
	hu := NewHostUtil()
 | 
						|
 | 
						|
	testCase := []struct {
 | 
						|
		name         string
 | 
						|
		expectedType FileType
 | 
						|
		setUp        func() (string, string, error)
 | 
						|
	}{
 | 
						|
		{
 | 
						|
			"Directory Test",
 | 
						|
			FileTypeDirectory,
 | 
						|
			func() (string, string, error) {
 | 
						|
				tempDir, err := ioutil.TempDir("", "test-get-filetype-")
 | 
						|
				return tempDir, tempDir, err
 | 
						|
			},
 | 
						|
		},
 | 
						|
		{
 | 
						|
			"File Test",
 | 
						|
			FileTypeFile,
 | 
						|
			func() (string, string, error) {
 | 
						|
				tempFile, err := ioutil.TempFile("", "test-get-filetype")
 | 
						|
				if err != nil {
 | 
						|
					return "", "", err
 | 
						|
				}
 | 
						|
				tempFile.Close()
 | 
						|
				return tempFile.Name(), tempFile.Name(), nil
 | 
						|
			},
 | 
						|
		},
 | 
						|
	}
 | 
						|
 | 
						|
	for idx, tc := range testCase {
 | 
						|
		path, cleanUpPath, err := tc.setUp()
 | 
						|
		if err != nil {
 | 
						|
			t.Fatalf("[%d-%s] unexpected error : %v", idx, tc.name, err)
 | 
						|
		}
 | 
						|
		if len(cleanUpPath) > 0 {
 | 
						|
			defer os.RemoveAll(cleanUpPath)
 | 
						|
		}
 | 
						|
 | 
						|
		fileType, err := hu.GetFileType(path)
 | 
						|
		if err != nil {
 | 
						|
			t.Fatalf("[%d-%s] unexpected error : %v", idx, tc.name, err)
 | 
						|
		}
 | 
						|
		if fileType != tc.expectedType {
 | 
						|
			t.Fatalf("[%d-%s] expected %s, but got %s", idx, tc.name, tc.expectedType, fileType)
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |