Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix encoding commin flags missing unknown compression #11

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions commonflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
86 changes: 86 additions & 0 deletions commonflags_test.go
Original file line number Diff line number Diff line change
@@ -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
// })

// }