Skip to content

Commit f00f458

Browse files
committed
test: Add integration test for include_file_owner_name and include_file_owner_group_name
1 parent 1dac8b8 commit f00f458

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
//go:build integration && !windows
19+
20+
package integration
21+
22+
import (
23+
"fmt"
24+
"os"
25+
"os/user"
26+
"path/filepath"
27+
"strconv"
28+
"syscall"
29+
"testing"
30+
"time"
31+
32+
"github.com/stretchr/testify/require"
33+
34+
"github.com/elastic/beats/v7/libbeat/tests/integration"
35+
)
36+
37+
func TestFilestreamHasOwnerAndGroup(t *testing.T) {
38+
filebeat := integration.NewBeat(
39+
t,
40+
"filebeat",
41+
"../../filebeat.test",
42+
)
43+
tempDir := filebeat.TempDir()
44+
logFilePath := filepath.Join(tempDir, "input.log")
45+
46+
integration.WriteLogFile(t, logFilePath, 5, false)
47+
48+
cfg := fmt.Sprintf(`
49+
filebeat.inputs:
50+
- type: filestream
51+
enabled: true
52+
paths:
53+
- %s
54+
include_file_owner_name: true
55+
include_file_owner_group_name: true
56+
57+
logging:
58+
level: debug
59+
metrics:
60+
enabled: false
61+
62+
output:
63+
file:
64+
path: ${path.home}
65+
filename: "output"
66+
rotate_on_startup: false
67+
`, logFilePath)
68+
69+
filebeat.WriteConfigFile(cfg)
70+
filebeat.Start()
71+
72+
// Get logFilePath owner and group
73+
logFileInfo, err := os.Stat(logFilePath)
74+
if err != nil {
75+
t.Fatalf("Failed to stat file: %v", err)
76+
}
77+
78+
stat := logFileInfo.Sys().(*syscall.Stat_t)
79+
80+
logFileOwner, err := user.LookupId(strconv.FormatUint(uint64(stat.Uid), 10))
81+
if err != nil {
82+
t.Fatalf("Failed to lookup uid %v", err)
83+
}
84+
logFileGroup, err := user.LookupId(strconv.FormatUint(uint64(stat.Gid), 10))
85+
if err != nil {
86+
t.Fatalf("Failed to lookup gid %v", err)
87+
}
88+
89+
filebeat.WaitPublishedEvents(20*time.Second, 5)
90+
91+
type evt struct {
92+
LogFileOwner string `json:"log.file.owner"`
93+
LogFileGroup string `json:"log.file.group"`
94+
}
95+
evts := integration.GetEventsFromFileOutput[evt](filebeat, 5, false)
96+
for _, e := range evts {
97+
require.Equal(t, e.LogFileOwner, logFileOwner)
98+
require.Equal(t, e.LogFileGroup, logFileGroup)
99+
}
100+
}

0 commit comments

Comments
 (0)