mirror of
https://github.com/postmannen/ctrl.git
synced 2025-01-18 21:59:30 +00:00
debugging tailfile test
This commit is contained in:
parent
1ece728621
commit
5ae3abe9fc
3 changed files with 56 additions and 8 deletions
|
@ -5,6 +5,7 @@
|
|||
package steward
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"io"
|
||||
"log"
|
||||
|
@ -82,7 +83,7 @@ func TestStewardServer(t *testing.T) {
|
|||
// checkREQPingTest(conf, t)
|
||||
// checkREQPongTest(conf, t)
|
||||
checkREQHttpGetTest(conf, t)
|
||||
// checkREQTailFileTest(conf, t)
|
||||
checkREQTailFileTest(conf, t)
|
||||
// checkREQToSocketTest(conf, t)
|
||||
|
||||
checkErrorKernelJSONtest(conf, t)
|
||||
|
@ -231,8 +232,6 @@ func checkREQErrorLogTest(conf *Configuration, t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
func checkREQHttpGetTest(conf *Configuration, t *testing.T) {
|
||||
// Web server for testing.
|
||||
{
|
||||
|
@ -266,6 +265,56 @@ func checkREQHttpGetTest(conf *Configuration, t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
func checkREQTailFileTest(conf *Configuration, t *testing.T) {
|
||||
// // Create a file with some content.
|
||||
// fh, err := os.Create("test.file")
|
||||
// if err != nil {
|
||||
// t.Fatalf(" * failed: unable to open temporary file: %v\n", err)
|
||||
// }
|
||||
// defer fh.Close()
|
||||
//
|
||||
// for i := 1; i <= 10; i++ {
|
||||
// _, err = fh.Write([]byte("some file content"))
|
||||
// if err != nil {
|
||||
// t.Fatalf(" * failed: writing to temporary file: %v\n", err)
|
||||
// }
|
||||
// time.Sleep(time.Millisecond * 500)
|
||||
// }
|
||||
//
|
||||
// wd, err := os.Getwd()
|
||||
// if err != nil {
|
||||
// t.Fatalf(" * failed: getting current working directory: %v\n", err)
|
||||
// }
|
||||
//
|
||||
// file := filepath.Join(wd, "test.file")
|
||||
|
||||
s := Message{
|
||||
Directory: "tail-files",
|
||||
FileExtension: ".result",
|
||||
ToNode: "central",
|
||||
Data: []string{"/var/log/system.log"},
|
||||
Method: REQTailFile,
|
||||
ACKTimeout: 3,
|
||||
Retries: 2,
|
||||
MethodTimeout: 10,
|
||||
}
|
||||
|
||||
sJSON, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
t.Fatalf(" * failed: json marshaling of message: %v: %v\n", sJSON, err)
|
||||
}
|
||||
|
||||
writeToSocketTest(conf, string(sJSON), t)
|
||||
|
||||
time.Sleep(time.Second * 5)
|
||||
|
||||
resultFile := filepath.Join(conf.SubscribersDataFolder, "tail-files", "central", "central.REQTailFile.result")
|
||||
findStringInFileTest("some file content", resultFile, conf, t)
|
||||
|
||||
}
|
||||
|
||||
// ------- Functionality tests.
|
||||
|
||||
// Check errorKernel
|
||||
|
|
|
@ -851,7 +851,7 @@ func (m methodREQnCliCommand) getKind() CommandOrEvent {
|
|||
// and the reply back will be sent as soon as the process is
|
||||
// done. No order are preserved.
|
||||
func (m methodREQnCliCommand) handler(proc process, message Message, node string) ([]byte, error) {
|
||||
log.Printf("<--- CLICommand REQUEST received from: %v, containing: %v", message.FromNode, message.Data)
|
||||
log.Printf("<--- nCLICommand REQUEST received from: %v, containing: %v", message.FromNode, message.Data)
|
||||
|
||||
// Execute the CLI command in it's own go routine, so we are able
|
||||
// to return immediately with an ack reply that the messag was
|
||||
|
@ -1025,7 +1025,7 @@ func (m methodREQTailFile) getKind() CommandOrEvent {
|
|||
// return the output of the command run back to the calling publisher
|
||||
// as a new message.
|
||||
func (m methodREQTailFile) handler(proc process, message Message, node string) ([]byte, error) {
|
||||
log.Printf("<--- CLICommand REQUEST received from: %v, containing: %v", message.FromNode, message.Data)
|
||||
log.Printf("<--- TailFile REQUEST received from: %v, containing: %v", message.FromNode, message.Data)
|
||||
|
||||
proc.processes.wg.Add(1)
|
||||
go func() {
|
||||
|
@ -1078,6 +1078,7 @@ func (m methodREQTailFile) handler(proc process, message Message, node string) (
|
|||
sendErrorLogMessage(proc.toRingbufferCh, proc.node, er)
|
||||
return
|
||||
case out := <-outCh:
|
||||
|
||||
// Prepare and queue for sending a new message with the output
|
||||
// of the action executed.
|
||||
newReplyMessage(proc, message, out)
|
||||
|
@ -1091,9 +1092,6 @@ func (m methodREQTailFile) handler(proc process, message Message, node string) (
|
|||
}
|
||||
|
||||
// ---
|
||||
|
||||
// --- methodREQTailFile
|
||||
|
||||
type methodREQnCliCommandCont struct {
|
||||
commandOrEvent CommandOrEvent
|
||||
}
|
||||
|
|
1
test.file
Normal file
1
test.file
Normal file
|
@ -0,0 +1 @@
|
|||
some file contentsome file contentsome file contentsome file contentsome file contentsome file contentsome file contentsome file contentsome file contentsome file content
|
Loading…
Add table
Reference in a new issue