Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental test manage func #704

Merged
merged 15 commits into from
Jun 29, 2023
Merged

Add experimental test manage func #704

merged 15 commits into from
Jun 29, 2023

Conversation

wbrowne
Copy link
Member

@wbrowne wbrowne commented Jun 16, 2023

What this PR does / why we need it:
Adds a new (experimental) API for plugins to create a running backend for test purposes.

Usage:

const addr = "127.0.0.1:8000"

factoryInvocations := 0
factory := datasource.InstanceFactoryFunc(func(settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
	factoryInvocations++
	i, err := NewDatasource(settings) // plugin's factory func
	return i, err
})

// <newAPI>
tp, err := datasourcetest.ManageForTest(factory, datasourcetest.ManageOpts{Address: addr})
require.NoError(t, err)
defer func() {
	err = tp.Client.Shutdown()
	t.Log("client shutdown error", err)
	err = tp.Server.Shutdown()
	t.Log("server shutdown error", err)
}()
// </newAPI>

pCtx := backend.PluginContext{DataSourceInstanceSettings: &backend.DataSourceInstanceSettings{
	ID: 1,
	JSONData: []byte(`{"foo":"bar"}`),
	DecryptedSecureJSONData: map[string]string{"secret": "p@ssw0rd",},
}}

t.Run("Test something", func(t *testing.T) {
	resp, err := tp.Client.QueryData(context.Background(), &backend.QueryDataRequest{PluginContext: pCtx})
	require.NoError(t, err)
	// ...

Special notes for your reviewer:

@wbrowne wbrowne requested a review from a team as a code owner June 16, 2023 14:46
@wbrowne wbrowne self-assigned this Jun 16, 2023
@wbrowne wbrowne requested review from marefr and xnyo and removed request for a team June 16, 2023 14:46
@wbrowne wbrowne changed the title Add test manage func Add experimental test manage func Jun 16, 2023
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

Sounds good to me

experimental/datasource/client.go Outdated Show resolved Hide resolved
@andresmgot
Copy link
Contributor

I think you added my commits here by mistake 😅

@wbrowne
Copy link
Member Author

wbrowne commented Jun 27, 2023

I think you added my commits here by mistake 😅

Doh! Thanks for catching - should be fixed 😄

@wbrowne wbrowne requested a review from andresmgot June 27, 2023 13:37
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Member

@xnyo xnyo left a comment

Choose a reason for hiding this comment

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

Awesome work!! 🚀 🚀

Just one small suggestion:

internal/tenant/tenanttest/tenant_test.go Outdated Show resolved Hide resolved
@wbrowne wbrowne requested a review from xnyo June 29, 2023 11:05
Copy link
Member

@xnyo xnyo left a comment

Choose a reason for hiding this comment

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

LGTM, great work!! 🚀🚀

@wbrowne wbrowne merged commit 792f8fd into main Jun 29, 2023
2 checks passed
@wbrowne wbrowne deleted the manage-for-test branch June 29, 2023 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants