-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: Refactor test suite in gelflogger and cleanup code The test suite in the gelflogger module is refactored to improve readability and maintainability. This involved moving the mock server functions to a separate 'helper' package. Also, the main logger file was cleaned up by removing unused imports and commented code. * refactor: Update gelflogger and introduce NewZeroLogger Implemented a baseLogProcessor in gelflogger's NewLogger for flexible log field processing. This change improves modularity by shifting the task of field processing from the exclusive scope of `formatGELFMessage`, allowing each log entry to be processed individually within the `Log` function. A redundant test case was also removed for clarity. Lastly, the `NewZeroLogger` function was added in `zerologger.go` to create a zerolog logger with a GelfWriter. * feat: Add zaplogger package and update dependencies Introduced a new zaplogger package for gelf-logger including tests, and updated required dependencies in the go.mod and go.sum files. The zaplogger package houses NewZapLogger, ProcessZapLoggerFields, and ConvertZapLogLevelToGraylog functions. Additionally, necessary dependencies like 'go.uber.org/zap' was added for functionality. * Update go.yml Updated go.yml according to warning "Node.js 16 actions are deprecated."
- Loading branch information
1 parent
9b997e3
commit d5e3112
Showing
10 changed files
with
488 additions
and
79 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
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,59 @@ | ||
package helper | ||
|
||
import ( | ||
"crypto/rand" | ||
"crypto/rsa" | ||
"crypto/tls" | ||
"crypto/x509" | ||
"crypto/x509/pkix" | ||
"math/big" | ||
"net" | ||
"testing" | ||
"time" | ||
) | ||
|
||
// StartMockServer creates a mock TCP server and returns a network listener. | ||
// The server listens on the specified TCP port on the loopback address, "127.0.0.1". | ||
// The returned listener should be closed after use to free the associated resources. | ||
func StartMockServer(t *testing.T) net.Listener { | ||
l, err := net.Listen("tcp", "127.0.0.1:0") | ||
if err != nil { | ||
t.Fatalf("Failed to start mock TCP server: %v", err) | ||
} | ||
return l | ||
} | ||
|
||
// StartMockTLSServer creates a mock TLS TCP server and returns a network listener. | ||
// It loads the X.509 key pair from the given PEM-encoded files, 'testcert.pem' and 'testkey.pem', for TLS configuration. | ||
// If the key pair cannot be loaded, the function aborts with a fatal error. | ||
// The server listens on the specified TCP port on the loopback address, "127.0.0.1". | ||
// The returned listener should be closed after use to free the associated resources. | ||
// To create these test certificate files, you can use OpenSSL with the following commands in your `test_data` folder under project root: | ||
// | ||
// `openssl req -newkey rsa:2048 -nodes -keyout testkey.pem -x509 -days 365 -out testcert.pem` | ||
func StartMockTLSServer(t *testing.T) net.Listener { | ||
|
||
cert := CreateTestCertificate() | ||
l, err := tls.Listen("tcp", "127.0.0.1:0", &tls.Config{Certificates: []tls.Certificate{cert}}) | ||
if err != nil { | ||
t.Fatalf("Failed to start mock TLS TCP server: %v", err) | ||
} | ||
return l | ||
} | ||
|
||
func CreateTestCertificate() tls.Certificate { | ||
privateKey, _ := rsa.GenerateKey(rand.Reader, 2048) | ||
template := &x509.Certificate{ | ||
SerialNumber: big.NewInt(1), | ||
Subject: pkix.Name{Organization: []string{"Acme Co"}}, | ||
NotBefore: time.Now(), | ||
NotAfter: time.Now().Add(time.Hour * 24 * 180), | ||
IsCA: true, | ||
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth}, | ||
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign, | ||
BasicConstraintsValid: true, | ||
} | ||
|
||
derBytes, _ := x509.CreateCertificate(rand.Reader, template, template, &privateKey.PublicKey, privateKey) | ||
return tls.Certificate{Certificate: [][]byte{derBytes}, PrivateKey: privateKey} | ||
} |
Oops, something went wrong.