-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
relocate list and pages de-serialization functions (#4852)
relocate list and pages de-serialization functions #### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🧹 Tech Debt/Cleanup #### Issue(s) #4754 #### Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual - [x] ⚡ Unit test - [x] 💚 E2E
- Loading branch information
1 parent
30c4877
commit dbf10d1
Showing
16 changed files
with
1,370 additions
and
343 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package keys | ||
|
||
type Set map[string]struct{} | ||
|
||
func (ks Set) HasKey(key string) bool { | ||
if _, ok := ks[key]; ok { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
func (ks Set) Keys() []string { | ||
sliceKeys := make([]string, 0) | ||
|
||
for k := range ks { | ||
sliceKeys = append(sliceKeys, k) | ||
} | ||
|
||
return sliceKeys | ||
} | ||
|
||
func HasKeys(data map[string]any, keys ...string) bool { | ||
for _, k := range keys { | ||
if _, ok := data[k]; !ok { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
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,122 @@ | ||
package keys | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/alcionai/corso/src/internal/tester" | ||
) | ||
|
||
type KeySetTestSuite struct { | ||
tester.Suite | ||
} | ||
|
||
func TestKeySetTestSuite(t *testing.T) { | ||
suite.Run(t, &KeySetTestSuite{Suite: tester.NewUnitSuite(t)}) | ||
} | ||
|
||
func (suite *KeySetTestSuite) TestHasKey() { | ||
tests := []struct { | ||
name string | ||
keySet Set | ||
key string | ||
expect assert.BoolAssertionFunc | ||
}{ | ||
{ | ||
name: "key exists in the set", | ||
keySet: Set{"key1": {}, "key2": {}}, | ||
key: "key1", | ||
expect: assert.True, | ||
}, | ||
{ | ||
name: "key does not exist in the set", | ||
keySet: Set{"key1": {}, "key2": {}}, | ||
key: "nonexistent", | ||
expect: assert.False, | ||
}, | ||
{ | ||
name: "empty set", | ||
keySet: Set{}, | ||
key: "key", | ||
expect: assert.False, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
suite.Run(test.name, func() { | ||
test.expect(suite.T(), test.keySet.HasKey(test.key)) | ||
}) | ||
} | ||
} | ||
|
||
func (suite *KeySetTestSuite) TestKeys() { | ||
tests := []struct { | ||
name string | ||
keySet Set | ||
expect assert.ValueAssertionFunc | ||
}{ | ||
{ | ||
name: "non-empty set", | ||
keySet: Set{"key1": {}, "key2": {}}, | ||
expect: assert.NotEmpty, | ||
}, | ||
{ | ||
name: "empty set", | ||
keySet: Set{}, | ||
expect: assert.Empty, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
suite.Run(test.name, func() { | ||
keys := test.keySet.Keys() | ||
test.expect(suite.T(), keys, []string{"key1", "key2"}) | ||
}) | ||
} | ||
} | ||
|
||
func (suite *KeySetTestSuite) TestHasKeys() { | ||
tests := []struct { | ||
name string | ||
data map[string]any | ||
keys []string | ||
expect assert.BoolAssertionFunc | ||
}{ | ||
{ | ||
name: "has all keys", | ||
data: map[string]any{ | ||
"key1": "data1", | ||
"key2": 2, | ||
"key3": struct{}{}, | ||
}, | ||
keys: []string{"key1", "key2", "key3"}, | ||
expect: assert.True, | ||
}, | ||
{ | ||
name: "has some keys", | ||
data: map[string]any{ | ||
"key1": "data1", | ||
"key2": 2, | ||
}, | ||
keys: []string{"key1", "key2", "key3"}, | ||
expect: assert.False, | ||
}, | ||
{ | ||
name: "has no key", | ||
data: map[string]any{ | ||
"key1": "data1", | ||
"key2": 2, | ||
}, | ||
keys: []string{"key4", "key5", "key6"}, | ||
expect: assert.False, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
suite.Run(test.name, func() { | ||
test.expect(suite.T(), HasKeys(test.data, test.keys...)) | ||
}) | ||
} | ||
} |
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
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
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
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
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.