From 07bfa2c9f0634321bd41cd4e5665781a0706ca91 Mon Sep 17 00:00:00 2001 From: Tiago Peczenyj Date: Tue, 19 Nov 2024 12:11:12 +0100 Subject: [PATCH] fix encoding commin flags missing unknown compression --- commonflags.go | 7 ++-- commonflags_test.go | 86 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 commonflags_test.go diff --git a/commonflags.go b/commonflags.go index 44adcd6..3d70da8 100644 --- a/commonflags.go +++ b/commonflags.go @@ -22,6 +22,9 @@ const ( // Common flags compression for disabled compression. cfCmprNone = 0 << 29 + + // Common flags compression for unknown compression. + cfCmprUnknown = 1 << 29 ) // DataType represents the type of data for a value @@ -70,9 +73,9 @@ func EncodeCommonFlags(valueType DataType, compression CompressionType) uint32 { switch compression { case NoCompression: - // flags |= 0 + flags |= cfCmprNone case UnknownCompression: - // flags |= ? + flags |= cfCmprUnknown } return flags diff --git a/commonflags_test.go b/commonflags_test.go new file mode 100644 index 0000000..88ccc17 --- /dev/null +++ b/commonflags_test.go @@ -0,0 +1,86 @@ +package gocbcore + +import "testing" + +func (suite *UnitTestSuite) TestCommonFlags() { + type tCase struct { + name string + valueType DataType + compression CompressionType + } + + testCases := []tCase{ + { + name: "must return json type with unknown compression", + valueType: JSONType, + compression: UnknownCompression, + }, + { + name: "must return json type with no compression", + valueType: JSONType, + compression: NoCompression, + }, + { + name: "must return binary type with unknown compression", + valueType: BinaryType, + compression: UnknownCompression, + }, + { + name: "must return binary type with no compression", + valueType: BinaryType, + compression: NoCompression, + }, + { + name: "must return string type with unknown compression", + valueType: StringType, + compression: UnknownCompression, + }, + { + name: "must return string type with no compression", + valueType: StringType, + compression: NoCompression, + }, + // + // { + // name: "must return unknown type with unknown compression", + // valueType: UnknownType, + // compression: UnknownCompression, + // }, + // { + // name: "must return unknown type with no compression", + // valueType: UnknownType, + // compression: NoCompression, + // }, + } + + for _, tCase := range testCases { + suite.T().Run(tCase.name, func(te *testing.T) { + flags := EncodeCommonFlags(tCase.valueType, tCase.compression) + + valueType, compression := DecodeCommonFlags(flags) + + if tCase.valueType != valueType { + te.Errorf("wrong valueType (expects %v, got %v)", tCase.valueType, valueType) + } + + if tCase.compression != compression { + te.Errorf("wrong compression (expects %v, got %v)", tCase.compression, compression) + } + }) + } +} + +// func TestCommonFlags(t *testing.T) { +// t.Parallel() + +// t.Run("issue #10 unknown flag ignored", func(t *testing.T) { +// t.Parallel() + +// flags := gocbcore.EncodeCommonFlags(gocbcore.JSONType, gocbcore.UnknownCompression) + +// _, compression := gocbcore.DecodeCommonFlags(flags) + +// ass +// }) + +// }