Skip to content

Commit

Permalink
added unit test for function in mapper-thrift-configstore file (#5789)
Browse files Browse the repository at this point in the history
* added unit test for function in mapper-thrift-configstore file

* added license information

* renamed file to snake_case and add additional testcase for empty structs

---------

Co-authored-by: Zijian <[email protected]>
  • Loading branch information
d-vignesh and Shaddoll authored Mar 19, 2024
1 parent d60041f commit c521fa3
Show file tree
Hide file tree
Showing 2 changed files with 256 additions and 0 deletions.
205 changes: 205 additions & 0 deletions common/types/mapper/thrift/config_store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
// Copyright (c) 2021 Uber Technologies Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

package thrift

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/uber/cadence/common/types"
"github.com/uber/cadence/common/types/testdata"
)

func TestDynamicConfigBlob(t *testing.T) {
testCases := []struct {
desc string
input *types.DynamicConfigBlob
}{
{
desc: "non-nil input test",
input: &testdata.DynamicConfigBlob,
},
{
desc: "empty input test",
input: &types.DynamicConfigBlob{},
},
{
desc: "nil input test",
input: nil,
},
}
for _, tc := range testCases {
thriftObj := FromDynamicConfigBlob(tc.input)
roundTripObj := ToDynamicConfigBlob(thriftObj)
assert.Equal(t, tc.input, roundTripObj)
}
}

func TestDynamicConfigEntryArray(t *testing.T) {
testCase := []struct {
desc string
input []*types.DynamicConfigEntry
}{
{
desc: "non-nil input test",
input: []*types.DynamicConfigEntry{&testdata.DynamicConfigEntry},
},
{
desc: "empty input test",
input: []*types.DynamicConfigEntry{},
},
{
desc: "nil input test",
input: nil,
},
}
for _, tc := range testCase {
thriftObj := FromDynamicConfigEntryArray(tc.input)
roundTripObj := ToDynamicConfigEntryArray(thriftObj)
assert.Equal(t, tc.input, roundTripObj)
}
}

func TestDynamicConfigEntry(t *testing.T) {
testCases := []struct {
desc string
input *types.DynamicConfigEntry
}{
{
desc: "non-nil input test",
input: &testdata.DynamicConfigEntry,
},
{
desc: "empty input test",
input: &types.DynamicConfigEntry{},
},
{
desc: "nil input test",
input: nil,
},
}
for _, tc := range testCases {
thriftObj := FromDynamicConfigEntry(tc.input)
roundTripObj := ToDynamicConfigEntry(thriftObj)
assert.Equal(t, tc.input, roundTripObj)
}
}

func TestDynamicConfigValueArray(t *testing.T) {
testCases := []struct {
desc string
input []*types.DynamicConfigValue
}{
{
desc: "non-nil input test",
input: []*types.DynamicConfigValue{&testdata.DynamicConfigValue},
},
{
desc: "empty input test",
input: []*types.DynamicConfigValue{},
},
{
desc: "nil input test",
input: nil,
},
}
for _, tc := range testCases {
thriftObj := FromDynamicConfigValueArray(tc.input)
roundTripObj := ToDynamicConfigValueArray(thriftObj)
assert.Equal(t, tc.input, roundTripObj)
}
}

func TestDynamicConfigValue(t *testing.T) {
testCases := []struct {
desc string
input *types.DynamicConfigValue
}{
{
desc: "non-nil input test",
input: &testdata.DynamicConfigValue,
},
{
desc: "empty input test",
input: &types.DynamicConfigValue{},
},
{
desc: "nil input test",
input: nil,
},
}
for _, tc := range testCases {
thriftObj := FromDynamicConfigValue(tc.input)
roundTripObj := ToDynamicConfigValue(thriftObj)
assert.Equal(t, tc.input, roundTripObj)
}
}

func TestDynamicConfigFilterArray(t *testing.T) {
testCases := []struct {
desc string
input []*types.DynamicConfigFilter
}{
{
desc: "non-nil input test",
input: []*types.DynamicConfigFilter{&testdata.DynamicConfigFilter},
},
{
desc: "empty input test",
input: []*types.DynamicConfigFilter{},
},
{
desc: "nil input test",
input: nil,
},
}
for _, tc := range testCases {
thriftObj := FromDynamicConfigFilterArray(tc.input)
roundTripObj := ToDynamicConfigFilterArray(thriftObj)
assert.Equal(t, tc.input, roundTripObj)
}
}

func TestDynamicConfigFilter(t *testing.T) {
testCases := []struct {
desc string
input *types.DynamicConfigFilter
}{
{
desc: "non-nil input test",
input: &testdata.DynamicConfigFilter,
},
{
desc: "empty input test",
input: &types.DynamicConfigFilter{},
},
{
desc: "nil input test",
input: nil,
},
}
for _, tc := range testCases {
thriftObj := FromDynamicConfigFilter(tc.input)
roundTripObj := ToDynamicConfigFilter(thriftObj)
assert.Equal(t, tc.input, roundTripObj)
}
}
51 changes: 51 additions & 0 deletions common/types/testdata/config_store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2021 Uber Technologies Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

package testdata

import (
"github.com/uber/cadence/common/types"
)

const (
DynamicConfigValueName = "test_config"
DynamicConfigFilterName = "test_filter"
DynamicConfigEntryName = "test_entry"
DynamicConfigBlobSchemaVersion = int64(1)
)

var (
DynamicConfigFilter = types.DynamicConfigFilter{
Name: DynamicConfigFilterName,
Value: &DataBlob,
}
DynamicConfigValue = types.DynamicConfigValue{
Value: &DataBlob,
Filters: []*types.DynamicConfigFilter{&DynamicConfigFilter},
}
DynamicConfigEntry = types.DynamicConfigEntry{
Name: DynamicConfigEntryName,
Values: []*types.DynamicConfigValue{&DynamicConfigValue},
}
DynamicConfigBlob = types.DynamicConfigBlob{
SchemaVersion: DynamicConfigBlobSchemaVersion,
Entries: []*types.DynamicConfigEntry{&DynamicConfigEntry},
}
)

0 comments on commit c521fa3

Please sign in to comment.