...

Source file src/github.com/Microsoft/hcsshim/internal/safefile/safeopen_test.go

Documentation: github.com/Microsoft/hcsshim/internal/safefile

     1  //go:build windows
     2  
     3  package safefile
     4  
     5  import (
     6  	"os"
     7  	"path/filepath"
     8  	"syscall"
     9  	"testing"
    10  
    11  	winio "github.com/Microsoft/go-winio"
    12  )
    13  
    14  func tempRoot(t *testing.T) (*os.File, error) {
    15  	t.Helper()
    16  	name := t.TempDir()
    17  	f, err := OpenRoot(name)
    18  	if err != nil {
    19  		return nil, err
    20  	}
    21  
    22  	t.Cleanup(func() {
    23  		_ = f.Close()
    24  	})
    25  
    26  	return f, err
    27  }
    28  
    29  func TestRemoveRelativeReadOnly(t *testing.T) {
    30  	root, err := tempRoot(t)
    31  	if err != nil {
    32  		t.Fatal(err)
    33  	}
    34  
    35  	p := filepath.Join(root.Name(), "foo")
    36  	f, err := os.Create(p)
    37  	if err != nil {
    38  		t.Fatal(err)
    39  	}
    40  	defer f.Close()
    41  
    42  	bi := winio.FileBasicInfo{}
    43  	bi.FileAttributes = syscall.FILE_ATTRIBUTE_READONLY
    44  	err = winio.SetFileBasicInfo(f, &bi)
    45  	if err != nil {
    46  		t.Fatal(err)
    47  	}
    48  	f.Close()
    49  
    50  	err = RemoveRelative("foo", root)
    51  	if err != nil {
    52  		t.Fatal(err)
    53  	}
    54  }
    55  

View as plain text