golang.org/x/tools@v0.21.0/godoc/vfs/os_test.go (about)

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package vfs_test
     6  
     7  import (
     8  	"os"
     9  	"runtime"
    10  	"testing"
    11  
    12  	"golang.org/x/tools/godoc/vfs"
    13  )
    14  
    15  func TestRootType(t *testing.T) {
    16  	goPath := os.Getenv("GOPATH")
    17  	var expectedType vfs.RootType
    18  	if goPath == "" {
    19  		expectedType = ""
    20  	} else {
    21  		expectedType = vfs.RootTypeGoPath
    22  	}
    23  	tests := []struct {
    24  		path   string
    25  		fsType vfs.RootType
    26  	}{
    27  		{runtime.GOROOT(), vfs.RootTypeGoRoot},
    28  		{goPath, expectedType},
    29  		{"/tmp/", ""},
    30  	}
    31  
    32  	for _, item := range tests {
    33  		fs := vfs.OS(item.path)
    34  		if fs.RootType("path") != item.fsType {
    35  			t.Errorf("unexpected fsType. Expected- %v, Got- %v", item.fsType, fs.RootType("path"))
    36  		}
    37  	}
    38  }