github.com/vmware/govmomi@v0.51.0/simulator/guest_operations_manager_test.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package simulator
     6  
     7  import (
     8  	"os"
     9  	"os/exec"
    10  	"runtime"
    11  	"strings"
    12  	"testing"
    13  
    14  	"github.com/vmware/govmomi/vim25/types"
    15  )
    16  
    17  func TestFileInfo(t *testing.T) {
    18  	switch runtime.GOOS {
    19  	case "linux", "darwin":
    20  	default:
    21  		// listFiles() returns a `find` command to run inside a linux docker container.
    22  		// The `find` command also works on darwin, skip otherwise.
    23  		t.Skipf("GOOS=%s", runtime.GOOS)
    24  	}
    25  
    26  	pwd, err := os.Getwd()
    27  	if err != nil {
    28  		t.Fatal(err)
    29  	}
    30  
    31  	req := &types.ListFilesInGuest{
    32  		FilePath:     pwd,
    33  		MatchPattern: "*_test.go",
    34  	}
    35  
    36  	args := listFiles(req)
    37  	path, err := exec.LookPath(args[0])
    38  	if err != nil {
    39  		t.Fatal(err)
    40  	}
    41  
    42  	cmd := exec.Cmd{Path: path, Args: args}
    43  	res, err := cmd.CombinedOutput()
    44  	if err != nil {
    45  		t.Fatal(err)
    46  	}
    47  
    48  	for _, info := range toFileInfo(string(res)) {
    49  		if info.Path == "" {
    50  			t.Fail()
    51  		}
    52  		if !strings.HasSuffix(info.Path, "_test.go") {
    53  			t.Fail()
    54  		}
    55  		if info.Type == "" {
    56  			t.Fail()
    57  		}
    58  		if info.Size == 0 {
    59  			t.Fail()
    60  		}
    61  		attr, ok := info.Attributes.(*types.GuestPosixFileAttributes)
    62  		if !ok {
    63  			t.Fail()
    64  		}
    65  		if attr.ModificationTime == nil {
    66  			t.Fail()
    67  		}
    68  		if attr.AccessTime == nil {
    69  			t.Fail()
    70  		}
    71  		if attr.Permissions == 0 {
    72  			t.Fail()
    73  		}
    74  	}
    75  }