Skip to content

Commit 21d0123

Browse files
committed
test: Add findmnt package
When testing mounts we can use findmnt --json output to parse the output cleanly. The package provides only ParseOutput() now, but it can be extended later to run the findmnt command.
1 parent af7362d commit 21d0123

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/integration/findmnt/findmnt.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//go:build integration
2+
3+
/*
4+
Copyright 2025 The Kubernetes Authors All rights reserved.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
// package parse findmnt command results.
20+
package findmnt
21+
22+
import "encoding/json"
23+
24+
type Filesystem struct {
25+
Target string `json:"target"`
26+
Source string `json:"source"`
27+
FSType string `json:"fstype"`
28+
Options string `json:"options"`
29+
}
30+
31+
type Result struct {
32+
Filesystems []Filesystem `json:"filesystems"`
33+
}
34+
35+
// ParseOutput parse findmnt output.
36+
func ParseOutput(output []byte) (*Result, error) {
37+
r := &Result{}
38+
if err := json.Unmarshal(output, r); err != nil {
39+
return nil, err
40+
}
41+
return r, nil
42+
}

0 commit comments

Comments
 (0)