You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: workflow_purge_test.go
    path of file: ./repos/cds/engine/api
    
    the code of the file until where you have to start completion: package api

import (
	"context"
	"encoding/json"
	"net/http/httptest"
	"testing"
	"time"

	"github.com/golang/mock/gomock"
	"github.com/jfrog/jfrog-client-go/artifactory/services"
	"github.com/ovh/cds/engine/api/authentication"
	"github.com/ovh/cds/engine/api/authentication/builtin"
	"github.com/ovh/cds/engine/api/event"
	"github.com/ovh/cds/engine/api/integration"
	"github.com/ovh/cds/engine/api/purge"
	"github.com/ovh/cds/sdk/artifact_manager"
	"github.com/ovh/cds/sdk/artifact_manager/mock_artifact_manager"
	"github.com/ovh/cds/sdk/cdsclient"

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

	"github.com/ovh/cds/engine/api/pipeline"
	"github.com/ovh/cds/engine/api/project"
	"github.com/ovh/cds/engine/api/test"
	"github.com/ovh/cds/engine/api/test
    
func Test_Purge_DeleteArtifactsFromRepositoryManager(t *testing.T) {
	ctx := context.Background()
	api, db, _ := newTestAPI(t)

	// Create user
	u, _ := assets.InsertAdminUser(t, db)
	consumer, _ := authentication.LoadUserConsumerByTypeAndUserID(context.TODO(), db, sdk.ConsumerLocal, u.ID, authentication.LoadUserConsumerOptions.WithAuthentifiedUser)

	p := assets.InsertTestProject(t, db, api.Cache, sdk.RandomString(10), sdk.RandomString(10))
	w := assets.InsertTestWorkflow(t, db, api.Cache, p, sdk.RandomString(10))

	integrationModel, err := integration.LoadModelByName(context.TODO(), db, sdk.ArtifactoryIntegration.Name)
	require.NoError(t, err)

	integrationConfig := integrationModel.DefaultConfig.Clone()
	integrationConfig.SetValue("url", "https://artifactory.lolcat.local/")
	integrationConfig.SetValue("platform", "artifactory")
	integrationConfig.SetValue("token.name", "my-token")
	integrationConfig.SetValue("token", "abcdef")
	integrationConfig.SetValue("release.token", "abcdef")
	integrationConfig.SetValue("project.key", "my-project-key")
	integrationConfig.SetValue("cds.repository", "my-repository")
	integrationConfig.SetValue("promotion.maturity.low", "snapshot")
	integrationConfig.SetValue("promotion.maturity.high", "release")

	projectIntegration := sdk.ProjectIntegration{
		ProjectID:          p.ID,
		IntegrationModelID: integrationModel.ID,
		Config:             integrationConfig,
		Model:              integrationModel,
	}

	require.NoError(t, integration.InsertIntegration(db, &projectIntegration))

	p.Integrations = append(p.Integrations, projectIntegration)

	w.Integrations = append(w.Integrations,
		sdk.WorkflowProjectIntegration{
			WorkflowID:           w.ID,
			ProjectIntegrationID: projectIntegration.ID,
			Config:               integrationModel.AdditionalDefaultConfig.Clone(),
			ProjectIntegration:   projectIntegration,
		},
	)

	workflow.Update(ctx, db, api.Cache, *p, w, workflow.UpdateOptions{
		DisableHookManagement: true,
	})

	w, err = workflow.Load(ctx, db, api.Cache, *p, w.Name, workflow.LoadOptions{
		DeepPipeline:          true,
		WithAsCodeUpdateEvent: true,
		WithIcon:              true,
		WithIntegrations:      true,
		WithTemplate:          true,
	})
	require.NoError(t, err)

	wr, err := workflow.CreateRun(db.DbMap, w, sdk.WorkflowRunPostHandlerOption{
		Hook: &sdk.WorkflowNodeRunHookEvent{},
	})
	require.NoError(t, err)

	opts := sdk.WorkflowRunPostHandlerOption{
		Manual:         &sdk.WorkflowNodeRunManual{},
		AuthConsumerID: consumer.ID,
	}

	api.initWorkflowRun(ctx, p.Key, w, wr, opts)

	wr, err = workflow.LoadRunByID(context.Background(), db.DbMap, wr.ID, workflow.LoadRunOptions{
		WithTests: true,
	})
	require.NoError(t, err)

	data := sdk.WorkflowRunResultArtifactManager{
		WorkflowRunResultArtifactCommon: sdk.WorkflowRunResultArtifactCommon{
			Name: "foo",
		},
		Path:     "path/to/foo",
		RepoName: "repository",
	}
	rawData, _ := json.Marshal(data)

	ctrl := gomock.NewController(t)
	t.Cleanup(func() {
		ctrl.Finish()
	})

	mockArtifactory := mock_artifact_manager.NewMockArtifactManager(ctrl)

	mockArtifactory.EXPECT().GetRepository("repository").Return(&services.RepositoryDetails{
		PackageType: "docker",
	}, nil)

	mockArtifactory.EXPECT().GetFileInfo("repository", "path/to/foo/manifest.json").Return(
		sdk.FileInfo{
			Checksums: &sdk.FileInfoChecksum{},
		},
		nil)

	mockArtifactory.EXPECT().SetProperties("repository-snapshot", "path/to/foo", gomock.Any()).Return(nil)

	artifact_manager.DefaultClientFactory = func(_, _, _ string) (artifact_manager.ArtifactManager, error) {
		return mockArtifactory, nil
	}

	api.Cache.SetWithTTL(workflow.GetRunResultKey(wr.ID, sdk.WorkflowRunResultTypeArtifactManager, data.Name), true, 60)
	require.NoError(t,
		workflow.AddResult(ctx, db.DbMap, api.Cache, wr,
			&sdk.WorkflowRunResult{
				Type:              sdk.WorkflowRunResultTypeArtifactManager,
				Created:           time.Now(),
				WorkflowRunID:     wr.ID,
				WorkflowNodeRunID: wr.RootRun().ID,
				WorkflowRunJobID:  wr.RootRun().Stages[0].RunJobs[0].ID,
				DataRaw:           rawData,
			},
		),
	)

	require.NoError(t, purge.DeleteArtifactsFromRepositoryManager(ctx, db, wr))
}