-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate metrika-streaming protoparser_test
Preparation for archive-export test. Move streaming test `.go` for separated file and its data to folder commit_hash:e9a831323c5a57a0b5e9973afb1b37afdb0f5319
- Loading branch information
Showing
8 changed files
with
262 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
256 changes: 256 additions & 0 deletions
256
pkg/parsers/registry/protobuf/protoparser/metrika_streaming_data_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,256 @@ | ||
package protoparser | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/doublecloud/transfer/pkg/abstract" | ||
"github.com/doublecloud/transfer/pkg/parsers" | ||
"github.com/doublecloud/transfer/pkg/parsers/registry/protobuf/protoscanner" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDoCloudStreamingExportHits(t *testing.T) { | ||
testCases := getCloudStreamingExportHitsTestCases(t) | ||
pMsg := parsers.Message{ | ||
Offset: 1, | ||
SeqNo: 1, | ||
Value: protoSampleContent(t, "metrika-streaming-data/metrika_cloud_export_hit_log_data.bin"), | ||
} | ||
|
||
for i, test := range testCases { | ||
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) { | ||
par, err := NewProtoParser(&test.conf, getSourceStatsMock()) | ||
require.NoError(t, err) | ||
|
||
actual := par.Do(pMsg, abstract.NewPartition("", 0)) | ||
|
||
unparsed := parsers.ExtractUnparsed(actual) | ||
if len(unparsed) > 0 { | ||
require.FailNow(t, "unexpected unparsed items", unparsed) | ||
} | ||
|
||
checkColsEqual(t, actual) | ||
|
||
for _, item := range actual { | ||
require.Equal(t, test.colsLen, len(item.ColumnNames)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func getCloudStreamingExportHitsTestCases(t *testing.T) []struct { | ||
conf ProtoParserConfig | ||
colsLen int | ||
} { | ||
|
||
res := []struct { | ||
conf ProtoParserConfig | ||
colsLen int | ||
}{ | ||
{ | ||
conf: ProtoParserConfig{}, | ||
colsLen: 92, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
IncludeColumns: []ColParams{ | ||
{ | ||
Name: "TransferID", | ||
Required: true, | ||
}, | ||
}, | ||
PrimaryKeys: []string{ | ||
"TransferID", | ||
"WatchID", | ||
}, | ||
}, | ||
colsLen: 2, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
IncludeColumns: []ColParams{ | ||
{ | ||
Name: "TransferID", | ||
Required: true, | ||
}, | ||
}, | ||
PrimaryKeys: []string{ | ||
"WatchID", | ||
}, | ||
}, | ||
colsLen: 2, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
IncludeColumns: []ColParams{ | ||
{ | ||
Name: "TransferID", | ||
Required: true, | ||
}, | ||
{ | ||
Name: "WatchID", | ||
Required: true, | ||
}, | ||
}, | ||
PrimaryKeys: []string{ | ||
"WatchID", | ||
}, | ||
}, | ||
colsLen: 2, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
IncludeColumns: []ColParams{ | ||
{ | ||
Name: "TransferID", | ||
Required: true, | ||
}, | ||
{ | ||
Name: "WatchID", | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
colsLen: 2, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
AddSyntheticKeys: true, | ||
}, | ||
colsLen: 95, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
AddSyntheticKeys: true, | ||
AddSystemColumns: true, | ||
}, | ||
colsLen: 97, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
IncludeColumns: []ColParams{ | ||
{ | ||
Name: "TransferID", | ||
Required: true, | ||
}, | ||
}, | ||
AddSyntheticKeys: true, | ||
}, | ||
colsLen: 4, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
IncludeColumns: []ColParams{ | ||
{ | ||
Name: "TransferID", | ||
Required: true, | ||
}, | ||
}, | ||
PrimaryKeys: []string{ | ||
"TransferID", | ||
}, | ||
AddSyntheticKeys: true, | ||
}, | ||
colsLen: 4, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
IncludeColumns: []ColParams{ | ||
{ | ||
Name: "TransferID", | ||
Required: true, | ||
}, | ||
}, | ||
PrimaryKeys: []string{ | ||
"WatchID", | ||
}, | ||
AddSyntheticKeys: true, | ||
}, | ||
colsLen: 5, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
PrimaryKeys: []string{ | ||
"WatchID", | ||
}, | ||
AddSyntheticKeys: true, | ||
}, | ||
colsLen: 95, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
IncludeColumns: []ColParams{ | ||
{ | ||
Name: "TransferID", | ||
Required: true, | ||
}, | ||
}, | ||
AddSyntheticKeys: true, | ||
AddSystemColumns: true, | ||
}, | ||
colsLen: 97, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
IncludeColumns: []ColParams{ | ||
{ | ||
Name: "TransferID", | ||
Required: true, | ||
}, | ||
}, | ||
PrimaryKeys: []string{ | ||
"TransferID", | ||
}, | ||
AddSyntheticKeys: true, | ||
AddSystemColumns: true, | ||
}, | ||
colsLen: 97, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
IncludeColumns: []ColParams{ | ||
{ | ||
Name: "TransferID", | ||
Required: true, | ||
}, | ||
}, | ||
PrimaryKeys: []string{ | ||
"TransferID", | ||
"WatchID", | ||
}, | ||
AddSyntheticKeys: true, | ||
AddSystemColumns: true, | ||
}, | ||
colsLen: 97, | ||
}, | ||
{ | ||
conf: ProtoParserConfig{ | ||
PrimaryKeys: []string{ | ||
"TransferID", | ||
}, | ||
AddSyntheticKeys: true, | ||
AddSystemColumns: true, | ||
}, | ||
colsLen: 97, | ||
}, | ||
} | ||
|
||
rootMsgDesc, err := extractMessageDesc( | ||
protoSampleContent(t, "metrika-streaming-data/metrika_cloud_export_hit_log.desc"), | ||
"CloudTransferHitList", | ||
) | ||
require.NoError(t, err) | ||
|
||
embeddedMsgDesc, ok := extractEmbeddedRepeatedMsgDesc(rootMsgDesc) | ||
require.True(t, ok) | ||
|
||
for i := range res { | ||
res[i].conf.ScannerMessageDesc = rootMsgDesc | ||
res[i].conf.ProtoMessageDesc = embeddedMsgDesc | ||
res[i].conf.ProtoScannerType = protoscanner.ScannerTypeRepeated | ||
res[i].conf.LineSplitter = abstract.LfLineSplitterDoNotSplit | ||
} | ||
|
||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.