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

Reworking the datasource format #84

Merged
merged 18 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix e2e datasource test
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
  • Loading branch information
Nexucis committed Sep 26, 2021
commit 289006c49f681efe87fffd5259a793fda9ccb2f0
4 changes: 2 additions & 2 deletions internal/api/e2e/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestCreateDatasource(t *testing.T) {
Status(http.StatusOK)

// check the document exists in the db
_, err := persistenceManager.GetDatasource().Get(entity.Metadata.Name)
_, err := persistenceManager.GetDatasource().Get(entity.Metadata.Project, entity.Metadata.Name)
assert.NoError(t, err)
utils.ClearAllKeys(t, persistenceManager.GetPersesDAO(), entity.GenerateID())
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestUpdateDatasource(t *testing.T) {
assert.True(t, result.Metadata.CreatedAt.UnixNano() < result.Metadata.UpdatedAt.UnixNano())

// check the document exists in the db
_, err = persistenceManager.GetDatasource().Get(entity.Metadata.Name)
_, err = persistenceManager.GetDatasource().Get(entity.Metadata.Project, entity.Metadata.Name)
assert.NoError(t, err)

utils.ClearAllKeys(t, persistenceManager.GetPersesDAO(), entity.GenerateID())
Expand Down
10 changes: 5 additions & 5 deletions pkg/client/api/v1/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestCreateDatasource(t *testing.T) {
defer server.Close()
persesClient := createClient(t, server)

object, err := persesClient.Datasource().Create(entity)
object, err := persesClient.Datasource(entity.Metadata.Project).Create(entity)
assert.NoError(t, err)

assert.Equal(t, object.Metadata.Name, entity.Metadata.Name)
Expand All @@ -47,7 +47,7 @@ func TestUpdateDatasource(t *testing.T) {

utils.CreateAndWaitUntilEntityExists(t, persistenceManager, entity)

object, err := persesClient.Datasource().Update(entity)
object, err := persesClient.Datasource(entity.Metadata.Project).Update(entity)
assert.NoError(t, err)

// for the moment the only thing to test is that the dates are correctly updated
Expand All @@ -66,7 +66,7 @@ func TestGetDatasource(t *testing.T) {

utils.CreateAndWaitUntilEntityExists(t, persistenceManager, entity)

object, err := persesClient.Datasource().Get(entity.Metadata.Name)
object, err := persesClient.Datasource(entity.Metadata.Project).Get(entity.Metadata.Name)
assert.NoError(t, err)
assert.Equal(t, entity.Metadata.Name, object.Metadata.Name)
assert.Equal(t, entity.Spec, object.Spec)
Expand All @@ -83,7 +83,7 @@ func TestDeleteDatasource(t *testing.T) {

utils.CreateAndWaitUntilEntityExists(t, persistenceManager, entity)

err := persesClient.Datasource().Delete(entity.Metadata.Name)
err := persesClient.Datasource(entity.Metadata.Project).Delete(entity.Metadata.Name)
assert.NoError(t, err)
}

Expand All @@ -96,7 +96,7 @@ func TestListDatasource(t *testing.T) {

utils.CreateAndWaitUntilEntityExists(t, persistenceManager, entity)

objects, err := persesClient.Datasource().List("")
objects, err := persesClient.Datasource(entity.Metadata.Project).List("")
assert.NoError(t, err)
assert.Equal(t, 1, len(objects))
assert.Equal(t, entity.Metadata.Name, objects[0].Metadata.Name)
Expand Down
22 changes: 17 additions & 5 deletions utils/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/perses/perses/internal/api/shared/dependency"
"github.com/perses/perses/internal/config"
v1 "github.com/perses/perses/pkg/model/api/v1"
"github.com/perses/perses/pkg/model/api/v1/datasource"
)

func ClearAllKeys(t *testing.T, dao database.DAO, keys ...string) {
Expand All @@ -52,7 +53,7 @@ func CreateAndWaitUntilEntityExists(t *testing.T, persistenceManager dependency.
}
case *v1.Datasource:
getFunc = func() (interface{}, error) {
return persistenceManager.GetDatasource().Get(entity.Metadata.Name)
return persistenceManager.GetDatasource().Get(entity.Metadata.Project, entity.Metadata.Name)
}
upsertFunc = func() error {
return persistenceManager.GetDatasource().Update(entity)
Expand Down Expand Up @@ -102,15 +103,26 @@ func NewProject() *v1.Project {
func NewDatasource(t *testing.T) *v1.Datasource {
promURL, err := url.Parse("https://prometheus.demo.do.prometheus.io")
if err != nil {

t.Fatal(err)
}
entity := &v1.Datasource{
Kind: v1.KindDatasource,
Metadata: v1.Metadata{
Name: "PrometheusDemo",
Metadata: v1.ProjectMetadata{
Metadata: v1.Metadata{
Name: "PrometheusDemo",
},
Project: "perses",
},
Spec: &datasource.Prometheus{
BasicDatasource: datasource.BasicDatasource{
Kind: datasource.PrometheusKind,
Default: false,
},
HTTP: datasource.HTTPConfiguration{
URL: promURL,
Access: datasource.ServerHTTPAccess,
},
},
Spec: v1.DatasourceSpec{URL: promURL},
}
entity.Metadata.CreateNow()
return entity
Expand Down