mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
* backport migration EE code structure * filesystem copy function * set db status to updating before migration - reset on completion * support for auto-backup on version upgrade * - rollback cli flag support (with confirmation) - rollback implementation backport from EE * removed edition as it is not required in CE * migrated test datastore from bolttest to bolt package to make it usable for testing * backported failsafe migration * - backported tests from EE - refactored tests to use test datastore * test store implementing datastore interface * addressed PR issues/improvements * refactor test * added backup file removal error logging * resolved conflicts, updated code * fixed missing bolttest package - migrated to bolt * feat(migration): wrap migration errors to provide context for failure EE-1742 (#5711) * feat(migrator): wrap errors to provide more context to failures EE-1742 * add overall failure back in. diff log file * updated helm tests pointing to correct teststore Co-authored-by: Matt Hook <hookenz@gmail.com>
53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package helm
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/portainer/libhelm/binary/test"
|
|
"github.com/portainer/libhelm/options"
|
|
portainer "github.com/portainer/portainer/api"
|
|
"github.com/portainer/portainer/api/http/security"
|
|
"github.com/portainer/portainer/api/kubernetes"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/portainer/portainer/api/bolt"
|
|
helper "github.com/portainer/portainer/api/internal/testhelpers"
|
|
)
|
|
|
|
func Test_helmDelete(t *testing.T) {
|
|
is := assert.New(t)
|
|
|
|
store, teardown := bolt.MustNewTestStore(true)
|
|
defer teardown()
|
|
|
|
err := store.Endpoint().CreateEndpoint(&portainer.Endpoint{ID: 1})
|
|
is.NoError(err, "Error creating environment")
|
|
|
|
err = store.User().CreateUser(&portainer.User{Username: "admin", Role: portainer.AdministratorRole})
|
|
is.NoError(err, "Error creating a user")
|
|
|
|
helmPackageManager := test.NewMockHelmBinaryPackageManager("")
|
|
kubeConfigService := kubernetes.NewKubeConfigCAService("", "")
|
|
h := NewHandler(helper.NewTestRequestBouncer(), store, helmPackageManager, kubeConfigService)
|
|
|
|
is.NotNil(h, "Handler should not fail")
|
|
|
|
// Install a single chart directly, to be deleted by the handler
|
|
options := options.InstallOptions{Name: "nginx-1", Chart: "nginx", Namespace: "default"}
|
|
h.helmPackageManager.Install(options)
|
|
|
|
t.Run("helmDelete succeeds with admin user", func(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodDelete, fmt.Sprintf("/1/kubernetes/helm/%s", options.Name), nil)
|
|
ctx := security.StoreTokenData(req, &portainer.TokenData{ID: 1, Username: "admin", Role: 1})
|
|
req = req.WithContext(ctx)
|
|
req.Header.Add("Authorization", "Bearer dummytoken")
|
|
|
|
rr := httptest.NewRecorder()
|
|
h.ServeHTTP(rr, req)
|
|
|
|
is.Equal(http.StatusNoContent, rr.Code, "Status should be 204")
|
|
})
|
|
}
|