github.com/alibaba/ilogtail/pkg@v0.0.0-20250526110833-c53b480d046c/helper/containercenter/mount_windows_test.go (about)

     1  // Copyright 2021 iLogtail Authors
     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  //go:build windows
    16  // +build windows
    17  
    18  package containercenter
    19  
    20  import (
    21  	"testing"
    22  
    23  	"github.com/alibaba/ilogtail/pkg/helper"
    24  	"github.com/stretchr/testify/require"
    25  )
    26  
    27  func TestGetMountedFilePath(t *testing.T) {
    28  	testCases := []struct {
    29  		dockerInstallPath   string
    30  		dockerDataMountPath string
    31  		logtailMountPath    string
    32  		filePath            string
    33  		outFilePath         string
    34  	}{
    35  		{
    36  			dockerInstallPath:   "",
    37  			dockerDataMountPath: "",
    38  			logtailMountPath:    "C:",
    39  			filePath:            "C:\\Program File\\docker\\containers\\id\\id.json",
    40  			outFilePath:         "C:\\Program File\\docker\\containers\\id\\id.json",
    41  		},
    42  		{
    43  			dockerInstallPath:   "",
    44  			dockerDataMountPath: "",
    45  			logtailMountPath:    "C:\\logtail_host",
    46  			filePath:            "C:\\Program File\\docker\\containers\\id\\id.json",
    47  			outFilePath:         "C:\\logtail_host\\Program File\\docker\\containers\\id\\id.json",
    48  		},
    49  		{
    50  			dockerInstallPath:   "\\",
    51  			dockerDataMountPath: "C:\\docker",
    52  			logtailMountPath:    "C:\\logtail_host",
    53  			filePath:            "D:\\containers\\id\\id.json",
    54  			outFilePath:         "C:\\docker\\containers\\id\\id.json",
    55  		},
    56  		{
    57  			dockerInstallPath:   "\\any_path\\xxx\\",
    58  			dockerDataMountPath: "C:\\path\\docker",
    59  			logtailMountPath:    "C:\\logtail_host",
    60  			filePath:            "E:\\any_path\\xxx\\containers\\id\\id.json",
    61  			outFilePath:         "C:\\path\\docker\\containers\\id\\id.json",
    62  		},
    63  		// containerd
    64  		{
    65  			dockerInstallPath:   "",
    66  			dockerDataMountPath: "",
    67  			logtailMountPath:    "C:\\logtail_host",
    68  			filePath:            "\\var\\logs\\pods\\xxx\\0.log",
    69  			outFilePath:         "\\var\\logs\\pods\\xxx\\0.log",
    70  		},
    71  	}
    72  
    73  	for _, c := range testCases {
    74  		*DockerInstallPath = addPathSeparatorAtEnd(c.dockerInstallPath)
    75  		*DockerDataMountPath = addPathSeparatorAtEnd(c.dockerDataMountPath)
    76  		DefaultLogtailMountPath = c.logtailMountPath
    77  		require.Equal(t, c.outFilePath, GetMountedFilePath(c.filePath))
    78  	}
    79  
    80  	require.Equal(t, helper.NormalizeWindowsPath("C:\\var\\addon-logtail\\token-config"), "C:\\var\\addon-logtail\\token-config")
    81  	require.Equal(t, helper.NormalizeWindowsPath("/var/addon-logtail/token-config"), "C:\\var\\addon-logtail\\token-config")
    82  	require.Equal(t, helper.NormalizeWindowsPath(""), "")
    83  }