From aaaaae5588feefa04954e745d45fd051dc9b0038 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sun, 14 Feb 2021 20:09:30 +0100 Subject: [PATCH] Add unit test for groups. --- group/group_test.go | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/group/group_test.go b/group/group_test.go index 691f85d..64ad49e 100644 --- a/group/group_test.go +++ b/group/group_test.go @@ -8,6 +8,75 @@ import ( "time" ) +func TestGroup(t *testing.T) { + groups.groups = nil + Add("group", &description{}) + Add("group/subgroup", &description{Public: true}) + if len(groups.groups) != 2 { + t.Errorf("Expected 2, got %v", len(groups.groups)) + } + g := Get("group") + g2 := Get("group/subgroup") + if g == nil { + t.Fatalf("Couldn't get group") + } + if g2 == nil { + t.Fatalf("Couldn't get group/subgroup") + } + if name := g.Name(); name != "group" { + t.Errorf("Name: expected group1, got %v", name) + } + if locked, _ := g.Locked(); locked { + t.Errorf("Locked: expected false, got %v", locked) + } + if public := g.Public(); public { + t.Errorf("Public: expected false, got %v", public) + } + if public := g2.Public(); !public { + t.Errorf("Public: expected true, got %v", public) + } + if redirect := g.Redirect(); redirect != "" { + t.Errorf("Redirect: expected empty, got %v", redirect) + } + if ar := g.AllowRecording(); ar { + t.Errorf("Allow Recording: expected false, got %v", ar) + } + api := g.API() + if api == nil { + t.Errorf("Couldn't get API") + } + + if names := GetNames(); len(names) != 2 { + t.Errorf("Expected 2, got %v", names) + } + + if subs := GetSubGroups("group"); len(subs) != 0 { + t.Errorf("Expected [], got %v", subs) + } + + if public := GetPublic(); len(public) != 1 || public[0].Name != "group/subgroup" { + t.Errorf("Expeced group/subgroup, got %v", public) + } + + Expire() + + if names := GetNames(); len(names) != 2 { + t.Errorf("Expected 2, got %v", names) + } + + if found := Delete("nosuchgroup"); found || len(GetNames()) != 2 { + t.Errorf("Expected 2, got %v", GetNames()) + } + + if found := Delete("group/subgroup"); !found { + t.Errorf("Failed to delete") + } + + if names := GetNames(); len(names) != 1 || names[0] != "group" { + t.Errorf("Expected group, got %v", names) + } +} + func TestJSTime(t *testing.T) { tm := time.Now() js := ToJSTime(tm)