github.com/matrixorigin/matrixone@v0.7.0/pkg/config/configuration_test.go (about)

     1  // Copyright 2023 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package config
    16  
    17  import (
    18  	"os"
    19  	"testing"
    20  
    21  	"github.com/stretchr/testify/assert"
    22  )
    23  
    24  func TestGetUnixSocketAddress(t *testing.T) {
    25  	assert.NoError(t, os.RemoveAll("/tmp/TestGetUnixSocketAddress/"))
    26  	f := &FrontendParameters{UnixSocketAddress: "/tmp/TestGetUnixSocketAddress/1"}
    27  	assert.Equal(t, f.UnixSocketAddress, f.GetUnixSocketAddress())
    28  }
    29  
    30  func TestIsFileExist(t *testing.T) {
    31  	existFile := "/tmp/TestIsFileExist/exist"
    32  	notExistFile := "/tmp/TestIsFileExist/not_exist"
    33  	assert.NoError(t, os.MkdirAll("/tmp/TestIsFileExist", 0755))
    34  	defer func() {
    35  		assert.NoError(t, os.RemoveAll("/tmp/TestIsFileExist"))
    36  	}()
    37  
    38  	f, err := os.Create(existFile)
    39  	assert.NoError(t, err)
    40  	assert.NoError(t, f.Close())
    41  
    42  	ok, err := isFileExist(existFile)
    43  	assert.NoError(t, err)
    44  	assert.True(t, ok)
    45  
    46  	ok, err = isFileExist(notExistFile)
    47  	assert.NoError(t, err)
    48  	assert.False(t, ok)
    49  }