github.com/keybase/client/go@v0.0.0-20240520164431-4f512a4c85a3/install/install_windows_test.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  //go:build windows
     5  // +build windows
     6  
     7  package install
     8  
     9  import (
    10  	"testing"
    11  
    12  	"os"
    13  	"path/filepath"
    14  
    15  	"github.com/keybase/client/go/libkb"
    16  	"github.com/stretchr/testify/assert"
    17  	"github.com/stretchr/testify/require"
    18  )
    19  
    20  func TestIsInUse(t *testing.T) {
    21  	tc := libkb.SetupTest(t, "TestIsInUse", 1)
    22  	defer tc.Cleanup()
    23  
    24  	// Should be false if no special file is present
    25  	require.False(t, IsInUse("", tc.G.Log))
    26  
    27  	tmpdir, err := os.MkdirTemp("", "TestIsInUse")
    28  	assert.Nil(t, err, "can't create temp tmpdir")
    29  
    30  	signalFileName := filepath.Join(tmpdir, ".kbfs_number_of_handles")
    31  
    32  	// Should be false if special file is empty
    33  	require.False(t, IsInUse(tmpdir, tc.G.Log))
    34  
    35  	d := []byte("5")
    36  	assert.Nil(t, os.WriteFile(signalFileName, d, 0644))
    37  	defer os.Remove(signalFileName)
    38  
    39  	// Should be true if special file has a number
    40  	require.True(t, IsInUse(tmpdir, tc.G.Log))
    41  
    42  	d = []byte("0")
    43  	assert.Nil(t, os.WriteFile(signalFileName, d, 0644))
    44  
    45  	// Should be false if special file has a zero
    46  	require.False(t, IsInUse(tmpdir, tc.G.Log))
    47  }