From f3d28ae82ca64ee1e79b3dae54360ba6f0f378bb Mon Sep 17 00:00:00 2001 From: Injun Song Date: Fri, 13 Dec 2024 10:31:30 +0900 Subject: [PATCH 1/2] ci: add coverpkg flag to improve test coverage reporting - Updated Makefile to include the coverpkg flag in test_coverage and test_e2e_local_coverage targets. - Added commands to remove and recreate coverage directories to ensure clean coverage data. --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 01c4d5611..9299d9731 100644 --- a/Makefile +++ b/Makefile @@ -70,12 +70,12 @@ test: $(PYTEST) test_coverage: - mkdir $(COVDATA_DIR)/unit - $(GO) test $(TEST_FLAGS) -cover -covermode=atomic ./... -args -test.gocoverdir=$(COVDATA_DIR)/unit + rm -rf $(COVDATA_DIR)/unit && mkdir $(COVDATA_DIR)/unit + $(GO) test $(TEST_FLAGS) -cover -coverpkg ./... -covermode=atomic ./... -args -test.gocoverdir=$(COVDATA_DIR)/unit $(PYTEST) --cov=./ --cov-report=xml:$(PYTHON_COVERAGE_OUTPUT) generate_coverage_profile: - mkdir $(COVDATA_DIR)/merged + rm -rf $(COVDATA_DIR)/merged && mkdir $(COVDATA_DIR)/merged $(GO) tool covdata merge -i=$(COVDATA_DIR)/unit,$(COVDATA_DIR)/ee -o $(COVDATA_DIR)/merged $(GO) tool covdata textfmt -i=$(COVDATA_DIR)/merged -o $(GO_COVERAGE_OUTPUT_TMP) cat $(GO_COVERAGE_OUTPUT_TMP) | grep -v "_mock.go" | grep -v ".pb.go" > $(GO_COVERAGE_OUTPUT) @@ -88,8 +88,8 @@ generate_coverage_profile: # unnecessary to enter TEST_ARGS. TEST_ARGS := test_e2e_local_coverage: - make build COVERFLAGS="-cover -covermode=atomic" - mkdir $(COVDATA_DIR)/ee + make build COVERFLAGS="-cover -covermode=atomic -coverpkg ./..." + rm -rf $(COVDATA_DIR)/ee && mkdir $(COVDATA_DIR)/ee GOCOVERDIR=$(COVDATA_DIR)/ee $(GO) test $(TEST_FLAGS) ./tests/ee/... -tags=e2e $(TEST_ARGS) test_e2e_local: build From 36e61c6dd04e7995a4e8b1c5da04b220b037c432 Mon Sep 17 00:00:00 2001 From: Injun Song Date: Fri, 22 Nov 2024 09:21:11 +0900 Subject: [PATCH 2/2] test: add missing test for proto/snpb.ValidateTopicLogStream --- proto/snpb/log_io_test.go | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 proto/snpb/log_io_test.go diff --git a/proto/snpb/log_io_test.go b/proto/snpb/log_io_test.go new file mode 100644 index 000000000..caf060a8c --- /dev/null +++ b/proto/snpb/log_io_test.go @@ -0,0 +1,73 @@ +package snpb_test + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/kakao/varlog/pkg/types" + "github.com/kakao/varlog/proto/snpb" +) + +func TestValidateTopicLogStream(t *testing.T) { + type testMessage interface { + GetTopicID() types.TopicID + GetLogStreamID() types.LogStreamID + } + tcs := []struct { + msg testMessage + isErr bool + }{ + { + msg: &snpb.AppendRequest{ + TopicID: types.TopicID(1), + LogStreamID: types.LogStreamID(2), + }, + isErr: false, + }, + { + msg: &snpb.AppendRequest{ + TopicID: types.TopicID(0), + LogStreamID: types.LogStreamID(2), + }, + isErr: true, + }, + { + msg: &snpb.AppendRequest{ + TopicID: types.TopicID(-1), + LogStreamID: types.LogStreamID(2), + }, + isErr: true, + }, + { + msg: &snpb.AppendRequest{ + TopicID: types.TopicID(1), + LogStreamID: types.LogStreamID(0), + }, + isErr: true, + }, + { + msg: &snpb.AppendRequest{ + TopicID: types.TopicID(1), + LogStreamID: types.LogStreamID(-1), + }, + isErr: true, + }, + } + + for _, tc := range tcs { + name := "unknown" + if s, ok := tc.msg.(fmt.Stringer); ok { + name = s.String() + } + t.Run(name, func(t *testing.T) { + err := snpb.ValidateTopicLogStream(tc.msg) + if tc.isErr { + require.Error(t, err) + return + } + require.NoError(t, err) + }) + } +}