Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Add GetRoles call to fetch all Grafana roles #151

Merged
merged 1 commit into from
May 31, 2023

Conversation

skatsaounis
Copy link
Contributor

Adds method to fetch roles. This will be used by the new data_source_role resource of Terraform provider which will fetch roles by name

Copy link
Contributor

@inkel inkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I've left some comments but overall looks good to me.

role_test.go Outdated
t.Log(pretty.PrettyFormat(roles))

if len(roles) != dashCount {
t.Errorf("Length of returned roles should be %d", dashCount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should instead be a call to t.Fatalf, as otherwise if this one fail then it's possible either of the if calls below result in a panic because execution will continue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I just updated the line with your suggestion

mockData := strings.Repeat(getRoleResponse+",", 1000) // make 1000 roles.
mockData = "[" + mockData[:len(mockData)-1] + "]" // remove trailing comma; make a json list.

// This creates 1000 + 1000 + 1 (2001, 3 calls) worth of roles.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also test what happens if 0 or any number below 1,000 is returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of them are tested with separate test cases with my new commit. Just a comment though. The same test is made for folders and dashboards and these cases are not covered. More or less I copied and modified the logic of those tests.

Hopefully we are good to go now 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's better! I'm aware some other tests do not cover all cases (yaaay) but given that we are adding new tests I think it's better if we test them thoroughly.

Copy link
Contributor

@inkel inkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in re-reviewing this one, LGTM!

mockData := strings.Repeat(getRoleResponse+",", 1000) // make 1000 roles.
mockData = "[" + mockData[:len(mockData)-1] + "]" // remove trailing comma; make a json list.

// This creates 1000 + 1000 + 1 (2001, 3 calls) worth of roles.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's better! I'm aware some other tests do not cover all cases (yaaay) but given that we are adding new tests I think it's better if we test them thoroughly.

@inkel inkel merged commit 655166f into grafana:master May 31, 2023
2 checks passed
@skatsaounis
Copy link
Contributor Author

@inkel thanks for merging this one. could you please create a release so as to update my PR on the provider to use it?

@skatsaounis skatsaounis deleted the add-get-roles branch May 31, 2023 13:49
@inkel
Copy link
Contributor

inkel commented May 31, 2023

💥 done: v0.22.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants