-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mapping of basic auth settings for DataSourceInstanceSettings (#379)
- Loading branch information
Showing
3 changed files
with
78 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package backend | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDataSourceInstanceSettings(t *testing.T) { | ||
t.Run("HTTPClientOptions() should translate basic auth settings as expected", func(t *testing.T) { | ||
tcs := []struct { | ||
instanceSettings *DataSourceInstanceSettings | ||
expectedClientOptions httpclient.Options | ||
}{ | ||
{ | ||
instanceSettings: &DataSourceInstanceSettings{}, | ||
expectedClientOptions: httpclient.Options{}, | ||
}, | ||
{ | ||
instanceSettings: &DataSourceInstanceSettings{ | ||
User: "user", | ||
JSONData: []byte("{}"), | ||
BasicAuthEnabled: true, | ||
BasicAuthUser: "buser", | ||
DecryptedSecureJSONData: map[string]string{ | ||
"basicAuthPassword": "bpwd", | ||
"password": "pwd", | ||
}, | ||
}, | ||
expectedClientOptions: httpclient.Options{ | ||
BasicAuth: &httpclient.BasicAuthOptions{ | ||
User: "buser", | ||
Password: "bpwd", | ||
}, | ||
}, | ||
}, | ||
{ | ||
instanceSettings: &DataSourceInstanceSettings{ | ||
User: "user", | ||
JSONData: []byte("{}"), | ||
BasicAuthEnabled: false, | ||
BasicAuthUser: "buser", | ||
DecryptedSecureJSONData: map[string]string{ | ||
"basicAuthPassword": "bpwd", | ||
"password": "pwd", | ||
}, | ||
}, | ||
expectedClientOptions: httpclient.Options{ | ||
BasicAuth: &httpclient.BasicAuthOptions{ | ||
User: "user", | ||
Password: "pwd", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
opts, err := tc.instanceSettings.HTTPClientOptions() | ||
assert.NoError(t, err) | ||
assert.Equal(t, tc.expectedClientOptions.BasicAuth, opts.BasicAuth) | ||
} | ||
}) | ||
} |
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