-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
1,319 additions
and
164 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
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,3 @@ | ||
package main | ||
|
||
// TODO: Implement me! |
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,155 @@ | ||
package model | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMerge(t *testing.T) { | ||
oldIndex := LegalHoldIndex{ | ||
"user1": { | ||
Username: "oldUser", | ||
Email: "[email protected]", | ||
Channels: []LegalHoldChannelMembership{ | ||
{"channel1", 1000, 2000}, | ||
{"channel3", 400, 4400}, | ||
}, | ||
}, | ||
"user2": { | ||
Username: "user2", | ||
Email: "[email protected]", | ||
Channels: []LegalHoldChannelMembership{ | ||
{"channel1", 1500, 2500}, | ||
{"channel2", 3000, 4000}, | ||
}, | ||
}, | ||
} | ||
|
||
newIndex := LegalHoldIndex{ | ||
"user1": { | ||
Username: "newUser", | ||
Email: "[email protected]", | ||
Channels: []LegalHoldChannelMembership{ | ||
{"channel1", 1500, 2500}, | ||
{"channel2", 3000, 4000}, | ||
}, | ||
}, | ||
"user3": { | ||
Username: "user3", | ||
Email: "[email protected]", | ||
Channels: []LegalHoldChannelMembership{ | ||
{"channel1", 1500, 2500}, | ||
{"channel2", 3000, 4000}, | ||
}, | ||
}, | ||
} | ||
|
||
expectedIndexAfterMerge := LegalHoldIndex{ | ||
"user1": { | ||
Username: "newUser", | ||
Email: "[email protected]", | ||
Channels: []LegalHoldChannelMembership{ | ||
{"channel1", 1000, 2500}, | ||
{"channel2", 3000, 4000}, | ||
{"channel3", 400, 4400}, | ||
}, | ||
}, | ||
"user2": { | ||
Username: "user2", | ||
Email: "[email protected]", | ||
Channels: []LegalHoldChannelMembership{ | ||
{"channel1", 1500, 2500}, | ||
{"channel2", 3000, 4000}, | ||
}, | ||
}, | ||
"user3": { | ||
Username: "user3", | ||
Email: "[email protected]", | ||
Channels: []LegalHoldChannelMembership{ | ||
{"channel1", 1500, 2500}, | ||
{"channel2", 3000, 4000}, | ||
}, | ||
}, | ||
} | ||
|
||
oldIndex.Merge(&newIndex) | ||
|
||
if !reflect.DeepEqual(oldIndex, expectedIndexAfterMerge) { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestGetLegalHoldChannelMembership(t *testing.T) { | ||
type args struct { | ||
channelMemberships []LegalHoldChannelMembership | ||
channelID string | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
args args | ||
wantLegalHoldChannelMembership LegalHoldChannelMembership | ||
wantFound bool | ||
}{ | ||
{ | ||
name: "Test Case 1: Membership exists", | ||
args: args{ | ||
channelMemberships: []LegalHoldChannelMembership{ | ||
{ChannelID: "ch1"}, | ||
{ChannelID: "ch2"}, | ||
}, | ||
channelID: "ch1", | ||
}, | ||
wantLegalHoldChannelMembership: LegalHoldChannelMembership{ChannelID: "ch1"}, | ||
wantFound: true, | ||
}, | ||
{ | ||
name: "Test Case 2: Membership does not exist", | ||
args: args{ | ||
channelMemberships: []LegalHoldChannelMembership{ | ||
{ChannelID: "ch1"}, | ||
{ChannelID: "ch2"}, | ||
}, | ||
channelID: "ch3", | ||
}, | ||
wantLegalHoldChannelMembership: LegalHoldChannelMembership{}, | ||
wantFound: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotLegalHoldChannelMembership, gotFound := getLegalHoldChannelMembership(tt.args.channelMemberships, tt.args.channelID) | ||
if gotLegalHoldChannelMembership != tt.wantLegalHoldChannelMembership { | ||
t.Errorf("getLegalHoldChannelMembership() got = %v, want %v", gotLegalHoldChannelMembership, tt.wantLegalHoldChannelMembership) | ||
} | ||
if gotFound != tt.wantFound { | ||
t.Errorf("getLegalHoldChannelMembership() got1 = %v, want %v", gotFound, tt.wantFound) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestLegalHoldChannelMembership_Combine(t *testing.T) { | ||
// Initialize a new LegalHoldChannelMembership instance | ||
lhcm1 := LegalHoldChannelMembership{ | ||
ChannelID: "testChannel1", | ||
StartTime: 10, | ||
EndTime: 20, | ||
} | ||
|
||
lhcm2 := LegalHoldChannelMembership{ | ||
ChannelID: "testChannel2", | ||
StartTime: 5, | ||
EndTime: 25, | ||
} | ||
|
||
// Combine the two instances | ||
lhcmCombined := lhcm1.Combine(lhcm2) | ||
|
||
require.Equal(t, lhcm1.ChannelID, lhcmCombined.ChannelID) | ||
require.Equal(t, int64(5), lhcmCombined.StartTime) | ||
require.Equal(t, int64(25), lhcmCombined.EndTime) | ||
} |
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.