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

Admin endpoint integration tests #560

Merged
merged 18 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
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
147 changes: 147 additions & 0 deletions tests/integration/golang/admin/namespace/create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
//go:build integration

package namespace

import (
"context"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"

"github.com/G-Research/fasttrackml/pkg/api/mlflow/common"
"github.com/G-Research/fasttrackml/pkg/api/mlflow/dao/models"
"github.com/G-Research/fasttrackml/pkg/ui/admin/request"
"github.com/G-Research/fasttrackml/tests/integration/golang/helpers"
)

type CreateNamespaceTestSuite struct {
suite.Suite
helpers.BaseTestSuite
}

func TestCreateNamespaceTestSuite(t *testing.T) {
suite.Run(t, new(CreateNamespaceTestSuite))
}

func (s *CreateNamespaceTestSuite) SetupTest() {
s.BaseTestSuite.SetupTest(s.T())
}

func (s *CreateNamespaceTestSuite) Test_Ok() {
defer func() {
assert.Nil(s.T(), s.NamespaceFixtures.UnloadFixtures())
}()
_, err := s.NamespaceFixtures.CreateNamespace(context.Background(), &models.Namespace{
ID: 1,
Code: "default",
DefaultExperimentID: common.GetPointer(int32(0)),
})
assert.Nil(s.T(), err)

requests := []request.Namespace{
{
Code: "test2",
Description: "test namespace 2 description",
},
{
Code: "test3",
Description: "test namespace 3 description",
},
}
for _, request := range requests {
assert.Nil(
s.T(),
s.AdminClient.WithMethod(
http.MethodPost,
).WithRequest(
request,
).DoRequest("/namespaces"),
)
}

namespaces, err := s.NamespaceFixtures.GetNamespaces(context.Background())
assert.Nil(s.T(), err)

// Check that the namespace has been created
for _, namespace := range namespaces {
for _, testNamespace := range requests {
if namespace.Code == testNamespace.Code {
assert.Equal(s.T(), testNamespace.Description, namespace.Description)
}
}
}

// Check the length of the namespaces considering the default namespace
assert.Equal(s.T(), len(requests)+1, len(namespaces))
}

func (s *CreateNamespaceTestSuite) Test_Error() {
defer func() {
assert.Nil(s.T(), s.NamespaceFixtures.UnloadFixtures())
}()
_, err := s.NamespaceFixtures.CreateNamespace(context.Background(), &models.Namespace{
ID: 1,
Code: "default",
DefaultExperimentID: common.GetPointer(int32(0)),
})
assert.Nil(s.T(), err)

testData := []struct {
name string
request *request.Namespace
}{
{
name: "EmptyCode",
request: &request.Namespace{
Code: "",
Description: "description",
},
},
{
name: "CodeLenghtLessThan2",
request: &request.Namespace{
Code: "a",
Description: "description",
},
},
{
name: "CodeLenghtGreaterThan12",
request: &request.Namespace{
Code: "TooLongNamespaceCode",
Description: "description",
},
},
{
name: "InvalidCode",
request: &request.Namespace{
Code: "test#",
Description: "description",
},
},
{
name: "CodeAlreadyExists",
request: &request.Namespace{
Code: "default",
Description: "description",
},
},
}
for _, tt := range testData {
s.T().Run(tt.name, func(t *testing.T) {
assert.Nil(
s.T(),
s.AdminClient.WithMethod(
http.MethodPost,
).WithRequest(
tt.request,
).DoRequest("/namespaces"),
)
namespaces, err := s.NamespaceFixtures.GetNamespaces(context.Background())
assert.Nil(s.T(), err)
// Check that creation failed, only the default namespace is present
assert.Equal(s.T(), 1, len(namespaces))
})
}
}
137 changes: 137 additions & 0 deletions tests/integration/golang/admin/namespace/delete_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//go:build integration

package namespace

