@ -30,134 +30,134 @@ func TestMergeSnapshots(t *testing.T) {
name : "first-nil" ,
s1 : nil ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) ,
} ) ,
want : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) ,
} ) ,
} ,
{
name : "first-empty" ,
s1 : NewSnapshot ( map [ Key ] RawItem { } ) ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} ) ,
want : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} ) ,
} ,
{
name : "second-nil" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) ,
} ) ,
s2 : nil ,
want : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) ,
} ) ,
} ,
{
name : "second-empty" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} ) ,
s2 : NewSnapshot ( map [ Key ] RawItem { } ) ,
want : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} ) ,
} ,
{
name : "no-conflicts" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} ) ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting4" : { value : 2 * time . Hour } ,
"Setting5" : { value : VisibleByPolicy } ,
"Setting6" : { value : ShowChoiceByPolicy } ,
"Setting4" : RawItemOf ( 2 * time . Hour ) ,
"Setting5" : RawItemOf ( VisibleByPolicy ) ,
"Setting6" : RawItemOf ( ShowChoiceByPolicy ) ,
} ) ,
want : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting4" : { value : 2 * time . Hour } ,
"Setting5" : { value : VisibleByPolicy } ,
"Setting6" : { value : ShowChoiceByPolicy } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
"Setting4" : RawItemOf ( 2 * time . Hour ) ,
"Setting5" : RawItemOf ( VisibleByPolicy ) ,
"Setting6" : RawItemOf ( ShowChoiceByPolicy ) ,
} ) ,
} ,
{
name : "with-conflicts" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) ,
} ) ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 456 } ,
"Setting3" : { value : false } ,
"Setting4" : { value : 2 * time . Hour } ,
"Setting1" : RawItemOf ( 456 ) ,
"Setting3" : RawItemOf ( false ) ,
"Setting4" : RawItemOf ( 2 * time . Hour ) ,
} ) ,
want : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 456 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting4" : { value : 2 * time . Hour } ,
"Setting1" : RawItemOf ( 456 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
"Setting4" : RawItemOf ( 2 * time . Hour ) ,
} ) ,
} ,
{
name : "with-scope-first-wins" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) ,
} , DeviceScope ) ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 456 } ,
"Setting3" : { value : false } ,
"Setting4" : { value : 2 * time . Hour } ,
"Setting1" : RawItemOf ( 456 ) ,
"Setting3" : RawItemOf ( false ) ,
"Setting4" : RawItemOf ( 2 * time . Hour ) ,
} , CurrentUserScope ) ,
want : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } ,
"Setting4" : { value : 2 * time . Hour } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) ,
"Setting4" : RawItemOf ( 2 * time . Hour ) ,
} , CurrentUserScope ) ,
} ,
{
name : "with-scope-second-wins" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) ,
} , CurrentUserScope ) ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 456 } ,
"Setting3" : { value : false } ,
"Setting4" : { value : 2 * time . Hour } ,
"Setting1" : RawItemOf ( 456 ) ,
"Setting3" : RawItemOf ( false ) ,
"Setting4" : RawItemOf ( 2 * time . Hour ) ,
} , DeviceScope ) ,
want : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 456 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting4" : { value : 2 * time . Hour } ,
"Setting1" : RawItemOf ( 456 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
"Setting4" : RawItemOf ( 2 * time . Hour ) ,
} , CurrentUserScope ) ,
} ,
{
@ -170,28 +170,27 @@ func TestMergeSnapshots(t *testing.T) {
name : "with-scope-first-empty" ,
s1 : NewSnapshot ( map [ Key ] RawItem { } , CurrentUserScope ) ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } } ,
DeviceScope , NewNamedOrigin ( "TestPolicy" , DeviceScope ) ) ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) } , DeviceScope , NewNamedOrigin ( "TestPolicy" , DeviceScope ) ) ,
want : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) ,
} , CurrentUserScope , NewNamedOrigin ( "TestPolicy" , DeviceScope ) ) ,
} ,
{
name : "with-scope-second-empty" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) ,
} , CurrentUserScope ) ,
s2 : NewSnapshot ( map [ Key ] RawItem { } ) ,
want : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) ,
} , CurrentUserScope ) ,
} ,
}
@ -244,9 +243,9 @@ func TestSnapshotEqual(t *testing.T) {
name : "first-nil" ,
s1 : nil ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} ) ,
wantEqual : false ,
wantEqualItems : false ,
@ -255,9 +254,9 @@ func TestSnapshotEqual(t *testing.T) {
name : "first-empty" ,
s1 : NewSnapshot ( map [ Key ] RawItem { } ) ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} ) ,
wantEqual : false ,
wantEqualItems : false ,
@ -265,9 +264,9 @@ func TestSnapshotEqual(t *testing.T) {
{
name : "second-nil" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : true } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( true ) ,
} ) ,
s2 : nil ,
wantEqual : false ,
@ -276,9 +275,9 @@ func TestSnapshotEqual(t *testing.T) {
{
name : "second-empty" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} ) ,
s2 : NewSnapshot ( map [ Key ] RawItem { } ) ,
wantEqual : false ,
@ -287,14 +286,14 @@ func TestSnapshotEqual(t *testing.T) {
{
name : "same-items-same-order-no-scope" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} ) ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} ) ,
wantEqual : true ,
wantEqualItems : true ,
@ -302,14 +301,14 @@ func TestSnapshotEqual(t *testing.T) {
{
name : "same-items-same-order-same-scope" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} , DeviceScope ) ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} , DeviceScope ) ,
wantEqual : true ,
wantEqualItems : true ,
@ -317,14 +316,14 @@ func TestSnapshotEqual(t *testing.T) {
{
name : "same-items-different-order-same-scope" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} , DeviceScope ) ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting3" : { value : false } ,
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : RawItemOf ( false ) ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
} , DeviceScope ) ,
wantEqual : true ,
wantEqualItems : true ,
@ -332,14 +331,14 @@ func TestSnapshotEqual(t *testing.T) {
{
name : "same-items-same-order-different-scope" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} , DeviceScope ) ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} , CurrentUserScope ) ,
wantEqual : false ,
wantEqualItems : true ,
@ -347,14 +346,14 @@ func TestSnapshotEqual(t *testing.T) {
{
name : "different-items-same-scope" ,
s1 : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 123 } ,
"Setting2" : { value : "String" } ,
"Setting3" : { value : false } ,
"Setting1" : RawItemOf ( 123 ) ,
"Setting2" : RawItemOf ( "String" ) ,
"Setting3" : RawItemOf ( false ) ,
} , DeviceScope ) ,
s2 : NewSnapshot ( map [ Key ] RawItem {
"Setting4" : { value : 2 * time . Hour } ,
"Setting5" : { value : VisibleByPolicy } ,
"Setting6" : { value : ShowChoiceByPolicy } ,
"Setting4" : RawItemOf ( 2 * time . Hour ) ,
"Setting5" : RawItemOf ( VisibleByPolicy ) ,
"Setting6" : RawItemOf ( ShowChoiceByPolicy ) ,
} , DeviceScope ) ,
wantEqual : false ,
wantEqualItems : false ,
@ -401,9 +400,9 @@ func TestSnapshotString(t *testing.T) {
{
name : "non-empty" ,
snapshot : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 2 * time . Hour } ,
"Setting2" : { value : VisibleByPolicy } ,
"Setting3" : { value : ShowChoiceByPolicy } ,
"Setting1" : RawItemOf ( 2 * time . Hour ) ,
"Setting2" : RawItemOf ( VisibleByPolicy ) ,
"Setting3" : RawItemOf ( ShowChoiceByPolicy ) ,
} , NewNamedOrigin ( "Test Policy" , DeviceScope ) ) ,
wantString : ` { Test Policy ( Device ) }
Setting1 = 2 h0m0s
@ -413,14 +412,14 @@ Setting3 = user-decides`,
{
name : "non-empty-with-item-origin" ,
snapshot : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { value : 42 , origin : NewNamedOrigin ( "Test Policy" , DeviceScope ) } ,
"Setting1" : RawItemWith ( 42 , nil , NewNamedOrigin ( "Test Policy" , DeviceScope ) ) ,
} ) ,
wantString : ` Setting1 = 42 - { Test Policy (Device)} ` ,
} ,
{
name : "non-empty-with-item-error" ,
snapshot : NewSnapshot ( map [ Key ] RawItem {
"Setting1" : { err : NewErrorText ( "bang!" ) } ,
"Setting1" : RawItemWith ( nil , NewErrorText ( "bang!" ) , nil ) ,
} ) ,
wantString : ` Setting1 = Error { "bang!"} ` ,
} ,