MCPcopy
hub / github.com/portainer/portainer / Test_createProject

Function Test_createProject

pkg/libstack/compose/composeplugin_test.go:687–1395  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

685}
686
687func Test_createProject(t *testing.T) {
688 ctx := context.Background()
689 dir := t.TempDir()
690 projectName := "create-project-test"
691
692 defer func() {
693 err := os.RemoveAll(dir)
694 if err != nil {
695 t.Fatalf("Failed to remove temp dir: %v", err)
696 }
697 }()
698
699 createTestLibstackOptions := func(workingDir, projectName string, env []string, envFilepath string) libstack.Options {
700 return libstack.Options{
701 WorkingDir: workingDir,
702 ProjectName: projectName,
703 Env: env,
704 EnvFilePath: envFilepath,
705 }
706 }
707 testSimpleComposeConfig := `services:
708 nginx:
709 container_name: nginx
710 image: nginx:latest`
711
712 expectedSimpleComposeProject := func(workingDirectory string, envOverrides map[string]string) *types.Project {
713 env := types.Mapping{consts.ComposeProjectName: "create-project-test"}
714 env = env.Merge(envOverrides)
715
716 if workingDirectory == "" {
717 workingDirectory = dir
718 }
719
720 if !filepath.IsAbs(workingDirectory) {
721 absWorkingDir, err := filepath.Abs(workingDirectory)
722 if err != nil {
723 t.Fatalf("Failed to get absolute path of working directory (%s): %v", workingDirectory, err)
724 }
725 workingDirectory = absWorkingDir
726 }
727
728 return &types.Project{
729 Name: projectName,
730 WorkingDir: workingDirectory,
731 Services: types.Services{
732 "nginx": {
733 Name: "nginx",
734 ContainerName: "nginx",
735 Environment: types.MappingWithEquals{},
736 Image: "nginx:latest",
737 Networks: map[string]*types.ServiceNetworkConfig{"default": nil},
738 },
739 },
740 Networks: types.Networks{"default": {Name: "create-project-test_default"}},
741 ComposeFiles: []string{
742 dir + "/docker-compose.yml",
743 },
744 Environment: env,

Callers

nothing calls this directly

Calls 4

createProjectFunction · 0.85
createFileFunction · 0.70
RunMethod · 0.65
RemoveMethod · 0.65

Tested by

no test coverage detected