import (
"context"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"

"github.com/G-Research/fasttrackml/pkg/api/mlflow/common"
"github.com/G-Research/fasttrackml/pkg/api/mlflow/dao/models"
"github.com/G-Research/fasttrackml/tests/integration/golang/helpers"
)

type DeleteNamespaceTestSuite struct {
suite.Suite
helpers.BaseTestSuite
}

func TestDeleteNamespaceTestSuite(t *testing.T) {
suite.Run(t, new(DeleteNamespaceTestSuite))
}

func (s *DeleteNamespaceTestSuite) SetupTest() {
s.BaseTestSuite.SetupTest(s.T())
}

func (s *DeleteNamespaceTestSuite) Test_Ok() {
defer func() {
assert.Nil(s.T(), s.NamespaceFixtures.UnloadFixtures())
}()
_, err := s.NamespaceFixtures.CreateNamespace(context.Background(), &models.Namespace{
ID: 1,
Code: "default",
DefaultExperimentID: common.GetPointer(int32(0)),
})
assert.Nil(s.T(), err)
_, err = s.NamespaceFixtures.CreateNamespace(context.Background(), &models.Namespace{
ID: 2,
Code: "test2",
Description: "test namespace 2 description",
DefaultExperimentID: common.GetPointer(int32(0)),
})
assert.Nil(s.T(), err)
ns2, err := s.NamespaceFixtures.CreateNamespace(context.Background(), &models.Namespace{
ID: 3,
Code: "test3",
Description: "test namespace 3 description",
DefaultExperimentID: common.GetPointer(int32(0)),
})
assert.Nil(s.T(), err)

tests := []struct {
name string
expectedNamespaceCount int
}{
{
name: "DeleteNamespace",
expectedNamespaceCount: 2,
},
}
for _, tt := range tests {
s.T().Run(tt.name, func(T *testing.T) {
assert.Nil(
s.T(),
s.AdminClient.WithMethod(
http.MethodDelete,
).DoRequest(
"/namespaces/%d", ns2.ID,
),
)
namespaces, err := s.NamespaceFixtures.GetNamespaces(context.Background())
assert.Nil(s.T(), err)
assert.Equal(s.T(), tt.expectedNamespaceCount, len(namespaces))
})
}
}

func (s *DeleteNamespaceTestSuite) Test_Error() {
defer func() {
assert.Nil(s.T(), s.NamespaceFixtures.UnloadFixtures())
}()
_, err := s.NamespaceFixtures.CreateNamespace(context.Background(), &models.Namespace{
ID: 1,
Code: "default",
DefaultExperimentID: common.GetPointer(int32(0)),
})
assert.Nil(s.T(), err)
_, err = s.NamespaceFixtures.CreateNamespace(context.Background(), &models.Namespace{
ID: 2,
Code: "test2",
Description: "test namespace 2 description",
DefaultExperimentID: common.GetPointer(int32(0)),
})
assert.Nil(s.T(), err)

testData := []struct {
name string
ID string
expectedNamespacesCount int
}{
{
name: "DeleteNamespaceWithNotFoundID",
ID: "10",
expectedNamespacesCount: 2,
},
{
name: "DeleteNamespaceWithEmptyID",
ID: "",
expectedNamespacesCount: 2,
},
{
name: "DeleteNamespaceWithInvalidID",
ID: "InvalidID",
expectedNamespacesCount: 2,
},
}
for _, tt := range testData {
s.T().Run(tt.name, func(t *testing.T) {
assert.Nil(
s.T(),
s.AdminClient.WithMethod(
http.MethodDelete,
).DoRequest(
"/namespaces/%s", tt.ID,
),
)
})
namespaces, err := s.NamespaceFixtures.GetNamespaces(context.Background())
assert.Nil(s.T(), err)
// Check that deletion failed and the namespace is still there
assert.Equal(s.T(), tt.expectedNamespacesCount, len(namespaces))
}
}
Loading