From 599075bc6580ba77dc22ba1c1ec8aa908ef2462d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 3 Oct 2021 13:44:28 +0300 Subject: add DTail color table test --- integrationtests/dtail_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 integrationtests/dtail_test.go (limited to 'integrationtests/dtail_test.go') diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go new file mode 100644 index 0000000..8d73174 --- /dev/null +++ b/integrationtests/dtail_test.go @@ -0,0 +1,22 @@ +package integrationtests + +import ( + "os" + "testing" +) + +func TestDTailColorTable(t *testing.T) { + stdoutFile := "dtailcolortable.stdout.tmp" + expectedStdoutFile := "dtailcolortable.expected" + + if err := runCommand(t, "../dtail", []string{"-colorTable"}, stdoutFile); err != nil { + t.Error(err) + return + } + if err := compareFiles(t, stdoutFile, expectedStdoutFile); err != nil { + t.Error(err) + return + } + + os.Remove(stdoutFile) +} -- cgit v1.2.3 From 7a7169791a64190e1002e38bc9c04ad0d5c1ce1f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 9 Oct 2021 16:44:28 +0300 Subject: add dtail health check unit test. --- integrationtests/dtail_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'integrationtests/dtail_test.go') diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go index 8d73174..9971f1a 100644 --- a/integrationtests/dtail_test.go +++ b/integrationtests/dtail_test.go @@ -9,7 +9,7 @@ func TestDTailColorTable(t *testing.T) { stdoutFile := "dtailcolortable.stdout.tmp" expectedStdoutFile := "dtailcolortable.expected" - if err := runCommand(t, "../dtail", []string{"-colorTable"}, stdoutFile); err != nil { + if _, err := runCommand(t, "../dtail", []string{"-colorTable"}, stdoutFile); err != nil { t.Error(err) return } -- cgit v1.2.3 From 97747ea0f3178f7f5890512d483fdccaa82846b0 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 9 Oct 2021 21:10:29 +0300 Subject: vetting and linting and some code restyling --- integrationtests/dtail_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'integrationtests/dtail_test.go') diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go index 9971f1a..36eadc0 100644 --- a/integrationtests/dtail_test.go +++ b/integrationtests/dtail_test.go @@ -8,8 +8,9 @@ import ( func TestDTailColorTable(t *testing.T) { stdoutFile := "dtailcolortable.stdout.tmp" expectedStdoutFile := "dtailcolortable.expected" + args := []string{"-colorTable"} - if _, err := runCommand(t, "../dtail", []string{"-colorTable"}, stdoutFile); err != nil { + if _, err := runCommand(t, "../dtail", args, stdoutFile); err != nil { t.Error(err) return } @@ -17,6 +18,5 @@ func TestDTailColorTable(t *testing.T) { t.Error(err) return } - os.Remove(stdoutFile) } -- cgit v1.2.3 From 71f89dc7ec7cf993d1eca98771212afe6310e9c8 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 10 Oct 2021 19:42:48 +0300 Subject: refactor --- integrationtests/dtail_test.go | 90 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) (limited to 'integrationtests/dtail_test.go') diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go index 36eadc0..267cd26 100644 --- a/integrationtests/dtail_test.go +++ b/integrationtests/dtail_test.go @@ -1,16 +1,102 @@ package integrationtests import ( + "context" "os" "testing" ) +func TestDTailWithServer(t *testing.T) { + followFile := "dtail.follow.tmp" + //serverStdoutFile := "dtail.dserver.stdout.tmp" + //greetings := []string{"world", "sol system", "milky way", "universe", "multiverse"} + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + serverCh, _, _, err := startCommand(ctx, + "../dserver", + "--logger", "stdout", + "--logLevel", "info", + "--port", "4242", + "--relaxedAuth", + ) + if err != nil { + t.Error(err) + return + } + + clientCh, _, _, err := startCommand(ctx, + "../dtail", + "--logger", "stdout", + "--logLevel", "devel", + "--servers", "localhost:4242", + "--files", followFile, + "--grep", "Hello", + "--trustAllHosts", + "--noColor", + ) + if err != nil { + t.Error(err) + return + } + + for { + select { + case line := <-serverCh: + t.Log("server:", line) + case line := <-clientCh: + t.Log("client:", line) + case <-ctx.Done(): + t.Log("Done reading client and server pipes") + } + } + + /* + // Start dtail client, connect to the server and follow followFile. + + //clientStdoutFile := "dtail.stdout.tmp" + /* + + t.Log(clientArgs) + // TODO: Pipe with dtail command to read stdin stream. + // runCommandContextRetry(ctx, t, "../dtail", clientArgs, clientStdoutFile) + + // Write greetings to followFile + fd, err := os.Create(followFile) + if err != nil { + t.Error(err) + } + defer fd.Close() + + go func() { + var circular int + for { + select { + case <-ctx.Done(): + return + case <-time.After(time.Second): + fd.WriteString(time.Now().String()) + fd.WriteString(fmt.Sprintf(" - Hello %s!\n", greetings[circular])) + circular = (circular + 1) % len(greetings) + } + } + }() + */ + + /* + os.Remove(serverStdoutFile) + os.Remove(clientStdoutFile) + os.Remove(followFile) + */ +} + func TestDTailColorTable(t *testing.T) { stdoutFile := "dtailcolortable.stdout.tmp" expectedStdoutFile := "dtailcolortable.expected" - args := []string{"-colorTable"} - if _, err := runCommand(t, "../dtail", args, stdoutFile); err != nil { + _, err := runCommand(context.TODO(), stdoutFile, "../dtail", "--colorTable") + if err != nil { t.Error(err) return } -- cgit v1.2.3 From c0f4ebc9b3773c37e22c686024c8cc7ce4e71f9f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 11 Oct 2021 11:51:30 +0300 Subject: add dtail integration test --- integrationtests/dtail_test.go | 103 ++++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 38 deletions(-) (limited to 'integrationtests/dtail_test.go') diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go index 267cd26..79b5881 100644 --- a/integrationtests/dtail_test.go +++ b/integrationtests/dtail_test.go @@ -2,18 +2,31 @@ package integrationtests import ( "context" + "fmt" "os" + "strings" "testing" + "time" ) +// TODO: Have a serverless variant too. func TestDTailWithServer(t *testing.T) { followFile := "dtail.follow.tmp" - //serverStdoutFile := "dtail.dserver.stdout.tmp" - //greetings := []string{"world", "sol system", "milky way", "universe", "multiverse"} + greetings := []string{"world!", "sol-system!", "milky-way!", "universe!", "multiverse!"} ctx, cancel := context.WithCancel(context.Background()) defer cancel() + go func() { + select { + case <-time.After(time.Minute): + t.Error("Max time for this test exceeded!") + cancel() + case <-ctx.Done(): + return + } + }() + serverCh, _, _, err := startCommand(ctx, "../dserver", "--logger", "stdout", @@ -40,55 +53,69 @@ func TestDTailWithServer(t *testing.T) { t.Error(err) return } + // Write greetings to followFile + fd, err := os.Create(followFile) + if err != nil { + t.Error(err) + } + defer fd.Close() + + go func() { + var circular int + for { + select { + case <-time.After(time.Second): + fd.WriteString(time.Now().String()) + fd.WriteString(fmt.Sprintf(" - Hello %s\n", greetings[circular])) + circular = (circular + 1) % len(greetings) + case <-ctx.Done(): + return + } + } + }() + + var greetingsRecv []string - for { + for len(greetingsRecv) < len(greetings) { select { case line := <-serverCh: t.Log("server:", line) case line := <-clientCh: t.Log("client:", line) + if strings.Contains(line, "Hello ") { + s := strings.Split(line, " ") + greeting := s[len(s)-1] + greetingsRecv = append(greetingsRecv, greeting) + t.Log("Received greeting", greeting, len(greetingsRecv)) + } case <-ctx.Done(): t.Log("Done reading client and server pipes") } } - /* - // Start dtail client, connect to the server and follow followFile. - - //clientStdoutFile := "dtail.stdout.tmp" - /* - - t.Log(clientArgs) - // TODO: Pipe with dtail command to read stdin stream. - // runCommandContextRetry(ctx, t, "../dtail", clientArgs, clientStdoutFile) - - // Write greetings to followFile - fd, err := os.Create(followFile) - if err != nil { - t.Error(err) - } - defer fd.Close() + // We expect to have received the greetings in the same order they were sent.` + offset := -1 + for i, g := range greetings { + if g == greetingsRecv[0] { + offset = i + break + } + } + if offset == -1 { + t.Error("Could not find first offset of greetings received") + return + } - go func() { - var circular int - for { - select { - case <-ctx.Done(): - return - case <-time.After(time.Second): - fd.WriteString(time.Now().String()) - fd.WriteString(fmt.Sprintf(" - Hello %s!\n", greetings[circular])) - circular = (circular + 1) % len(greetings) - } - } - }() - */ + for i, g := range greetingsRecv { + index := (i + offset) % len(greetings) + if greetings[index] != g { + t.Error(fmt.Sprintf("Expected '%s' but got '%s' at '%v' vs '%v'\n", + g, greetings[index], greetings, greetingsRecv)) + return + } + } - /* - os.Remove(serverStdoutFile) - os.Remove(clientStdoutFile) - os.Remove(followFile) - */ + os.Remove(followFile) } func TestDTailColorTable(t *testing.T) { -- cgit v1.2.3 From 7b873100d94ddc3c698a620cb83b61dcb2074303 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 13 Oct 2021 09:00:03 +0300 Subject: add another dcat integration test - catting 100 files at once --- integrationtests/dtail_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'integrationtests/dtail_test.go') diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go index 79b5881..8e932a1 100644 --- a/integrationtests/dtail_test.go +++ b/integrationtests/dtail_test.go @@ -27,7 +27,7 @@ func TestDTailWithServer(t *testing.T) { } }() - serverCh, _, _, err := startCommand(ctx, + serverCh, _, _, err := startCommand(ctx, t, "../dserver", "--logger", "stdout", "--logLevel", "info", @@ -39,7 +39,7 @@ func TestDTailWithServer(t *testing.T) { return } - clientCh, _, _, err := startCommand(ctx, + clientCh, _, _, err := startCommand(ctx, t, "../dtail", "--logger", "stdout", "--logLevel", "devel", @@ -122,7 +122,7 @@ func TestDTailColorTable(t *testing.T) { stdoutFile := "dtailcolortable.stdout.tmp" expectedStdoutFile := "dtailcolortable.expected" - _, err := runCommand(context.TODO(), stdoutFile, "../dtail", "--colorTable") + _, err := runCommand(context.TODO(), t, stdoutFile, "../dtail", "--colorTable") if err != nil { t.Error(err) return -- cgit v1.2.3 From 06ece112c0dd20c0c211c538216fe64ebe4045c9 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 14 Oct 2021 20:10:55 +0300 Subject: add dgrep context integration tests --- integrationtests/dtail_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'integrationtests/dtail_test.go') diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go index 8e932a1..f180b8a 100644 --- a/integrationtests/dtail_test.go +++ b/integrationtests/dtail_test.go @@ -30,7 +30,7 @@ func TestDTailWithServer(t *testing.T) { serverCh, _, _, err := startCommand(ctx, t, "../dserver", "--logger", "stdout", - "--logLevel", "info", + "--logLevel", "trace", "--port", "4242", "--relaxedAuth", ) @@ -42,7 +42,7 @@ func TestDTailWithServer(t *testing.T) { clientCh, _, _, err := startCommand(ctx, t, "../dtail", "--logger", "stdout", - "--logLevel", "devel", + "--logLevel", "trace", "--servers", "localhost:4242", "--files", followFile, "--grep", "Hello", -- cgit v1.2.3 From 698fb76b98c46c677abe13fdc93afc6c4f38c39e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 14 Oct 2021 20:55:35 +0300 Subject: refactor --- integrationtests/dtail_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'integrationtests/dtail_test.go') diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go index f180b8a..811f357 100644 --- a/integrationtests/dtail_test.go +++ b/integrationtests/dtail_test.go @@ -31,7 +31,7 @@ func TestDTailWithServer(t *testing.T) { "../dserver", "--logger", "stdout", "--logLevel", "trace", - "--port", "4242", + "--port", "4243", "--relaxedAuth", ) if err != nil { @@ -43,7 +43,7 @@ func TestDTailWithServer(t *testing.T) { "../dtail", "--logger", "stdout", "--logLevel", "trace", - "--servers", "localhost:4242", + "--servers", "localhost:4243", "--files", followFile, "--grep", "Hello", "--trustAllHosts", -- cgit v1.2.3 From b27fc108ecd6eead5c97cf6e894bf8d639fff75c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 15 Oct 2021 13:06:18 +0300 Subject: Execute test directories individually --- integrationtests/dtail_test.go | 1 + 1 file changed, 1 insertion(+) (limited to 'integrationtests/dtail_test.go') diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go index 811f357..a03056c 100644 --- a/integrationtests/dtail_test.go +++ b/integrationtests/dtail_test.go @@ -31,6 +31,7 @@ func TestDTailWithServer(t *testing.T) { "../dserver", "--logger", "stdout", "--logLevel", "trace", + "--bindAddress", "localhost", "--port", "4243", "--relaxedAuth", ) -- cgit v1.2.3 From 10314cef906fd9b73e003be69c2f6b7b3d66570c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 15 Oct 2021 13:20:48 +0300 Subject: Can configure DTail client not to mess with ~/.ssh/known_hosts via env var - this is useful for running unit and integration tests in jenkins --- integrationtests/dtail_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'integrationtests/dtail_test.go') diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go index a03056c..4af7401 100644 --- a/integrationtests/dtail_test.go +++ b/integrationtests/dtail_test.go @@ -9,7 +9,6 @@ import ( "time" ) -// TODO: Have a serverless variant too. func TestDTailWithServer(t *testing.T) { followFile := "dtail.follow.tmp" greetings := []string{"world!", "sol-system!", "milky-way!", "universe!", "multiverse!"} @@ -40,6 +39,8 @@ func TestDTailWithServer(t *testing.T) { return } + // TODO: In testmode, the client should not try to manipulate any known_hosts files. + // TODO: In testmode, never read a config file (use none for all commands) clientCh, _, _, err := startCommand(ctx, t, "../dtail", "--logger", "stdout", @@ -91,6 +92,7 @@ func TestDTailWithServer(t *testing.T) { } case <-ctx.Done(): t.Log("Done reading client and server pipes") + break } } -- cgit v1.2.3 From 860c41441b3bcf542b5701ae2257812879ce47b4 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 19 Oct 2021 19:01:12 +0300 Subject: Set DTAIL_RUN_INTEGRATIONT_TEST to yes for integration tests --- integrationtests/dtail_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'integrationtests/dtail_test.go') diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go index 4af7401..c6d0107 100644 --- a/integrationtests/dtail_test.go +++ b/integrationtests/dtail_test.go @@ -7,9 +7,15 @@ import ( "strings" "testing" "time" + + "github.com/mimecast/dtail/internal/config" ) func TestDTailWithServer(t *testing.T) { + if !config.Env("DTAIL_RUN_INTEGRATION_TESTS") { + t.Log("Skipping") + return + } followFile := "dtail.follow.tmp" greetings := []string{"world!", "sol-system!", "milky-way!", "universe!", "multiverse!"} @@ -122,6 +128,10 @@ func TestDTailWithServer(t *testing.T) { } func TestDTailColorTable(t *testing.T) { + if !config.Env("DTAIL_RUN_INTEGRATION_TESTS") { + t.Log("Skipping") + return + } stdoutFile := "dtailcolortable.stdout.tmp" expectedStdoutFile := "dtailcolortable.expected" -- cgit v1.2.3