diff options
author | MrArmonius <mrarmonius@gmail.com> | 2021-07-16 16:56:56 +0200 |
---|---|---|
committer | MrArmonius <mrarmonius@gmail.com> | 2021-07-19 18:57:40 +0200 |
commit | 9a8c19ec0f9b2f09daab244a49c67904c5c086aa (patch) | |
tree | f30c61228022493823ca812b292fee2285b2d233 /test/bottin_test.go | |
parent | da627ac39ad437bfb6be7e5f343933a0ca4e5073 (diff) | |
download | bottin-9a8c19ec0f9b2f09daab244a49c67904c5c086aa.tar.gz bottin-9a8c19ec0f9b2f09daab244a49c67904c5c086aa.zip |
Bottin's Test V2.0 with Framework Testing
V2 the test end-to-end,
Tests made similar to V1.0,
Add the possibility to pararellize the tests,
Create an environnement for easy integration of news test,
Diffstat (limited to 'test/bottin_test.go')
-rw-r--r-- | test/bottin_test.go | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/test/bottin_test.go b/test/bottin_test.go new file mode 100644 index 0000000..00c0da9 --- /dev/null +++ b/test/bottin_test.go @@ -0,0 +1,160 @@ +package main + +import ( + "testing" +) + +func TestAddThenDelete(t *testing.T) { + t.Parallel() + //SetUp - Create Users and Groups + inst, err := Init() + if err != nil { + t.Error(err) + } + + //TearDown - Delete all the users and groups created + err = inst.Clean() + if err != nil { + t.Error(err) + } +} + +func TestConfirmAddAttributes(t *testing.T) { + t.Parallel() + //SetUp - Create Users and Groups + inst, err := Init() + if err != nil { + t.Error(err) + } + + //Test search_attribute to confirm the Add + if ok, err := inst.CompareOurDataWithConsul(); !ok { + t.Error(err) + } + //TearDown - Delete all the users and groups created + err = inst.Clean() + if err != nil { + t.Error(err) + } +} + +//Modifyrequest Test +func TestModifyRequest(t *testing.T) { + t.Parallel() + //SetUp - Create Users and Groups + inst, err := Init() + if err != nil { + t.Error(err) + } + + //Test modify all data (groups and users) + err = inst.ModifyRandomAllData() + if err != nil { + t.Error(err) + } + + //TearDown - Delete all the users and groups created + err = inst.Clean() + if err != nil { + t.Error(err) + } +} + +func TestModifyRequestAndCheck(t *testing.T) { + t.Parallel() + //SetUp - Create Users and Groups + inst, err := Init() + if err != nil { + t.Error(err) + } + + //Test modify all data (groups and users) + err = inst.ModifyRandomAllData() + if err != nil { + t.Error(err) + } + + //Check if the data was modify on Consul + if ok, err := inst.CompareOurDataWithConsul(); !ok { + t.Error(err) + } + + //TearDown - Delete all the users and groups created + err = inst.Clean() + if err != nil { + t.Error(err) + } +} + +func TestAddUserInGroup(t *testing.T) { + t.Parallel() + //SetUp - Create Users and Groups + inst, err := Init() + if err != nil { + t.Error(err) + } + + //Add users in group + err = inst.AddAllUsersInGroup() + if err != nil { + t.Error(err) + } + + //TearDown - Delete all the users and groups created + err = inst.Clean() + if err != nil { + t.Error(err) + } +} + +func TestDeleteGroupsAfterAddedUsers(t *testing.T) { + t.Parallel() + //SetUp - Create Users and Groups + inst, err := Init() + if err != nil { + t.Error(err) + } + + //Add users in group + err = inst.AddAllUsersInGroup() + if err != nil { + t.Error(err) + } + + //Delete the half groups + number := len(inst.dataGroups) / 2 + err = inst.clean(inst.dataGroups[0:number]) + if err != nil { + t.Error(err) + } + inst.dataGroups = inst.dataGroups[number:len(inst.dataGroups)] + + //Check all the groups in memberOf exist + ok, err := inst.CheckMemberOf() + if err != nil { + t.Error(err) + } + if !ok { + t.Errorf("Found group in memberOf that isn't in Consul.") + } + + //TearDown - Delete all the users and groups created + err = inst.Clean() + if err != nil { + t.Error(err) + } +} + +//Example of paralellism Test +func TestPrincipal(t *testing.T) { + + t.Run("A=1", TestAddThenDelete) + t.Run("A=2", TestModifyRequest) + if !testing.Short() { + t.Run("B=1", TestConfirmAddAttributes) + t.Run("B=2", TestModifyRequestAndCheck) + t.Run("C=1", TestAddUserInGroup) + t.Run("C=2", TestDeleteGroupsAfterAddedUsers) + } + +} |