Skip to content

Commit

Permalink
Merge pull request #30 from t4lz/go-statfs
Browse files Browse the repository at this point in the history
Add test image for go-statfs E2E test
  • Loading branch information
t4lz authored Feb 10, 2025
2 parents 07d2918 + a36452a commit 241086e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
10 changes: 10 additions & 0 deletions go-statfs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:1.23-alpine3.20
WORKDIR /app
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod test.txt ./
RUN go mod download && go mod verify

COPY . .
RUN go build -v -o /app/go-statfs ./...

CMD ["/app/go-statfs"]
3 changes: 3 additions & 0 deletions go-statfs/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module go-statfs

go 1.23.5
54 changes: 54 additions & 0 deletions go-statfs/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
"encoding/json"
"fmt"
_ "net" // for dynamic linking
"os"
"os/signal"
"syscall"
)

func main() {
rootPath := "/"
var statfs syscall.Statfs_t
err := syscall.Statfs(rootPath, &statfs)
if err != nil {
fmt.Println("Error:", err)
return
}

// Convert struct to a JSON-friendly format
data := map[string]interface{}{
"bavail": statfs.Bavail,
"bfree": statfs.Bfree,
"blocks": statfs.Blocks,
"bsize": statfs.Bsize,
"ffree": statfs.Ffree,
"files": statfs.Files,
"flags": statfs.Flags,
"frsize": statfs.Frsize,
"fsid": []int32{int32(statfs.Fsid.X__val[0]), int32(statfs.Fsid.X__val[1])},
"namelen": statfs.Namelen,
"spare": statfs.Spare,
"type": statfs.Type,
}

// Convert to JSON
jsonData, err := json.MarshalIndent(data, "", " ")
if err != nil {
fmt.Println("JSON Encoding Error:", err)
return
}

// Print JSON
fmt.Println(string(jsonData))

// Create a channel to receive OS signals
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

// Block forever waiting for a signal
<-sigs

}
1 change: 1 addition & 0 deletions go-statfs/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

0 comments on commit 241086e

Please sign in to comment.