Skip to content

Commit 508ed8d

Browse files
committed
Merge remote-tracking branch 'origin/dev'
2 parents f5e7af9 + 2bd080e commit 508ed8d

File tree

385 files changed

+73387
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

385 files changed

+73387
-87
lines changed

.github/workflows/ci.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
PBM_BRANCH: ${{ github.event.inputs.pbm_branch || 'main' }}
3939
GO_VER: ${{ github.event.inputs.go_ver || '1.22-bullseye' }}
4040
PR_NUMBER: ${{ github.event.number|| github.event.inputs.pr_ver }}
41-
41+
MAKE_TARGET: 'build-cover'
4242
steps:
4343
- name: Checkout testing repo
4444
uses: actions/checkout@v4
@@ -58,8 +58,50 @@ jobs:
5858
docker compose run test pytest -s --junitxml=junit.xml -k ${{ matrix.test }}
5959
working-directory: psmdb-testing/pbm-functional/pytest
6060

61+
- name: Fetch coverage files
62+
run: |
63+
docker compose run --rm golang_reports cp -r /gocoverdir/reports /test
64+
sudo chmod -R 777 reports
65+
working-directory: psmdb-testing/pbm-functional/pytest
66+
if: success() || failure()
67+
68+
- name: Upload coverage reports
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: reports-${{ matrix.test }}-${{ matrix.psmdb }}
72+
path: psmdb-testing/pbm-functional/pytest/reports/
73+
if: success() || failure()
74+
6175
- name: Publish Test Report
6276
uses: mikepenz/action-junit-report@v4
6377
if: success() || failure()
6478
with:
6579
report_paths: "**/junit.xml"
80+
81+
coverage:
82+
if: ${{ always() }}
83+
needs: test
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v4
87+
- name: Set up Go
88+
uses: actions/setup-go@v5
89+
with:
90+
go-version-file: 'go.mod'
91+
check-latest: true
92+
- name: Download all coverage reports
93+
uses: actions/download-artifact@v4
94+
with:
95+
path: reports
96+
pattern: reports-*
97+
merge-multiple: true
98+
- name: Merge coverage reports
99+
run: |
100+
go tool covdata textfmt -i=./reports -o ./coverage.txt
101+
- name: Upload coverage to Codecov
102+
uses: codecov/codecov-action@v3
103+
with:
104+
files: ./coverage.txt
105+
flags: integration
106+
fail_ci_if_error: false
107+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ jobs:
2121
uses: codecov/codecov-action@v4
2222
with:
2323
file: cover.out
24+
flags: unittests
2425
fail_ci_if_error: false
2526
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/reviewdog.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
uses: codecov/codecov-action@v4
1717
with:
1818
file: cover.out
19+
flags: unittests
1920
fail_ci_if_error: false
2021
token: ${{ secrets.CODECOV_TOKEN }}
2122

cmd/pbm-agent/commands_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"os"
6+
"strings"
7+
"testing"
8+
9+
"github.com/spf13/cobra"
10+
11+
"github.com/percona/percona-backup-mongodb/pbm/version"
12+
)
13+
14+
func TestRootCmd_NoArgs(t *testing.T) {
15+
rootCmd, _ := setupTestCmd()
16+
err := rootCmd.Execute()
17+
if err == nil || !strings.Contains(err.Error(), "required flag mongodb-uri") {
18+
t.Fatal(err)
19+
}
20+
}
21+
22+
func TestRootCmd_Config(t *testing.T) {
23+
tmpConfig, cleanup := createTempConfigFile(`
24+
log:
25+
path: "/dev/stderr"
26+
level: "D"
27+
json: false
28+
`)
29+
defer cleanup()
30+
31+
rootCmd, _ := setupTestCmd("--config", tmpConfig)
32+
err := rootCmd.Execute()
33+
if err == nil || !strings.Contains(err.Error(), "required flag mongodb-uri") {
34+
t.Fatal(err)
35+
}
36+
}
37+
38+
func createTempConfigFile(content string) (string, func()) {
39+
temp, _ := os.CreateTemp("", "test-config-*.yaml")
40+
41+
_, _ = temp.WriteString(content)
42+
_ = temp.Close()
43+
44+
return temp.Name(), func() {
45+
_ = os.Remove(temp.Name())
46+
}
47+
}
48+
49+
func TestVersionCommand_Default(t *testing.T) {
50+
rootCmd, buf := setupTestCmd("version")
51+
err := rootCmd.Execute()
52+
if err != nil {
53+
t.Fatal(err)
54+
}
55+
56+
output := buf.String()
57+
58+
if !strings.Contains(output, "Version:") {
59+
t.Errorf("expected full version info in output, got: %s", output)
60+
}
61+
}
62+
63+
func TestVersionCommand_Short(t *testing.T) {
64+
rootCmd, buf := setupTestCmd("version", "--short")
65+
err := rootCmd.Execute()
66+
if err != nil {
67+
t.Fatal(err)
68+
}
69+
70+
output := buf.String()
71+
72+
if !strings.Contains(output, version.Current().Short()) {
73+
t.Errorf("expected short version info in output, got: %s", output)
74+
}
75+
}
76+
77+
func setupTestCmd(args ...string) (*cobra.Command, *bytes.Buffer) {
78+
cmd := rootCommand()
79+
cmd.AddCommand(versionCommand())
80+
81+
var buf bytes.Buffer
82+
cmd.SetOut(&buf)
83+
cmd.SetErr(&buf)
84+
cmd.SetArgs(args)
85+
86+
return cmd, &buf
87+
}

0 commit comments

Comments
 (0)