@@ -39,110 +39,54 @@ func TestAccDatasourceOrganizationUser_basic(t *testing.T) {
39
39
})
40
40
}
41
41
42
- func TestAccDatasourceOrganizationUser_exactMatch (t * testing.T ) {
42
+ func TestAccDatasourceOrganizationUser_disambiguation (t * testing.T ) {
43
43
testutils .CheckOSSTestsEnabled (t )
44
44
45
45
var user1 , user2 models.UserProfileDTO
46
46
checks := []resource.TestCheckFunc {
47
- userCheckExists .exists ("grafana_user.test1" , & user1 ),
48
- userCheckExists .exists ("grafana_user.test2" , & user2 ),
49
- // Test that exact login match works when multiple users are returned
50
- resource .TestCheckResourceAttr (
51
- "data.grafana_organization_user.exact_match" , "login" , "test-exact-match" ,
52
- ),
53
- resource .TestMatchResourceAttr (
54
- "data.grafana_organization_user.exact_match" , "user_id" , common .IDRegexp ,
55
- ),
47
+ userCheckExists .exists ("grafana_user.user1" , & user1 ),
48
+ userCheckExists .exists ("grafana_user.user2" , & user2 ),
49
+ resource .TestCheckResourceAttr ("data.grafana_organization_user.from_email" , "login" , "login1" ),
50
+ resource .
TestCheckResourceAttr (
"data.grafana_organization_user.from_email" ,
"email" ,
"[email protected] " ),
51
+ resource .TestCheckResourceAttr ("data.grafana_organization_user.from_login" , "login" , "log" ),
52
+ resource .
TestCheckResourceAttr (
"data.grafana_organization_user.from_login" ,
"email" ,
"[email protected] ~" ),
56
53
}
57
54
58
55
resource .ParallelTest (t , resource.TestCase {
59
56
ProtoV5ProviderFactories : testutils .ProtoV5ProviderFactories ,
60
- CheckDestroy : userCheckExists .destroyed (& user1 , nil ),
57
+ CheckDestroy : resource .ComposeTestCheckFunc (
58
+ userCheckExists .destroyed (& user1 , nil ),
59
+ userCheckExists .destroyed (& user2 , nil ),
60
+ ),
61
61
Steps : []resource.TestStep {
62
62
{
63
- Config : testAccDatasourceOrganizationUserExactMatch ,
63
+ Config : testAccDatasourceOrganizationUserDisambiguation ,
64
64
Check : resource .ComposeTestCheckFunc (checks ... ),
65
65
},
66
66
},
67
67
})
68
68
}
69
69
70
- // TestDataSourceOrganizationUserExactMatchLogic tests the exact matching logic without requiring a Grafana instance
71
- func TestDataSourceOrganizationUserExactMatchLogic (t * testing.T ) {
72
- // Test case 2: Multiple users returned, exact login match exists
73
- usersMultiple := []* models.UserLookupDTO {
74
- {
75
- UserID : 1 ,
76
- Login : "test-exact-match" ,
77
- },
78
- {
79
- UserID : 2 ,
80
- Login : "test-exact-match-other" ,
81
- },
82
- }
83
-
84
- // Test case 3: Multiple users returned, no exact login match
85
- usersNoExact := []* models.UserLookupDTO {
86
- {
87
- UserID : 1 ,
88
- Login : "test-exact-match-other1" ,
89
- },
90
- {
91
- UserID : 2 ,
92
- Login : "test-exact-match-other2" ,
93
- },
94
- }
95
-
96
- // Test that we can identify exact matches
97
- var exactMatch * models.UserLookupDTO
98
- login := "test-exact-match"
99
-
100
- for _ , user := range usersMultiple {
101
- if user .Login == login {
102
- if exactMatch != nil {
103
- t .Fatal ("Multiple exact matches found when there should only be one" )
104
- }
105
- exactMatch = user
106
- }
107
- }
108
-
109
- if exactMatch == nil {
110
- t .Fatal ("Expected to find exact match but didn't" )
111
- }
112
-
113
- if exactMatch .UserID != 1 {
114
- t .Fatalf ("Expected UserID 1, got %d" , exactMatch .UserID )
115
- }
116
-
117
- // Test that we don't find exact matches when they don't exist
118
- exactMatch = nil
119
- for _ , user := range usersNoExact {
120
- if user .Login == login {
121
- exactMatch = user
122
- }
123
- }
124
-
125
- if exactMatch != nil {
126
- t .Fatal ("Expected no exact match but found one" )
127
- }
70
+ var testAccDatasourceOrganizationUserDisambiguation = `
71
+ resource "grafana_user" "user1" {
72
+
73
+ name = "Test User 1"
74
+ login = "login1"
75
+ password = "my-password"
128
76
}
129
77
130
- const testAccDatasourceOrganizationUserExactMatch = `
131
- resource "grafana_user" "test1" {
132
-
133
- name = "Test Exact Match 1"
134
- login = "test-exact-match"
78
+ resource "grafana_user" "user2" {
79
+
80
+ name = "Test User 1a"
81
+ login = "log"
135
82
password = "my-password"
136
83
}
137
84
138
- resource "grafana_user" "test2" {
139
-
140
- name = "Test Exact Match 2"
141
- login = "test-exact-match-other"
142
- password = "my-password"
85
+ data "grafana_organization_user" "from_email" {
86
+ email = grafana_user.user1.email
143
87
}
144
88
145
- data "grafana_organization_user" "exact_match " {
146
- login = grafana_user.test1 .login
89
+ data "grafana_organization_user" "from_login " {
90
+ login = grafana_user.user2 .login
147
91
}
148
92
`
0 commit comments