Skip to content

Commit 72d6e5d

Browse files
committed
integration
1 parent 6ea9a95 commit 72d6e5d

12 files changed

Lines changed: 1097 additions & 7 deletions

File tree

.github/workflows/github-actions.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,8 @@ jobs:
8181
- name: Go Test
8282
run: make test
8383

84+
- name: Integration Test
85+
run: make integration
86+
8487
- name: Coverage
8588
run: bash <(curl -s https://codecov.io/bash)

Makefile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ check: license-check
1515
test:
1616
go test -v ./... -coverprofile=coverage.out -covermode=atomic
1717

18+
integration:
19+
go test -tags integration -v -timeout 120s ./integrations/...
20+
1821
clean-dist:
1922
mkdir -p dist
2023
rm -f dist/*.zip
@@ -41,10 +44,3 @@ local-tools:
4144
install: format check test
4245
go install logtail.go
4346

44-
remote-package: clean-dist
45-
rm -f ../logtail.zip
46-
zip ../logtail.zip -r *
47-
ssh root@$(LINUX_BUILD_SERVER) "rm -rf /go/logtail && rm -f /go/logtail.zip"
48-
scp ../logtail.zip root@$(LINUX_BUILD_SERVER):/go/logtail.zip
49-
ssh root@$(LINUX_BUILD_SERVER) "source /etc/profile && unzip -d /go/logtail /go/logtail.zip && cd /go/logtail && make package-linux"
50-
scp root@$(LINUX_BUILD_SERVER):/go/logtail/dist/logtail-$(version)-linux.zip dist/
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//go:build integration
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership.
7+
* The ASF licenses this file to You under the Apache License, Version 2.0
8+
* (the "License"); you may not use this file except in compliance with
9+
* the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
package cli_flags_test
21+
22+
import (
23+
"testing"
24+
"time"
25+
26+
"github.com/vogo/logtail/integrations/helper"
27+
)
28+
29+
func TestCLIFlags(t *testing.T) {
30+
binary := helper.BuildBinary(t)
31+
32+
t.Run("CmdAloneFails", func(t *testing.T) {
33+
proc := helper.RunLogtail(t, binary, "-cmd", "printf 'hello\n'")
34+
35+
if err := proc.Wait(5 * time.Second); err != nil {
36+
t.Fatalf("process did not exit: %v", err)
37+
}
38+
39+
if proc.ExitCode() == 0 {
40+
t.Error("expected non-zero exit code")
41+
}
42+
43+
helper.AssertStderrContains(t, proc, "router not exists")
44+
})
45+
46+
t.Run("CmdWithMatchContainsNoURLFails", func(t *testing.T) {
47+
proc := helper.RunLogtail(t, binary, "-cmd", "printf 'ERROR critical\n'", "-match-contains", "ERROR")
48+
49+
if err := proc.Wait(5 * time.Second); err != nil {
50+
t.Fatalf("process did not exit: %v", err)
51+
}
52+
53+
if proc.ExitCode() == 0 {
54+
t.Error("expected non-zero exit code")
55+
}
56+
57+
helper.AssertStderrContains(t, proc, "router id is nil")
58+
})
59+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//go:build integration
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership.
7+
* The ASF licenses this file to You under the Apache License, Version 2.0
8+
* (the "License"); you may not use this file except in compliance with
9+
* the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
package cmd_tail_console_test
21+
22+
import (
23+
"testing"
24+
"time"
25+
26+
"github.com/vogo/logtail/integrations/helper"
27+
)
28+
29+
func TestCmdTailConsole(t *testing.T) {
30+
binary := helper.BuildBinary(t)
31+
dir := helper.TempDir(t, "cmd-tail-console")
32+
33+
config := map[string]any{
34+
"loglevel": "ERROR",
35+
"transfers": map[string]any{
36+
"console": map[string]any{
37+
"type": "console",
38+
},
39+
},
40+
"routers": map[string]any{
41+
"all": map[string]any{
42+
"transfers": []string{"console"},
43+
},
44+
},
45+
"servers": map[string]any{
46+
"s1": map[string]any{
47+
"command": "printf 'hello logtail\\n'",
48+
"routers": []string{"all"},
49+
},
50+
},
51+
}
52+
53+
configPath := helper.WriteConfig(t, dir, config)
54+
proc := helper.RunLogtail(t, binary, "-file", configPath)
55+
56+
time.Sleep(3 * time.Second)
57+
proc.Stop()
58+
59+
helper.AssertStdoutContains(t, proc, "hello logtail")
60+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//go:build integration
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership.
7+
* The ASF licenses this file to You under the Apache License, Version 2.0
8+
* (the "License"); you may not use this file except in compliance with
9+
* the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
package cmd_tail_file_transfer_test
21+
22+
import (
23+
"os"
24+
"path/filepath"
25+
"testing"
26+
"time"
27+
28+
"github.com/vogo/logtail/integrations/helper"
29+
)
30+
31+
func TestCmdTailFileTransfer(t *testing.T) {
32+
binary := helper.BuildBinary(t)
33+
dir := helper.TempDir(t, "cmd-tail-file")
34+
35+
outputDir := filepath.Join(dir, "output")
36+
if err := os.MkdirAll(outputDir, 0o755); err != nil {
37+
t.Fatal(err)
38+
}
39+
40+
config := map[string]any{
41+
"loglevel": "ERROR",
42+
"transfers": map[string]any{
43+
"file-out": map[string]any{
44+
"type": "file",
45+
"dir": outputDir,
46+
},
47+
},
48+
"routers": map[string]any{
49+
"all": map[string]any{
50+
"transfers": []string{"file-out"},
51+
},
52+
},
53+
"servers": map[string]any{
54+
"s1": map[string]any{
55+
"command": "printf 'line1\\nline2\\nline3\\n'",
56+
"routers": []string{"all"},
57+
},
58+
},
59+
}
60+
61+
configPath := helper.WriteConfig(t, dir, config)
62+
proc := helper.RunLogtail(t, binary, "-file", configPath)
63+
64+
time.Sleep(3 * time.Second)
65+
proc.Stop()
66+
67+
filePath := helper.AssertFileExists(t, outputDir, "file-out-")
68+
helper.AssertFileContains(t, filePath, "line1")
69+
helper.AssertFileContains(t, filePath, "line2")
70+
helper.AssertFileContains(t, filePath, "line3")
71+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//go:build integration
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership.
7+
* The ASF licenses this file to You under the Apache License, Version 2.0
8+
* (the "License"); you may not use this file except in compliance with
9+
* the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
package cmd_tail_match_filter_test
21+
22+
import (
23+
"testing"
24+
"time"
25+
26+
"github.com/vogo/logtail/integrations/helper"
27+
)
28+
29+
func TestCmdTailMatchFilter(t *testing.T) {
30+
binary := helper.BuildBinary(t)
31+
dir := helper.TempDir(t, "cmd-tail-match")
32+
33+
config := map[string]any{
34+
"loglevel": "ERROR",
35+
"transfers": map[string]any{
36+
"console": map[string]any{
37+
"type": "console",
38+
},
39+
},
40+
"routers": map[string]any{
41+
"error-only": map[string]any{
42+
"transfers": []string{"console"},
43+
"matchers": []map[string]any{
44+
{
45+
"contains": []string{"ERROR"},
46+
"notcontains": []string{"IGNORE"},
47+
},
48+
},
49+
},
50+
},
51+
"servers": map[string]any{
52+
"s1": map[string]any{
53+
"command": "printf '2024-01-01 ERROR real-error\\n2024-01-01 INFO normal-info\\n2024-01-01 ERROR IGNORE skip-this\\n'",
54+
"routers": []string{"error-only"},
55+
},
56+
},
57+
}
58+
59+
configPath := helper.WriteConfig(t, dir, config)
60+
proc := helper.RunLogtail(t, binary, "-file", configPath)
61+
62+
time.Sleep(2 * time.Second)
63+
proc.Stop()
64+
65+
helper.AssertStdoutContains(t, proc, "real-error")
66+
helper.AssertStdoutNotContains(t, proc, "normal-info")
67+
helper.AssertStdoutNotContains(t, proc, "skip-this")
68+
}

0 commit comments

Comments
 (0)