| 1 | package ram |
| 2 | |
| 3 | import ( |
| 4 | "strconv" |
| 5 | "testing" |
| 6 | "time" |
| 7 | ) |
| 8 | |
| 9 | var ( |
| 10 | groupName = strconv.FormatInt(time.Now().Unix(), 10) |
| 11 | group = GroupRequest{ |
| 12 | Group: Group{ |
| 13 | GroupName: groupName, |
| 14 | Comments: "no any comments", |
| 15 | }, |
| 16 | } |
| 17 | groupQuery = GroupQueryRequest{GroupName: groupName} |
| 18 | newGroupName = strconv.FormatInt(time.Now().Unix()+100, 10) |
| 19 | groupNew = GroupUpdateRequest{ |
| 20 | GroupName: groupName, |
| 21 | NewGroupName: newGroupName, |
| 22 | NewComments: "no any comments new", |
| 23 | } |
| 24 | uName string |
| 25 | ) |
| 26 | |
| 27 | func TestCreateGroup(t *testing.T) { |
| 28 | client := NewTestClient() |
| 29 | resp, err := client.CreateGroup(group) |
| 30 | if err != nil { |
| 31 | t.Errorf("Failed to CreateGroup %v", err) |
| 32 | } |
| 33 | t.Logf("pass CreateGroup %v", resp) |
| 34 | } |
| 35 | |
| 36 | func TestGetGroup(t *testing.T) { |
| 37 | client := NewTestClient() |
| 38 | resp, err := client.GetGroup(groupQuery) |
| 39 | if err != nil { |
| 40 | t.Errorf("Failed to GetGroup %v", err) |
| 41 | } |
| 42 | t.Logf("pass GetGroup %v", resp) |
| 43 | } |
| 44 | |
| 45 | func TestUpdateGroup(t *testing.T) { |
| 46 | client := NewTestClient() |
| 47 | resp, err := client.UpdateGroup(groupNew) |
| 48 | if err != nil { |
| 49 | t.Errorf("Failed to UpdateGroup %v", err) |
| 50 | } |
| 51 | t.Logf("pass UpdateGroup %v", resp) |
| 52 | } |
| 53 | |
| 54 | func TestListGroup(t *testing.T) { |
| 55 | client := NewTestClient() |
| 56 | resp, err := client.ListGroup(GroupListRequest{}) |
| 57 | if err != nil { |
| 58 | t.Errorf("Failed to ListGroup %v", err) |
| 59 | } |
| 60 | t.Logf("pass ListGroup %v", resp) |
| 61 | } |
| 62 | |
| 63 | func TestAddUserToGroup(t *testing.T) { |
| 64 | client := NewTestClient() |
| 65 | listParams := ListUserRequest{} |
| 66 | resp, err := client.ListUsers(listParams) |
| 67 | if err != nil { |
| 68 | t.Errorf("Failed to ListUser %v", err) |
| 69 | return |
| 70 | } |
| 71 | uName = resp.Users.User[0].UserName |
| 72 | addUserToGroupReq := UserRelateGroupRequest{ |
| 73 | UserName: uName, |
| 74 | GroupName: newGroupName, |
| 75 | } |
| 76 | response, err := client.AddUserToGroup(addUserToGroupReq) |
| 77 | if err != nil { |
| 78 | t.Errorf("Failed to AddUserToGroup %v", err) |
| 79 | } |
| 80 | t.Logf("pass AddUserToGroup %v", response) |
| 81 | } |
| 82 | |
| 83 | func TestRemoveUserFromGroup(t *testing.T) { |
| 84 | client := NewTestClient() |
| 85 | removeUserToGroupReq := UserRelateGroupRequest{ |
| 86 | UserName: uName, |
| 87 | GroupName: newGroupName, |
| 88 | } |
| 89 | response, err := client.RemoveUserFromGroup(removeUserToGroupReq) |
| 90 | if err != nil { |
| 91 | t.Errorf("Failed to RemoveUserFromGroup %v", err) |
| 92 | } |
| 93 | t.Logf("pass RemoveUserFromGroup %v", response) |
| 94 | } |
| 95 | |
| 96 | func TestListGroupsForUser(t *testing.T) { |
| 97 | client := NewTestClient() |
| 98 | response, err := client.ListGroupsForUser(UserQueryRequest{UserName: uName}) |
| 99 | if err != nil { |
| 100 | t.Errorf("Failed to ListGroupsForUser %v", err) |
| 101 | } |
| 102 | t.Logf("pass ListGroupsForUser %v", response) |
| 103 | } |
| 104 | |
| 105 | func TestListUsersForGroup(t *testing.T) { |
| 106 | client := NewTestClient() |
| 107 | groupQuery.GroupName = newGroupName |
| 108 | response, err := client.ListUsersForGroup(groupQuery) |
| 109 | if err != nil { |
| 110 | t.Errorf("Failed to ListUsersForGroup %v", err) |
| 111 | } |
| 112 | t.Logf("pass ListUsersForGroup %v", response) |
| 113 | } |
| 114 | |
| 115 | func TestDeleteGroup(t *testing.T) { |
| 116 | client := NewTestClient() |
| 117 | groupQuery.GroupName = newGroupName |
| 118 | resp, err := client.DeleteGroup(groupQuery) |
| 119 | if err != nil { |
| 120 | t.Errorf("Failed to DeleteGroup %v", err) |
| 121 | } |
| 122 | t.Logf("pass DeleteGroup %v", resp) |
| 123 | } |