How to use WithStatus method of result Package

Best Testkube code snippet using result.WithStatus

operations_test.go

Source:operations_test.go Github

copy

Full Screen

...500 {501 Items: 2,502 Group: &Group{IPID: "1", Name: "group 1", Email: "group.1@mail.com"},503 Resources: []*Member{504 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),505 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),506 },507 },508 },509 ).Build(),510 scim: GroupsMembersResultBuilder().WithResources(511 []*GroupMembers{512 {513 Items: 2,514 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"},515 Resources: []*Member{516 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),517 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),518 },519 },520 },521 ).Build(),522 },523 wantCreate: GroupsMembersResultBuilder().WithResources(524 []*GroupMembers{525 GroupMembersBuilder().526 WithGroup(527 &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},528 ).529 WithResources(530 []*Member{531 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),532 },533 ).Build(),534 },535 ).Build(),536 wantEqual: GroupsMembersResultBuilder().WithResources(537 []*GroupMembers{538 GroupMembersBuilder().539 WithGroup(540 &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},541 ).542 WithResources(543 []*Member{544 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),545 },546 ).Build(),547 },548 ).Build(),549 wantDelete: GroupsMembersResultBuilder().WithResources(550 []*GroupMembers{551 GroupMembersBuilder().552 WithGroup(553 &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},554 ).555 WithResources(556 []*Member{557 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),558 },559 ).Build(),560 },561 ).Build(),562 wantErr: false,563 },564 {565 name: "two groups: g1 -> add 1, g1 -> equal 1, g2 -> equal 1, g1 -> delete 1, g2 -> delete 1",566 args: args{567 idp: GroupsMembersResultBuilder().WithResources(568 []*GroupMembers{569 GroupMembersBuilder().570 WithGroup(571 &Group{IPID: "1", Name: "group 1", Email: "group.1@mail.com"},572 ).573 WithResources(574 []*Member{575 MemberBuilder().WithIPID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),576 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),577 },578 ).Build(),579 GroupMembersBuilder().580 WithGroup(581 &Group{IPID: "2", Name: "group 2", Email: "group.2@mail.com"},582 ).583 WithResources(584 []*Member{585 MemberBuilder().WithIPID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),586 },587 ).Build(),588 },589 ).Build(),590 scim: GroupsMembersResultBuilder().WithResources(591 []*GroupMembers{592 GroupMembersBuilder().593 WithGroup(594 &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"},595 ).596 WithResources(597 []*Member{598 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),599 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),600 },601 ).Build(),602 GroupMembersBuilder().603 WithGroup(604 &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"},605 ).606 WithResources(607 []*Member{608 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),609 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),610 },611 ).Build(),612 },613 ).Build(),614 },615 wantCreate: GroupsMembersResultBuilder().WithResources(616 []*GroupMembers{617 GroupMembersBuilder().618 WithGroup(619 &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},620 ).621 WithResources(622 []*Member{623 MemberBuilder().WithIPID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),624 },625 ).Build(),626 },627 ).Build(),628 wantEqual: GroupsMembersResultBuilder().WithResources(629 []*GroupMembers{630 GroupMembersBuilder().631 WithGroup(632 &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},633 ).634 WithResources(635 []*Member{636 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),637 },638 ).Build(),639 GroupMembersBuilder().640 WithGroup(641 &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: Hash(&Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"})},642 ).643 WithResources(644 []*Member{645 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),646 },647 ).Build(),648 },649 ).Build(),650 wantDelete: GroupsMembersResultBuilder().WithResources(651 []*GroupMembers{652 GroupMembersBuilder().653 WithGroup(654 &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},655 ).656 WithResources(657 []*Member{658 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),659 },660 ).Build(),661 GroupMembersBuilder().662 WithGroup(663 &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: Hash(&Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"})},664 ).665 WithResources(666 []*Member{667 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),668 },669 ).Build(),670 },671 ).Build(),672 wantErr: false,673 },674 {675 name: "two groups: 2 equals, 1 add",676 args: args{677 idp: GroupsMembersResultBuilder().WithResources(678 []*GroupMembers{679 GroupMembersBuilder().680 WithGroup(681 &Group{IPID: "1", Name: "group 1", Email: "group.1@mail.com"},682 ).683 WithResources(684 []*Member{685 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),686 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),687 },688 ).Build(),689 GroupMembersBuilder().690 WithGroup(691 &Group{IPID: "2", Name: "group 2", Email: "group.2@mail.com"},692 ).693 WithResources(694 []*Member{695 MemberBuilder().WithIPID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),696 },697 ).Build(),698 GroupMembersBuilder().699 WithGroup(700 &Group{IPID: "3", Name: "group 3", Email: "group.3@mail.com"}).701 WithResources(702 []*Member{},703 ).Build(),704 },705 ).Build(),706 scim: GroupsMembersResultBuilder().WithResources(707 []*GroupMembers{708 GroupMembersBuilder().709 WithGroup(710 &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"},711 ).712 WithResources(713 []*Member{714 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),715 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),716 },717 ).Build(),718 GroupMembersBuilder().719 WithGroup(720 &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"},721 ).722 WithResources(723 []*Member{},724 ).Build(),725 GroupMembersBuilder().726 WithGroup(727 &Group{IPID: "3", SCIMID: "3", Name: "group 3", Email: "group.3@mail.com"},728 ).729 WithResources(730 []*Member{},731 ).Build(),732 },733 ).Build(),734 },735 wantCreate: GroupsMembersResultBuilder().WithResources(736 []*GroupMembers{737 GroupMembersBuilder().738 WithGroup(739 &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: Hash(&Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"})},740 ).741 WithResources(742 []*Member{743 MemberBuilder().WithIPID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),744 },745 ).Build(),746 },747 ).Build(),748 wantEqual: GroupsMembersResultBuilder().WithResources(749 []*GroupMembers{750 GroupMembersBuilder().751 WithGroup(752 &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},753 ).754 WithResources(755 []*Member{756 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),757 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),758 },759 ).Build(),760 GroupMembersBuilder().761 WithGroup(762 &Group{IPID: "3", SCIMID: "3", Name: "group 3", Email: "group.3@mail.com", HashCode: Hash(&Group{IPID: "3", SCIMID: "3", Name: "group 3", Email: "group.3@mail.com"})}).763 WithResources(764 []*Member{},765 ).Build(),766 },767 ).Build(),768 wantDelete: GroupsMembersResultBuilder().WithResources([]*GroupMembers{}).Build(),769 wantErr: false,770 },771 }772 for _, tt := range tests {773 t.Run(tt.name, func(t *testing.T) {774 if !tt.wantErr {775 tt.wantCreate.SetHashCode()776 tt.wantEqual.SetHashCode()777 tt.wantDelete.SetHashCode()778 }779 gotCreate, gotEqual, gotDelete, err := MembersOperations(tt.args.idp, tt.args.scim)780 if (err != nil) != tt.wantErr {781 t.Errorf("MembersOperations() error = %v", err)782 return783 }784 if !reflect.DeepEqual(gotCreate, tt.wantCreate) {785 t.Errorf("MembersOperations() gotCreate = %s, want %s", utils.ToJSON(gotCreate), utils.ToJSON(tt.wantCreate))786 }787 if !reflect.DeepEqual(gotEqual, tt.wantEqual) {788 t.Errorf("MembersOperations() gotEqual = %s, want %s", utils.ToJSON(gotEqual), utils.ToJSON(tt.wantEqual))789 }790 if !reflect.DeepEqual(gotDelete, tt.wantDelete) {791 t.Errorf("MembersOperations() gotDelete = %s, want %s", utils.ToJSON(gotDelete), utils.ToJSON(tt.wantDelete))792 }793 })794 }795}796func TestMergeGroupsResult(t *testing.T) {797 type args struct {798 grs []*GroupsResult799 }800 tests := []struct {801 name string802 args args803 wantMerged *GroupsResult804 }{805 {806 name: "merge empty",807 args: args{808 grs: []*GroupsResult{},809 },810 wantMerged: &GroupsResult{811 Items: 0,812 Resources: []*Group{},813 HashCode: "",814 },815 },816 {817 name: "nil arg",818 args: args{819 grs: nil,820 },821 wantMerged: &GroupsResult{822 Items: 0,823 Resources: []*Group{},824 HashCode: "",825 },826 },827 {828 name: "three groups",829 args: args{830 grs: []*GroupsResult{831 {832 Items: 1,833 Resources: []*Group{834 {IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@gmail.com", HashCode: "1234567890"},835 },836 HashCode: "1234",837 },838 {839 Items: 2,840 Resources: []*Group{841 {IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@gmail.com", HashCode: "0987654321"},842 {IPID: "3", SCIMID: "3", Name: "group 3", Email: "group.3@gmail.com", HashCode: "1234509876"},843 },844 HashCode: "1234",845 },846 },847 },848 wantMerged: &GroupsResult{849 Items: 3,850 Resources: []*Group{851 {IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@gmail.com", HashCode: "1234567890"},852 {IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@gmail.com", HashCode: "0987654321"},853 {IPID: "3", SCIMID: "3", Name: "group 3", Email: "group.3@gmail.com", HashCode: "1234509876"},854 },855 },856 },857 }858 for _, tt := range tests {859 t.Run(tt.name, func(t *testing.T) {860 tt.wantMerged.SetHashCode()861 if gotMerged := MergeGroupsResult(tt.args.grs...); !reflect.DeepEqual(gotMerged, tt.wantMerged) {862 t.Errorf("MergeGroupsResult() = %s, want %s", utils.ToJSON(gotMerged), utils.ToJSON(tt.wantMerged))863 }864 })865 }866}867func TestMergeUsersResult(t *testing.T) {868 type args struct {869 urs []*UsersResult870 }871 tests := []struct {872 name string873 args args874 wantMerged *UsersResult875 }{876 {877 name: "merge empty",878 args: args{879 urs: []*UsersResult{},880 },881 wantMerged: &UsersResult{882 Items: 0,883 Resources: []*User{},884 HashCode: "",885 },886 },887 {888 name: "nil arg",889 args: args{890 urs: nil,891 },892 wantMerged: &UsersResult{893 Items: 0,894 Resources: []*User{},895 HashCode: "",896 },897 },898 {899 name: "three users",900 args: args{901 urs: []*UsersResult{902 {903 Items: 1,904 Resources: []*User{905 {IPID: "1", SCIMID: "1", Name: Name{GivenName: "user", FamilyName: "1"}, Email: "user.1@gmail.com", HashCode: "1234567890"},906 },907 HashCode: "1234",908 },909 {910 Items: 2,911 Resources: []*User{912 {IPID: "2", SCIMID: "2", Name: Name{GivenName: "user", FamilyName: "2"}, Email: "user.2@gmail.com", HashCode: "0987654321"},913 {IPID: "3", SCIMID: "3", Name: Name{GivenName: "user", FamilyName: "3"}, Email: "user.3@gmail.com", HashCode: "1234509876"},914 },915 HashCode: "1234",916 },917 },918 },919 wantMerged: &UsersResult{920 Items: 3,921 Resources: []*User{922 {IPID: "1", SCIMID: "1", Name: Name{GivenName: "user", FamilyName: "1"}, Email: "user.1@gmail.com", HashCode: "1234567890"},923 {IPID: "2", SCIMID: "2", Name: Name{GivenName: "user", FamilyName: "2"}, Email: "user.2@gmail.com", HashCode: "0987654321"},924 {IPID: "3", SCIMID: "3", Name: Name{GivenName: "user", FamilyName: "3"}, Email: "user.3@gmail.com", HashCode: "1234509876"},925 },926 },927 },928 }929 for _, tt := range tests {930 t.Run(tt.name, func(t *testing.T) {931 tt.wantMerged.SetHashCode()932 if gotMerged := MergeUsersResult(tt.args.urs...); !reflect.DeepEqual(gotMerged, tt.wantMerged) {933 t.Errorf("MergeUsersResult() = %s, want %s", utils.ToJSON(gotMerged), utils.ToJSON(tt.wantMerged))934 }935 })936 }937}938func TestMergeGroupsMembersResult(t *testing.T) {939 type args struct {940 gms []*GroupsMembersResult941 }942 tests := []struct {943 name string944 args args945 wantMerged *GroupsMembersResult946 }{947 {948 name: "empty",949 args: args{950 gms: []*GroupsMembersResult{},951 },952 wantMerged: &GroupsMembersResult{953 Items: 0,954 Resources: make([]*GroupMembers, 0),955 },956 },957 {958 name: "nil arg",959 args: args{960 gms: nil,961 },962 wantMerged: &GroupsMembersResult{963 Items: 0,964 Resources: make([]*GroupMembers, 0),965 },966 },967 {968 name: "two groups, two members each",969 args: args{970 gms: []*GroupsMembersResult{971 {972 Items: 1,973 HashCode: "123",974 Resources: []*GroupMembers{975 {976 Items: 2,977 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: "1234567890"},978 Resources: []*Member{979 {IPID: "1", SCIMID: "1", Email: "user.1@gmail.com", HashCode: "1234567890", Status: "ACTIVE"},980 {IPID: "2", SCIMID: "2", Email: "user.2@gmail.com", HashCode: "0987654321", Status: "ACTIVE"},981 },982 },983 },984 },985 {986 Items: 1,987 HashCode: "321",988 Resources: []*GroupMembers{989 {990 Items: 2,991 Group: &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: "0987654321"},992 Resources: []*Member{993 {IPID: "1", SCIMID: "1", Email: "user.1@gmail.com", HashCode: "1234567890", Status: "ACTIVE"},994 {IPID: "3", SCIMID: "3", Email: "user.3@gmail.com", HashCode: "5612309870", Status: "ACTIVE"},995 },996 },997 },998 },999 },1000 },1001 wantMerged: &GroupsMembersResult{1002 Items: 2,1003 HashCode: "123",1004 Resources: []*GroupMembers{1005 {1006 Items: 2,1007 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: "1234567890"},1008 Resources: []*Member{1009 {IPID: "1", SCIMID: "1", Email: "user.1@gmail.com", HashCode: "1234567890", Status: "ACTIVE"},1010 {IPID: "2", SCIMID: "2", Email: "user.2@gmail.com", HashCode: "0987654321", Status: "ACTIVE"},1011 },1012 },1013 {1014 Items: 2,1015 Group: &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: "0987654321"},1016 Resources: []*Member{1017 {IPID: "1", SCIMID: "1", Email: "user.1@gmail.com", HashCode: "1234567890", Status: "ACTIVE"},1018 {IPID: "3", SCIMID: "3", Email: "user.3@gmail.com", HashCode: "5612309870", Status: "ACTIVE"},1019 },1020 },1021 },1022 },1023 },1024 {1025 name: "three groups, one members each",1026 args: args{1027 gms: []*GroupsMembersResult{1028 {1029 Items: 1,1030 HashCode: "123",1031 Resources: []*GroupMembers{1032 {1033 Items: 1,1034 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: "1234567890"},1035 Resources: []*Member{1036 {IPID: "1", SCIMID: "1", Email: "user.1@gmail.com", HashCode: "1234567890", Status: "ACTIVE"},1037 },1038 },1039 },1040 },1041 {1042 Items: 1,1043 HashCode: "321",1044 Resources: []*GroupMembers{1045 {1046 Items: 1,1047 Group: &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: "0987654321"},1048 Resources: []*Member{1049 {IPID: "2", SCIMID: "2", Email: "user.2@gmail.com", HashCode: "0987654321", Status: "ACTIVE"},1050 },1051 },1052 },1053 },1054 {1055 Items: 1,1056 HashCode: "321",1057 Resources: []*GroupMembers{1058 {1059 Items: 1,1060 Group: &Group{IPID: "3", SCIMID: "3", Name: "group 3", Email: "group.3@mail.com", HashCode: "6543219870"},1061 Resources: []*Member{1062 {IPID: "3", SCIMID: "3", Email: "user.3@gmail.com", HashCode: "5612309870", Status: "ACTIVE"},1063 },1064 },1065 },1066 },1067 },1068 },1069 wantMerged: &GroupsMembersResult{1070 Items: 3,1071 HashCode: "123",1072 Resources: []*GroupMembers{1073 {1074 Items: 1,1075 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: "1234567890"},1076 Resources: []*Member{1077 {IPID: "1", SCIMID: "1", Email: "user.1@gmail.com", HashCode: "1234567890", Status: "ACTIVE"},1078 },1079 },1080 {1081 Items: 1,1082 Group: &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: "0987654321"},1083 Resources: []*Member{1084 {IPID: "2", SCIMID: "2", Email: "user.2@gmail.com", HashCode: "0987654321", Status: "ACTIVE"},1085 },1086 },1087 {1088 Items: 1,1089 Group: &Group{IPID: "3", SCIMID: "3", Name: "group 3", Email: "group.3@mail.com", HashCode: "6543219870"},1090 Resources: []*Member{1091 {IPID: "3", SCIMID: "3", Email: "user.3@gmail.com", HashCode: "5612309870", Status: "ACTIVE"},1092 },1093 },1094 },1095 },1096 },1097 }1098 for _, tt := range tests {1099 t.Run(tt.name, func(t *testing.T) {1100 tt.wantMerged.SetHashCode()1101 if gotMerged := MergeGroupsMembersResult(tt.args.gms...); !reflect.DeepEqual(gotMerged, tt.wantMerged) {1102 t.Errorf("MergeGroupsMembersResult() = %s, want %s", utils.ToJSON(gotMerged), utils.ToJSON(tt.wantMerged))1103 }1104 })1105 }1106}1107func TestMembersDataSets(t *testing.T) {1108 type args struct {1109 idp []*GroupMembers1110 scim []*GroupMembers1111 }1112 tests := []struct {1113 name string1114 args args1115 wantCreate []*GroupMembers1116 wantEqual []*GroupMembers1117 wantDelete []*GroupMembers1118 }{1119 {1120 name: "empty return empty",1121 args: args{1122 idp: make([]*GroupMembers, 0),1123 scim: make([]*GroupMembers, 0),1124 },1125 wantCreate: make([]*GroupMembers, 0),1126 wantEqual: make([]*GroupMembers, 0),1127 wantDelete: make([]*GroupMembers, 0),1128 },1129 {1130 name: "one group: 1 add, 1 equal, 1 delete",1131 args: args{1132 idp: []*GroupMembers{1133 {1134 Items: 2,1135 Group: &Group{IPID: "1", Name: "group 1", Email: "group.1@mail.com"},1136 Resources: []*Member{1137 MemberBuilder().WithIPID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1138 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),1139 },1140 },1141 },1142 scim: []*GroupMembers{1143 {1144 Items: 2,1145 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"},1146 Resources: []*Member{1147 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1148 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1149 },1150 },1151 },1152 },1153 wantCreate: []*GroupMembers{1154 {1155 Items: 1,1156 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1157 Resources: []*Member{1158 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),1159 },1160 HashCode: Hash(&GroupMembers{1161 Items: 1,1162 Group: &Group{IPID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1163 Resources: []*Member{1164 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),1165 },1166 }),1167 },1168 },1169 wantEqual: []*GroupMembers{1170 {1171 Items: 1,1172 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1173 Resources: []*Member{1174 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1175 },1176 HashCode: Hash(&GroupMembers{1177 Items: 1,1178 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1179 Resources: []*Member{1180 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1181 },1182 }),1183 },1184 },1185 wantDelete: []*GroupMembers{1186 {1187 Items: 1,1188 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1189 Resources: []*Member{1190 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1191 },1192 HashCode: Hash(&GroupMembers{1193 Items: 1,1194 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1195 Resources: []*Member{1196 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1197 },1198 }),1199 },1200 },1201 },1202 {1203 name: "two groups: g1 -> add 1, g1 -> equal 1, g2 -> equal 1, g1 -> delete 1, g2 -> delete 1",1204 args: args{1205 idp: []*GroupMembers{1206 {1207 Items: 2,1208 Group: &Group{IPID: "1", Name: "group 1", Email: "group.1@mail.com"},1209 Resources: []*Member{1210 MemberBuilder().WithIPID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1211 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),1212 },1213 },1214 {1215 Items: 1,1216 Group: &Group{IPID: "2", Name: "group 2", Email: "group.2@mail.com"},1217 Resources: []*Member{1218 MemberBuilder().WithIPID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1219 },1220 },1221 },1222 scim: []*GroupMembers{1223 {1224 Items: 2,1225 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"},1226 Resources: []*Member{1227 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),1228 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1229 },1230 },1231 {1232 Items: 2,1233 Group: &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"},1234 Resources: []*Member{1235 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1236 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1237 },1238 },1239 },1240 },1241 wantCreate: []*GroupMembers{1242 {1243 Items: 1,1244 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1245 Resources: []*Member{1246 MemberBuilder().WithIPID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1247 },1248 HashCode: Hash(&GroupMembers{1249 Items: 1,1250 Group: &Group{IPID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1251 Resources: []*Member{1252 MemberBuilder().WithIPID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1253 },1254 }),1255 },1256 },1257 wantEqual: []*GroupMembers{1258 {1259 Items: 1,1260 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1261 Resources: []*Member{1262 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),1263 },1264 HashCode: Hash(&GroupMembers{1265 Items: 1,1266 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1267 Resources: []*Member{1268 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),1269 },1270 }),1271 },1272 {1273 Items: 1,1274 Group: &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: Hash(&Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"})},1275 Resources: []*Member{1276 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1277 },1278 HashCode: Hash(&GroupMembers{1279 Items: 1,1280 Group: &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: Hash(&Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"})},1281 Resources: []*Member{1282 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1283 },1284 }),1285 },1286 },1287 wantDelete: []*GroupMembers{1288 {1289 Items: 1,1290 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1291 Resources: []*Member{1292 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1293 },1294 HashCode: Hash(&GroupMembers{1295 Items: 1,1296 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1297 Resources: []*Member{1298 MemberBuilder().WithIPID("3").WithSCIMID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1299 },1300 }),1301 },1302 {1303 Items: 1,1304 Group: &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: Hash(&Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"})},1305 Resources: []*Member{1306 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1307 },1308 HashCode: Hash(&GroupMembers{1309 Items: 1,1310 Group: &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: Hash(&Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"})},1311 Resources: []*Member{1312 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1313 },1314 }),1315 },1316 },1317 },1318 {1319 name: "two groups: 2 equals, 1 add",1320 args: args{1321 idp: []*GroupMembers{1322 {1323 Items: 2,1324 Group: &Group{IPID: "1", Name: "group 1", Email: "group.1@mail.com"},1325 Resources: []*Member{1326 MemberBuilder().WithIPID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1327 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),1328 },1329 },1330 {1331 Items: 1,1332 Group: &Group{IPID: "2", Name: "group 2", Email: "group.2@mail.com"},1333 Resources: []*Member{1334 MemberBuilder().WithIPID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1335 },1336 },1337 {1338 Items: 0,1339 Group: &Group{IPID: "3", Name: "group 3", Email: "group.3@mail.com"},1340 Resources: []*Member{},1341 },1342 },1343 scim: []*GroupMembers{1344 {1345 Items: 2,1346 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"},1347 Resources: []*Member{1348 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1349 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),1350 },1351 },1352 {1353 Items: 0,1354 Group: &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"},1355 Resources: []*Member{},1356 },1357 {1358 Items: 0,1359 Group: &Group{IPID: "3", SCIMID: "3", Name: "group 3", Email: "group.3@mail.com"},1360 Resources: []*Member{},1361 },1362 },1363 },1364 wantCreate: []*GroupMembers{1365 {1366 Items: 1,1367 Group: &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: Hash(&Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"})},1368 Resources: []*Member{1369 MemberBuilder().WithIPID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1370 },1371 HashCode: Hash(&GroupMembers{1372 Items: 1,1373 Group: &Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com", HashCode: Hash(&Group{IPID: "2", SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"})}, Resources: []*Member{1374 MemberBuilder().WithIPID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1375 },1376 }),1377 },1378 },1379 wantEqual: []*GroupMembers{1380 {1381 Items: 2,1382 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1383 Resources: []*Member{1384 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1385 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),1386 },1387 HashCode: Hash(&GroupMembers{1388 Items: 2,1389 Group: &Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com", HashCode: Hash(&Group{IPID: "1", SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"})},1390 Resources: []*Member{1391 MemberBuilder().WithIPID("1").WithSCIMID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1392 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),1393 },1394 }),1395 },1396 {1397 Items: 0,1398 Group: &Group{IPID: "3", SCIMID: "3", Name: "group 3", Email: "group.3@mail.com", HashCode: Hash(&Group{IPID: "3", SCIMID: "3", Name: "group 3", Email: "group.3@mail.com"})},1399 Resources: []*Member{},1400 HashCode: Hash(&GroupMembers{1401 Items: 0,1402 Group: &Group{IPID: "3", SCIMID: "3", Name: "group 3", Email: "group.3@mail.com", HashCode: Hash(&Group{IPID: "3", SCIMID: "3", Name: "group 3", Email: "group.3@mail.com"})},1403 Resources: []*Member{},1404 }),1405 },1406 },1407 wantDelete: []*GroupMembers{},1408 },1409 }1410 for _, tt := range tests {1411 t.Run(tt.name, func(t *testing.T) {1412 for _, item := range tt.wantCreate {1413 item.SetHashCode()1414 }1415 for _, item := range tt.wantEqual {1416 item.SetHashCode()1417 }1418 for _, item := range tt.wantDelete {1419 item.SetHashCode()1420 }1421 gotCreate, gotEqual, gotDelete := membersDataSets(tt.args.idp, tt.args.scim)1422 if !reflect.DeepEqual(gotCreate, tt.wantCreate) {1423 t.Errorf("membersDataSets() gotCreate = %s, want %s", utils.ToJSON(gotCreate), utils.ToJSON(tt.wantCreate))1424 }1425 if !reflect.DeepEqual(gotEqual, tt.wantEqual) {1426 t.Errorf("membersDataSets() gotEqual = %s, want %s", utils.ToJSON(gotEqual), utils.ToJSON(tt.wantEqual))1427 }1428 if !reflect.DeepEqual(gotDelete, tt.wantDelete) {1429 t.Errorf("membersDataSets() gotDelete = %s, want %s", utils.ToJSON(gotDelete), utils.ToJSON(tt.wantDelete))1430 }1431 })1432 }1433}1434func TestUpdateGroupsMembersSCIMID(t *testing.T) {1435 t.Run("empty arguments", func(t *testing.T) {1436 idp := &GroupsMembersResult{}1437 scim := &GroupsResult{}1438 scimUser := &UsersResult{}1439 got := UpdateGroupsMembersSCIMID(idp, scim, scimUser)1440 assert.Equal(t, 0, got.Items)1441 assert.Equal(t, 0, len(got.Resources))1442 assert.NotEqual(t, "", got.HashCode)1443 })1444 t.Run("update idp SCIM groups and users ids", func(t *testing.T) {1445 idp := &GroupsMembersResult{1446 Items: 2,1447 Resources: []*GroupMembers{1448 {1449 Items: 2, Group: &Group{IPID: "1", Name: "group 1", Email: "group.1@mail.com"},1450 Resources: []*Member{1451 MemberBuilder().WithIPID("1").WithEmail("user.1@mail.com").WithStatus("ACTIVE").Build(),1452 MemberBuilder().WithIPID("2").WithSCIMID("2").WithEmail("user.2@mail.com").WithStatus("ACTIVE").Build(),1453 },1454 },1455 {1456 Items: 3, Group: &Group{IPID: "2", Name: "group 2", Email: "group.2@mail.com"},1457 Resources: []*Member{1458 MemberBuilder().WithIPID("3").WithEmail("user.3@mail.com").WithStatus("ACTIVE").Build(),1459 {IPID: "4", Email: "user.4@mail.com", Status: "ACTIVE"},1460 {IPID: "5", Email: "user.5@mail.com", Status: "ACTIVE"},1461 },1462 },1463 },1464 }1465 scim := &GroupsResult{1466 Items: 2,1467 Resources: []*Group{1468 {SCIMID: "1", Name: "group 1", Email: "group.1@mail.com"},1469 {SCIMID: "2", Name: "group 2", Email: "group.2@mail.com"},1470 },1471 }1472 scimUser := &UsersResult{...

Full Screen

Full Screen

controller_test.go

Source:controller_test.go Github

copy

Full Screen

1/*2Copyright 2021 The Crossplane Authors.3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12*/13package hooks14import (15 "context"16 "fmt"17 "testing"18 "time"19 xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"20 "github.com/pkg/errors"21 "github.com/crossplane/crossplane-runtime/pkg/meta"22 "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"23 "github.com/crossplane/crossplane-runtime/pkg/test"24 "github.com/google/go-cmp/cmp"25 "github.com/xanzy/go-gitlab"26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"27 "sigs.k8s.io/controller-runtime/pkg/client"28 "github.com/crossplane-contrib/provider-gitlab/apis/projects/v1alpha1"29 "github.com/crossplane-contrib/provider-gitlab/pkg/clients/projects"30 "github.com/crossplane-contrib/provider-gitlab/pkg/clients/projects/fake"31)32var (33 errBoom = errors.New("boom")34 createTime = time.Now()35 projectID = 567836 projectHookID = 123437)38type args struct {39 projecthook projects.HookClient40 kube client.Client41 cr *v1alpha1.Hook42}43type projectHookModifier func(*v1alpha1.Hook)44func withConditions(c ...xpv1.Condition) projectHookModifier {45 return func(r *v1alpha1.Hook) { r.Status.ConditionedStatus.Conditions = c }46}47func withDefaultValues() projectHookModifier {48 return func(ph *v1alpha1.Hook) {49 f := false50 ph.Spec.ForProvider = v1alpha1.HookParameters{51 URL: nil,52 ConfidentialNoteEvents: &f,53 ProjectID: &projectID,54 PushEvents: &f,55 PushEventsBranchFilter: nil,56 IssuesEvents: &f,57 ConfidentialIssuesEvents: &f,58 MergeRequestsEvents: &f,59 TagPushEvents: &f,60 NoteEvents: &f,61 JobEvents: &f,62 PipelineEvents: &f,63 WikiPageEvents: &f,64 EnableSSLVerification: &f,65 Token: nil,66 }67 }68}69func withProjectID(pid int) projectHookModifier {70 return func(r *v1alpha1.Hook) {71 r.Spec.ForProvider.ProjectID = &pid72 }73}74func withStatus(s v1alpha1.HookObservation) projectHookModifier {75 return func(r *v1alpha1.Hook) { r.Status.AtProvider = s }76}77func withExternalName(projectHookID int) projectHookModifier {78 return func(r *v1alpha1.Hook) { meta.SetExternalName(r, fmt.Sprint(projectHookID)) }79}80func projecthook(m ...projectHookModifier) *v1alpha1.Hook {81 cr := &v1alpha1.Hook{}82 for _, f := range m {83 f(cr)84 }85 return cr86}87func TestObserve(t *testing.T) {88 type want struct {89 cr *v1alpha1.Hook90 result managed.ExternalObservation91 err error92 }93 cases := map[string]struct {94 args95 want96 }{97 "SuccessfulAvailable": {98 args: args{99 projecthook: &fake.MockClient{100 MockGetHook: func(pid interface{}, projectHookID int, options ...gitlab.RequestOptionFunc) (*gitlab.ProjectHook, *gitlab.Response, error) {101 return &gitlab.ProjectHook{}, &gitlab.Response{}, nil102 },103 },104 cr: projecthook(105 withDefaultValues(),106 withExternalName(projectHookID),107 withStatus(v1alpha1.HookObservation{108 ID: projectHookID,109 CreatedAt: &metav1.Time{Time: createTime},110 }),111 ),112 },113 want: want{114 cr: projecthook(115 withDefaultValues(),116 withExternalName(projectHookID),117 withConditions(xpv1.Available()),118 ),119 result: managed.ExternalObservation{120 ResourceExists: true,121 ResourceUpToDate: true,122 },123 },124 },125 "NotUpToDate": {126 args: args{127 projecthook: &fake.MockClient{128 MockGetHook: func(pid interface{}, projectHookID int, options ...gitlab.RequestOptionFunc) (*gitlab.ProjectHook, *gitlab.Response, error) {129 return &gitlab.ProjectHook{130 MergeRequestsEvents: true,131 }, &gitlab.Response{}, nil132 },133 },134 cr: projecthook(135 withDefaultValues(),136 withExternalName(projectHookID),137 withStatus(v1alpha1.HookObservation{138 ID: projectHookID,139 CreatedAt: &metav1.Time{Time: createTime},140 }),141 ),142 },143 want: want{144 cr: projecthook(145 withDefaultValues(),146 withExternalName(projectHookID),147 withConditions(xpv1.Available()),148 ),149 result: managed.ExternalObservation{150 ResourceExists: true,151 ResourceUpToDate: false,152 },153 },154 },155 "LateInitSuccess": {156 args: args{157 projecthook: &fake.MockClient{158 MockGetHook: func(pid interface{}, projectHookID int, options ...gitlab.RequestOptionFunc) (*gitlab.ProjectHook, *gitlab.Response, error) {159 return &gitlab.ProjectHook{}, &gitlab.Response{}, nil160 },161 },162 cr: projecthook(163 withProjectID(projectID),164 withExternalName(projectHookID),165 withStatus(v1alpha1.HookObservation{166 ID: projectHookID,167 CreatedAt: &metav1.Time{Time: createTime},168 }),169 ),170 },171 want: want{172 cr: projecthook(173 withDefaultValues(),174 withExternalName(projectHookID),175 withConditions(xpv1.Available()),176 ),177 result: managed.ExternalObservation{178 ResourceExists: true,179 ResourceUpToDate: true,180 ResourceLateInitialized: true,181 },182 },183 },184 }185 for name, tc := range cases {186 t.Run(name, func(t *testing.T) {187 e := &external{kube: tc.kube, client: tc.projecthook}188 o, err := e.Observe(context.Background(), tc.args.cr)189 if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" {190 t.Errorf("r: -want, +got:\n%s", diff)191 }192 if diff := cmp.Diff(tc.want.cr, tc.args.cr, test.EquateConditions()); diff != "" {193 t.Errorf("r: -want, +got:\n%s", diff)194 }195 if diff := cmp.Diff(tc.want.result, o); diff != "" {196 t.Errorf("r: -want, +got:\n%s", diff)197 }198 })199 }200}201func TestCreate(t *testing.T) {202 type want struct {203 cr *v1alpha1.Hook204 result managed.ExternalCreation205 err error206 }207 cases := map[string]struct {208 args209 want210 }{211 "SuccessfulCreation": {212 args: args{213 kube: &test.MockClient{214 MockUpdate: test.NewMockUpdateFn(nil),215 },216 projecthook: &fake.MockClient{217 MockAddHook: func(pid interface{}, opt *gitlab.AddProjectHookOptions, options ...gitlab.RequestOptionFunc) (*gitlab.ProjectHook, *gitlab.Response, error) {218 return &gitlab.ProjectHook{ID: projectHookID}, &gitlab.Response{}, nil219 },220 },221 cr: projecthook(222 withDefaultValues(),223 ),224 },225 want: want{226 cr: projecthook(227 withDefaultValues(),228 withConditions(xpv1.Creating()),229 withExternalName(projectHookID),230 ),231 result: managed.ExternalCreation{},232 },233 },234 "FailedCreation": {235 args: args{236 projecthook: &fake.MockClient{237 MockAddHook: func(pid interface{}, opt *gitlab.AddProjectHookOptions, options ...gitlab.RequestOptionFunc) (*gitlab.ProjectHook, *gitlab.Response, error) {238 return &gitlab.ProjectHook{}, &gitlab.Response{}, errBoom239 },240 },241 cr: projecthook(242 withDefaultValues(),243 ),244 },245 want: want{246 cr: projecthook(247 withDefaultValues(),248 withConditions(xpv1.Creating()),249 ),250 err: errors.Wrap(errBoom, errCreateFailed),251 },252 },253 }254 for name, tc := range cases {255 t.Run(name, func(t *testing.T) {256 e := &external{kube: tc.kube, client: tc.projecthook}257 o, err := e.Create(context.Background(), tc.args.cr)258 if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" {259 t.Errorf("r: -want, +got:\n%s", diff)260 }261 if diff := cmp.Diff(tc.want.cr, tc.args.cr, test.EquateConditions()); diff != "" {262 t.Errorf("r: -want, +got:\n%s", diff)263 }264 if diff := cmp.Diff(tc.want.result, o); diff != "" {265 t.Errorf("r: -want, +got:\n%s", diff)266 }267 })268 }269}270func TestUpdate(t *testing.T) {271 type want struct {272 cr *v1alpha1.Hook273 result managed.ExternalUpdate274 err error275 }276 cases := map[string]struct {277 args278 want279 }{280 "SuccessfulEditProject": {281 args: args{282 projecthook: &fake.MockClient{283 MockEditHook: func(pid interface{}, hook int, opt *gitlab.EditProjectHookOptions, options ...gitlab.RequestOptionFunc) (*gitlab.ProjectHook, *gitlab.Response, error) {284 return &gitlab.ProjectHook{}, &gitlab.Response{}, nil285 },286 },287 cr: projecthook(288 withExternalName(projectHookID),289 withProjectID(projectID),290 withStatus(v1alpha1.HookObservation{ID: projectHookID}),291 ),292 },293 want: want{294 cr: projecthook(295 withExternalName(projectHookID),296 withProjectID(projectID),297 withStatus(v1alpha1.HookObservation{ID: projectHookID}),298 ),299 },300 },301 "FailedEdit": {302 args: args{303 projecthook: &fake.MockClient{304 MockEditHook: func(pid interface{}, hook int, opt *gitlab.EditProjectHookOptions, options ...gitlab.RequestOptionFunc) (*gitlab.ProjectHook, *gitlab.Response, error) {305 return &gitlab.ProjectHook{}, &gitlab.Response{}, errBoom306 },307 },308 cr: projecthook(309 withExternalName(projectHookID),310 withProjectID(projectID),311 withStatus(v1alpha1.HookObservation{ID: projectHookID}),312 ),313 },314 want: want{315 cr: projecthook(316 withExternalName(projectHookID),317 withProjectID(projectID),318 withStatus(v1alpha1.HookObservation{ID: projectHookID}),319 ),320 err: errors.Wrap(errBoom, errUpdateFailed),321 },322 },323 }324 for name, tc := range cases {325 t.Run(name, func(t *testing.T) {326 e := &external{kube: tc.kube, client: tc.projecthook}327 o, err := e.Update(context.Background(), tc.args.cr)328 if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" {329 t.Errorf("r: -want, +got:\n%s", diff)330 }331 if diff := cmp.Diff(tc.want.cr, tc.args.cr, test.EquateConditions()); diff != "" {332 t.Errorf("r: -want, +got:\n%s", diff)333 }334 if diff := cmp.Diff(tc.want.result, o); diff != "" {335 t.Errorf("r: -want, +got:\n%s", diff)336 }337 })338 }339}340func TestDelete(t *testing.T) {341 type want struct {342 cr *v1alpha1.Hook343 err error344 }345 cases := map[string]struct {346 args347 want348 }{349 "SuccessfulDeletion": {350 args: args{351 projecthook: &fake.MockClient{352 MockDeleteHook: func(pid interface{}, hook int, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) {353 return &gitlab.Response{}, nil354 },355 },356 cr: projecthook(357 withProjectID(projectID),358 withStatus(v1alpha1.HookObservation{359 ID: projectHookID,360 }),361 withConditions(xpv1.Available()),362 ),363 },364 want: want{365 cr: projecthook(366 withProjectID(projectID),367 withStatus(v1alpha1.HookObservation{368 ID: projectHookID,369 }),370 withConditions(xpv1.Deleting()),371 ),372 },373 },374 "FailedDeletion": {375 args: args{376 projecthook: &fake.MockClient{377 MockDeleteHook: func(pid interface{}, hook int, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) {378 return &gitlab.Response{}, errBoom379 },380 },381 cr: projecthook(382 withProjectID(projectID),383 withStatus(v1alpha1.HookObservation{384 ID: projectHookID,385 }),386 withConditions(xpv1.Available()),387 ),388 },389 want: want{390 cr: projecthook(391 withProjectID(projectID),392 withStatus(v1alpha1.HookObservation{393 ID: projectHookID,394 }),395 withConditions(xpv1.Deleting()),396 ),397 err: errors.Wrap(errBoom, errDeleteFailed),398 },399 },400 "InvalidHookID": {401 args: args{402 projecthook: &fake.MockClient{403 MockDeleteHook: func(pid interface{}, hook int, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) {404 return &gitlab.Response{}, nil405 },406 },407 cr: projecthook(408 withProjectID(projectID),409 withConditions(xpv1.Available()),410 ),411 },412 want: want{413 cr: projecthook(414 withProjectID(projectID),415 withConditions(xpv1.Deleting()),416 ),417 },418 },419 }420 for name, tc := range cases {421 t.Run(name, func(t *testing.T) {422 e := &external{client: tc.projecthook}423 err := e.Delete(context.Background(), tc.args.cr)424 if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" {425 t.Errorf("r: -want, +got:\n%s", diff)426 }427 if diff := cmp.Diff(tc.want.cr, tc.args.cr, test.EquateConditions()); diff != "" {428 t.Errorf("r: -want, +got:\n%s", diff)429 }430 })431 }432}...

Full Screen

Full Screen

with_status_test.go

Source:with_status_test.go Github

copy

Full Screen

...21 "testing"22 "google.golang.org/grpc/codes"23 "google.golang.org/grpc/status"24)25func TestWithStatus(t *testing.T) {26 t.Run("no wrap for nil good", func(t *testing.T) {27 if WithStatus(nil, codes.OK, "") != nil {28 t.Error("nil with ok must be nil")29 }30 })31 t.Run("nil with no good must return original status", func(t *testing.T) {32 err := WithStatus(nil, 1000, "oh")33 if err == nil {34 t.Error("nil with unknown wrap must be not nil")35 }36 if Code(err) != 1000 {37 t.Error("unexpected code")38 }39 })40 t.Run("status wrap works", func(t *testing.T) {41 cause := errors.New("cause")42 err := WithStatus(cause, 1000, "oh")43 if err == nil {44 t.Error("nil with unknown wrap must be not nil")45 }46 s, ok := FromError(err)47 if !ok {48 t.Error("unexpected result")49 }50 if s.Code() != 1000 {51 t.Error("unexpected code")52 }53 if s.Message() != "oh" {54 t.Error("unexpected desc")55 }56 if Cause(err) != cause {57 t.Error("invalid cause")58 }59 })60 t.Run("wrapped status wrap works", func(t *testing.T) {61 cause := errors.New("cause")62 status := WithStatus(cause, 1000, "oh")63 var err error = &withMessage{cause: status, msg: "wrap"}64 s, ok := FromError(err)65 if !ok {66 t.Error("unexpected result")67 }68 if s.Code() != 1000 {69 t.Error("unexpected code")70 }71 if s.Message() != "oh" {72 t.Error("unexpected desc")73 }74 if Cause(err) != cause {75 t.Error("invalid cause")76 }77 })78 t.Run("status override works", func(t *testing.T) {79 cause := status.Error(codes.InvalidArgument, "x")80 err := WithStatus(cause, codes.FailedPrecondition, "y")81 s, ok := FromError(err)82 if !ok {83 t.Error("unexpected result")84 }85 if s.Code() != codes.FailedPrecondition {86 t.Error("unexpected code")87 }88 if s.Message() != "y" {89 t.Error("unexpected desc")90 }91 if Cause(err) != cause {92 t.Error("invalid cause")93 }94 })...

Full Screen

Full Screen

WithStatus

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 app := fiber.New()4 app.Get("/test", func(c *fiber.Ctx) error {5 return c.SendStatus(fiber.StatusNotFound)6 })7 app.Listen(":3000")8}

Full Screen

Full Screen

WithStatus

Using AI Code Generation

copy

Full Screen

1func (r *result) WithStatus(status int) *result {2}3func (r *result) WithStatus(status int) *result {4}5func (r *result) WithStatus(status int) *result {6}7func (r *result) WithStatus(status int) *result {8}9func (r *result) WithStatus(status int) *result {10}11func (r *result) WithStatus(status int) *result {12}13func (r *result) WithStatus(status int) *result {14}15func (r *result) WithStatus(status int) *result {16}17func (r *result) WithStatus(status int) *result {18}19func (r *result) WithStatus(status int) *result {20}21func (r *result) WithStatus(status int) *result {22}23func (r *result) WithStatus(status int) *result {24}25func (r *result)

Full Screen

Full Screen

WithStatus

Using AI Code Generation

copy

Full Screen

1func WithStatus(status int) Result {2 return Result{status: status}3}4func WithStatus(status int) Result {5 return Result{status: status}6}7func WithStatus(status int) Result {8 return Result{status: status}9}10func WithStatus(status int) Result {11 return Result{status: status}12}13func WithStatus(status int) Result {14 return Result{status: status}15}16func WithStatus(status int) Result {17 return Result{status: status}18}19func WithStatus(status int) Result {20 return Result{status: status}21}22func WithStatus(status int) Result {23 return Result{status: status}24}25func WithStatus(status int) Result {26 return Result{status: status}27}28func WithStatus(status int) Result {29 return Result{status: status}30}31func WithStatus(status int) Result {32 return Result{status: status}33}34func WithStatus(status int) Result {35 return Result{status: status}36}37func WithStatus(status int) Result {38 return Result{status: status}39}40func WithStatus(status int) Result {41 return Result{status: status}42}43func WithStatus(status int) Result {44 return Result{status: status}45}

Full Screen

Full Screen

WithStatus

Using AI Code Generation

copy

Full Screen

1result := result.WithStatus(200, "OK")2result := result.WithHeader("Content-Type", "application/json")3result := result.WithBody([]byte("Hello, world!"))4result := result.WithStatus(200, "OK")5result := result.WithHeader("Content-Type", "application/json")6result := result.WithBody([]byte("Hello, world!"))7result := result.WithBody([]byte("Hello, world!"))8result := result.WithStatus(200, "OK")9result := result.WithHeader("Content-Type", "application/json")10result := result.WithBody([]byte("Hello, world!"))11result := result.WithBody([]byte("Hello, world!"))12result := result.WithBody([]byte("Hello, world!"))13result := result.WithStatus(200, "OK")14result := result.WithHeader("Content-Type", "application/json")15result := result.WithBody([]byte("Hello, world!"))16result := result.WithBody([]byte("Hello, world!"))17result := result.WithBody([]byte("Hello, world!"))18result := result.WithBody([]byte("Hello, world!"))19result := result.WithStatus(200, "OK")20result := result.WithHeader("Content-Type", "application/json")

Full Screen

Full Screen

WithStatus

Using AI Code Generation

copy

Full Screen

1result := new(Result)2result.WithStatus("success")3result := new(Result)4result.WithStatus("success")5result := new(Result)6result.WithStatus("success")7result := new(Result)8result.WithStatus("success")9result := new(Result)10result.WithStatus("success")11result := new(Result)12result.WithStatus("success")13result := new(Result)14result.WithStatus("success")15result := new(Result)16result.WithStatus("success")17result := new(Result)18result.WithStatus("success")19result := new(Result)20result.WithStatus("success")21result := new(Result)22result.WithStatus("success")23result := new(Result)24result.WithStatus("success")25result := new(Result)26result.WithStatus("success")27result := new(Result)28result.WithStatus("success")29result := new(Result)30result.WithStatus("success")31result := new(Result)32result.WithStatus("success")33result := new(Result)34result.WithStatus("success")35result := new(Result)

Full Screen

Full Screen

WithStatus

Using AI Code Generation

copy

Full Screen

1func main(){2 result := NewResult()3 result.WithStatus(200)4 result.WithStatus(http.StatusOK)5 result.WithStatus(http.StatusNotFound)6 result.WithStatus(http.StatusForbidden)7 result.WithStatus(http.StatusUnauthorized)8 result.WithStatus(http.StatusInternalServerError)9 result.WithStatus(http.StatusBadGateway)10 result.WithStatus(http.StatusRequestTimeout)11 result.WithStatus(http.StatusServiceUnavailable)12 result.WithStatus(http.StatusGatewayTimeout)13 result.WithStatus(http.StatusTeapot)14 result.WithStatus(http.StatusTooManyRequests)15 result.WithStatus(http.StatusRequestHeaderFieldsTooLarge)16 result.WithStatus(http.StatusUnavailableForLegalReasons)17 result.WithStatus(http.StatusUnprocessableEntity)18 result.WithStatus(http.StatusLocked)19 result.WithStatus(http.StatusFailedDependency)20 result.WithStatus(http.StatusTooEarly)21 result.WithStatus(http.StatusUpgradeRequired)22 result.WithStatus(http.StatusPreconditionRequired)23 result.WithStatus(http.StatusTooManyRequests)24 result.WithStatus(http.StatusRequestHeaderFieldsTooLarge)25 result.WithStatus(http.StatusUnavailableForLegalReasons)26 result.WithStatus(http.StatusUnprocessableEntity)27 result.WithStatus(http.StatusLocked)28 result.WithStatus(http.StatusFailedDependency)29 result.WithStatus(http.StatusTooEarly)30 result.WithStatus(http.StatusUpgradeRequired)31 result.WithStatus(http.StatusPreconditionRequired)32 result.WithStatus(http.StatusPreconditionFailed)33 result.WithStatus(http.StatusPaymentRequired)34 result.WithStatus(http.StatusNotAcceptable)35 result.WithStatus(http.StatusNotImplemented)36 result.WithStatus(http.StatusConflict)37 result.WithStatus(http.StatusCreated)38 result.WithStatus(http.StatusNoContent)39 result.WithStatus(http.StatusNotModified)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful