-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ziwen Ning <[email protected]>
- Loading branch information
Showing
5 changed files
with
167 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2e | ||
|
||
import ( | ||
"bufio" | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/containerd/containerd/cio" | ||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
) | ||
|
||
const ( | ||
fluentdLogDirName = "./../fluentd-logs" | ||
) | ||
|
||
var testFluentd = func() { | ||
// These tests are run in serial because we only define one log driver instance. | ||
ginkgo.Describe("fluentd shim logger", ginkgo.Serial, func() { | ||
ginkgo.It("should send logs to fluentd log driver", func() { | ||
args := map[string]string{ | ||
logDriverTypeKey: fluentdDriverName, | ||
containerIdKey: testContainerId, | ||
containerNameKey: testContainerName, | ||
"--verbose": "true", | ||
} | ||
creator := cio.BinaryIO(*Binary, args) | ||
sendTestLogByContainerd(creator, testLog) | ||
validateTestLogsInFluentd(fluentdLogDirName, testLog) | ||
}) | ||
}) | ||
} | ||
|
||
func validateTestLogsInFluentd(dirName string, testLog string) { | ||
var fileName string | ||
err := filepath.Walk(dirName, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if strings.HasPrefix(info.Name(), "data.") && strings.HasSuffix(info.Name(), ".log") && info.Name() != "data.log" { | ||
fileName = path | ||
} | ||
return nil | ||
}) | ||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) | ||
gomega.Expect(fileName).ShouldNot(gomega.Equal("")) | ||
file, err := os.Open(fileName) | ||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) | ||
defer file.Close() | ||
var lastLine string | ||
scanner := bufio.NewScanner(file) | ||
for scanner.Scan() { | ||
lastLine = scanner.Text() | ||
} | ||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) | ||
contentParts := strings.Split(lastLine, "\t") | ||
gomega.Expect(len(contentParts)).Should(gomega.Equal(3)) | ||
var logContent map[string]string | ||
err = json.Unmarshal([]byte(contentParts[2]), &logContent) | ||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) | ||
gomega.Expect(logContent["log"]).Should(gomega.Equal(testLog)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters