-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up to 10 custom headers on go client
Fixes #483
- Loading branch information
Showing
3 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/grafana/grafana-plugin-sdk-go/backend" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewDatasourceSettings(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
// Create a mock backend.DataSourceInstanceSettings | ||
settings := backend.DataSourceInstanceSettings{ | ||
JSONData: []byte(`{ | ||
"addCorsHeader": true, | ||
"defaultDatabase": "myDatabase", | ||
"usePOST": false, | ||
"useYandexCloudAuthorization": true, | ||
"xHeaderKey": "myKey", | ||
"xHeaderUser": "myUser", | ||
"useCompression": true, | ||
"compressionType": "gzip", | ||
"tlsSkipVerify": false, | ||
"httpHeaderName1": "header1", | ||
"httpHeaderValue1": "value1", | ||
"httpHeaderName2": "header2", | ||
"httpHeaderValue2": "value2" | ||
}`), | ||
DecryptedSecureJSONData: map[string]string{ | ||
"httpHeaderValue1": "value1", | ||
"httpHeaderValue2": "value2", | ||
}, | ||
} | ||
|
||
// Call the NewDatasourceSettings function | ||
instance, err := NewDatasourceSettings(ctx, settings) | ||
require.NoError(t, err) | ||
|
||
// Assert the instance type | ||
dsSettings, ok := instance.(*DatasourceSettings) | ||
require.True(t, ok) | ||
|
||
// Assert the instance fields | ||
require.Equal(t, true, dsSettings.AddCorsHeader) | ||
require.Equal(t, "myDatabase", dsSettings.DefaultDatabase) | ||
require.Equal(t, false, dsSettings.UsePost) | ||
require.Equal(t, true, dsSettings.UseYandexCloudAuthorization) | ||
require.Equal(t, "myKey", dsSettings.XHeaderKey) | ||
require.Equal(t, "myUser", dsSettings.XHeaderUser) | ||
require.Equal(t, true, dsSettings.UseCompression) | ||
require.Equal(t, "gzip", dsSettings.CompressionType) | ||
require.Equal(t, false, dsSettings.TLSSkipVerify) | ||
require.Equal(t, "header1", dsSettings.HttpHeaderName1) | ||
require.Equal(t, "value1", dsSettings.CustomHeaders["header1"]) | ||
require.Equal(t, "header2", dsSettings.HttpHeaderName2) | ||
require.Equal(t, "value2", dsSettings.CustomHeaders["header2"]) | ||
} |