github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libkbfs/cr_actions_test.go (about)

     1  // Copyright 2016 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  package libkbfs
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  
    11  	"github.com/keybase/client/go/kbfs/data"
    12  )
    13  
    14  func testPPS(s string) data.PathPartString {
    15  	return data.NewPathPartString(s, nil)
    16  }
    17  
    18  func TestCRActionsCollapseNoChange(t *testing.T) {
    19  	al := crActionList{
    20  		&copyUnmergedEntryAction{
    21  			testPPS("old1"), testPPS("new1"), testPPS(""), false, false,
    22  			data.DirEntry{}, nil},
    23  		&copyUnmergedEntryAction{
    24  			testPPS("old2"), testPPS("new2"), testPPS(""), false, false,
    25  			data.DirEntry{}, nil},
    26  		&renameUnmergedAction{
    27  			testPPS("old3"), testPPS("new3"), testPPS(""), 0, false,
    28  			data.ZeroPtr, data.ZeroPtr},
    29  		&renameMergedAction{testPPS("old4"), testPPS("new4"), testPPS("")},
    30  		&copyUnmergedAttrAction{
    31  			testPPS("old5"), testPPS("new5"), []attrChange{mtimeAttr}, false},
    32  	}
    33  
    34  	newList := al.collapse()
    35  	if !reflect.DeepEqual(al, newList) {
    36  		t.Errorf("Collapse returned different list: %v vs %v", al, newList)
    37  	}
    38  }
    39  
    40  func TestCRActionsCollapseEntry(t *testing.T) {
    41  	al := crActionList{
    42  		&copyUnmergedAttrAction{
    43  			testPPS("old"), testPPS("new"), []attrChange{mtimeAttr}, false},
    44  		&copyUnmergedEntryAction{
    45  			testPPS("old"), testPPS("new"), testPPS(""), false, false,
    46  			data.DirEntry{}, nil},
    47  		&renameUnmergedAction{
    48  			testPPS("old"), testPPS("new"), testPPS(""), 0, false, data.ZeroPtr,
    49  			data.ZeroPtr},
    50  	}
    51  
    52  	expected := crActionList{
    53  		al[2],
    54  	}
    55  
    56  	newList := al.collapse()
    57  	if !reflect.DeepEqual(expected, newList) {
    58  		t.Errorf("Collapse returned unexpected list: %v vs %v",
    59  			expected, newList)
    60  	}
    61  
    62  	// change the order
    63  	al = crActionList{al[1], al[2], al[0]}
    64  
    65  	newList = al.collapse()
    66  	if !reflect.DeepEqual(expected, newList) {
    67  		t.Errorf("Collapse returned unexpected list: %v vs %v",
    68  			expected, newList)
    69  	}
    70  
    71  	// Omit the top action this time
    72  	al = crActionList{al[0], al[2]}
    73  	expected = crActionList{al[0]}
    74  
    75  	newList = al.collapse()
    76  	if !reflect.DeepEqual(expected, newList) {
    77  		t.Errorf("Collapse returned unexpected list: %v vs %v",
    78  			expected, newList)
    79  	}
    80  }
    81  func TestCRActionsCollapseAttr(t *testing.T) {
    82  	al := crActionList{
    83  		&copyUnmergedAttrAction{
    84  			testPPS("old"), testPPS("new"), []attrChange{mtimeAttr}, false},
    85  		&copyUnmergedAttrAction{
    86  			testPPS("old"), testPPS("new"), []attrChange{exAttr}, false},
    87  		&copyUnmergedAttrAction{
    88  			testPPS("old"), testPPS("new"), []attrChange{mtimeAttr}, false},
    89  	}
    90  
    91  	expected := crActionList{
    92  		&copyUnmergedAttrAction{
    93  			testPPS("old"), testPPS("new"), []attrChange{mtimeAttr, exAttr},
    94  			false},
    95  	}
    96  
    97  	newList := al.collapse()
    98  	if !reflect.DeepEqual(expected, newList) {
    99  		t.Errorf("Collapse returned unexpected list: %v vs %v",
   100  			expected, newList)
   101  	}
   102  }