github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/test/teams_test.go (about)

     1  // Copyright 2017 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 test
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func TestTeamsTwoWriters(t *testing.T) {
    12  	test(t,
    13  		users("alice", "bob"),
    14  		team("ab", "alice,bob", ""),
    15  		inSingleTeamTlf("ab"),
    16  		as(alice,
    17  			mkfile("a", "hello"),
    18  		),
    19  		as(bob,
    20  			read("a", "hello"),
    21  			mkfile("b", "world"),
    22  		),
    23  		as(alice,
    24  			read("b", "world"),
    25  		),
    26  	)
    27  }
    28  
    29  func TestTeamsTwoWritersNonCanonical(t *testing.T) {
    30  	test(t,
    31  		users("alice", "bob"),
    32  		team("ab", "alice,bob", ""),
    33  		inSingleTeamNonCanonical("AB", "ab"),
    34  		as(alice,
    35  			mkfile("a", "hello"),
    36  		),
    37  		as(bob,
    38  			read("a", "hello"),
    39  			mkfile("b", "world"),
    40  		),
    41  		as(alice,
    42  			read("b", "world"),
    43  		),
    44  	)
    45  }
    46  
    47  func TestTeamsWriterReader(t *testing.T) {
    48  	test(t,
    49  		users("alice", "bob"),
    50  		team("a_b", "alice", "bob"),
    51  		inSingleTeamTlf("a_b"),
    52  		as(alice,
    53  			mkfile("a", "hello"),
    54  		),
    55  		as(bob,
    56  			read("a", "hello"),
    57  			expectError(mkfile("b", "world"),
    58  				"bob does not have write access to directory /keybase/team/a_b"),
    59  		),
    60  	)
    61  }
    62  
    63  func TestTeamsTwoWritersJournal(t *testing.T) {
    64  	test(t, journal(),
    65  		users("alice", "bob"),
    66  		team("ab", "alice,bob", ""),
    67  		inSingleTeamTlf("ab"),
    68  		as(alice,
    69  			// The tests don't support enabling journaling on a
    70  			// non-existent TLF, so force the TLF creation first.
    71  			mkfile("foo", "bar"),
    72  			rm("foo"),
    73  		),
    74  		as(alice,
    75  			enableJournal(),
    76  			mkfile("a", "hello"),
    77  		),
    78  		as(alice,
    79  			// Wait for the flush, after doing a SyncAll().
    80  			flushJournal(),
    81  		),
    82  		as(bob,
    83  			enableJournal(),
    84  			read("a", "hello"),
    85  			mkfile("b", "world"),
    86  		),
    87  		as(bob,
    88  			// Wait for the flush, after doing a SyncAll().
    89  			flushJournal(),
    90  		),
    91  		as(alice,
    92  			read("b", "world"),
    93  		),
    94  	)
    95  }
    96  
    97  func TestTeamsNameChange(t *testing.T) {
    98  	test(t,
    99  		users("alice", "bob"),
   100  		team("ab", "alice,bob", ""),
   101  		inSingleTeamTlf("ab"),
   102  		as(alice,
   103  			mkfile("a", "hello"),
   104  		),
   105  		as(bob,
   106  			read("a", "hello"),
   107  			mkfile("b", "world"),
   108  		),
   109  		as(alice,
   110  			read("b", "world"),
   111  		),
   112  		changeTeamName("ab", "ba"),
   113  		inSingleTeamTlf("ba"),
   114  		as(alice,
   115  			read("a", "hello"),
   116  			read("b", "world"),
   117  		),
   118  		as(bob,
   119  			read("a", "hello"),
   120  			read("b", "world"),
   121  		),
   122  	)
   123  }
   124  
   125  func TestSubteamsTwoWriters(t *testing.T) {
   126  	test(t,
   127  		users("alice", "bob"),
   128  		team("al", "alice", ""),
   129  		team("al.ab", "alice,bob", ""),
   130  		inSingleTeamTlf("al.ab"),
   131  		as(alice,
   132  			mkfile("a", "hello"),
   133  		),
   134  		as(bob,
   135  			read("a", "hello"),
   136  			mkfile("b", "world"),
   137  		),
   138  		as(alice,
   139  			read("b", "world"),
   140  		),
   141  	)
   142  }
   143  
   144  func TestSubteamsTwoWritersJournal(t *testing.T) {
   145  	test(t, journal(),
   146  		users("alice", "bob"),
   147  		team("al", "alice", ""),
   148  		team("al.ab", "alice,bob", ""),
   149  		inSingleTeamTlf("al.ab"),
   150  		as(alice,
   151  			// The tests don't support enabling journaling on a
   152  			// non-existent TLF, so force the TLF creation first.
   153  			mkfile("foo", "bar"),
   154  			rm("foo"),
   155  		),
   156  		as(alice,
   157  			enableJournal(),
   158  			mkfile("a", "hello"),
   159  		),
   160  		as(alice,
   161  			// Wait for the flush, after doing a SyncAll().
   162  			flushJournal(),
   163  		),
   164  		as(bob,
   165  			enableJournal(),
   166  			read("a", "hello"),
   167  			mkfile("b", "world"),
   168  		),
   169  		as(bob,
   170  			// Wait for the flush, after doing a SyncAll().
   171  			flushJournal(),
   172  		),
   173  		as(alice,
   174  			read("b", "world"),
   175  		),
   176  	)
   177  }