github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/git/settings_test.go (about) 1 package git 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/keybase/client/go/chat/globals" 8 "github.com/keybase/client/go/kbtest" 9 "github.com/keybase/client/go/protocol/chat1" 10 "github.com/keybase/client/go/protocol/keybase1" 11 "github.com/keybase/client/go/teams" 12 "github.com/stretchr/testify/require" 13 ) 14 15 func TestSettings(t *testing.T) { 16 tc := SetupTest(t, "settings", 1) 17 defer tc.Cleanup() 18 19 u, err := kbtest.CreateAndSignupFakeUser("t", tc.G) 20 require.NoError(t, err) 21 22 teamName := u.Username + "t1" 23 _, err = teams.CreateRootTeam(context.Background(), tc.G, teamName, keybase1.TeamSettings{}) 24 require.NoError(t, err) 25 26 repoName := "repoName" 27 repoID := "abc123" 28 doPut(t, tc.G, teamName, repoID, repoName) 29 folder := keybase1.FolderHandle{ 30 Name: teamName, 31 FolderType: keybase1.FolderType_TEAM, 32 } 33 34 arg := keybase1.GetTeamRepoSettingsArg{ 35 Folder: folder, 36 RepoID: keybase1.RepoID(repoID), 37 } 38 settings, err := GetTeamRepoSettings(context.Background(), tc.G, arg) 39 require.NoError(t, err) 40 41 require.False(t, settings.ChatDisabled) 42 require.NotNil(t, settings.ChannelName) 43 require.Equal(t, globals.DefaultTeamTopic, *settings.ChannelName) 44 45 setArg := keybase1.SetTeamRepoSettingsArg{ 46 Folder: folder, 47 RepoID: keybase1.RepoID(repoID), 48 ChatDisabled: true, 49 } 50 err = SetTeamRepoSettings(context.Background(), tc.G, setArg) 51 require.NoError(t, err) 52 53 settings, err = GetTeamRepoSettings(context.Background(), tc.G, arg) 54 require.NoError(t, err) 55 require.True(t, settings.ChatDisabled) 56 require.Nil(t, settings.ChannelName) 57 58 // create a channel and change the settings to use it 59 require.NotNil(t, tc.G.ChatHelper) 60 channelName := "git" 61 err = tc.G.ChatHelper.SendTextByName(context.Background(), teamName, &channelName, chat1.ConversationMembersType_TEAM, keybase1.TLFIdentifyBehavior_CHAT_CLI, "hello") 62 require.NoError(t, err) 63 64 setArg = keybase1.SetTeamRepoSettingsArg{ 65 Folder: folder, 66 RepoID: keybase1.RepoID(repoID), 67 ChatDisabled: false, 68 ChannelName: &channelName, 69 } 70 err = SetTeamRepoSettings(context.Background(), tc.G, setArg) 71 require.NoError(t, err) 72 73 settings, err = GetTeamRepoSettings(context.Background(), tc.G, arg) 74 require.NoError(t, err) 75 require.False(t, settings.ChatDisabled) 76 require.NotNil(t, settings.ChannelName) 77 require.Equal(t, "git", *settings.ChannelName) 78 }