* Correctly encode default project response
* Make getGCEDefaultProject a method of Service and add test
* Handle error appropriately
* Update test and function definition
(cherry picked from commit ccb8888055)
Co-authored-by: Andreas Christou <andreas.christou@grafana.com>
This commit is contained in:
co-authored by
Andreas Christou
parent
525a9d041d
commit
f5f022e6ac
@@ -1,7 +1,9 @@
|
||||
package cloudmonitoring
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -9,6 +11,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -285,3 +288,23 @@ func Test_processData_functions(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_getGCEDefaultProject(t *testing.T) {
|
||||
project := "test-project"
|
||||
s := Service{
|
||||
im: &fakeInstance{
|
||||
services: map[string]datasourceService{
|
||||
cloudMonitor: {
|
||||
url: routes[cloudMonitor].url,
|
||||
client: &http.Client{},
|
||||
},
|
||||
},
|
||||
},
|
||||
gceDefaultProjectGetter: func(ctx context.Context) (string, error) {
|
||||
return project, nil
|
||||
},
|
||||
}
|
||||
|
||||
assert.HTTPSuccess(t, s.getGCEDefaultProject, "GET", "/gceDefaultProject", nil)
|
||||
assert.HTTPBodyContains(t, s.getGCEDefaultProject, "GET", "/gceDefaultProject", nil, fmt.Sprintf("\"%v\"", project))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user