Repository: tensorchord/envd (language: python)

Issue:
bug(context): use does not work in context create command
## Description

https://github.com/tensorchord/envd/blob/main/pkg/home/context.go#L97

use here is not used.

## Reproduction

## Additional Info

---
<!-- Issue Author: Don't delete this message to encourage other users to support your issue! -->
**Message from the maintainers**:

Impacted by this bug? Give it a 👍. We prioritise the issues with the most 👍.



Discussion / hints:

Fix patch:
diff --git a/pkg/home/context.go b/pkg/home/context.go
index 4df702c1c..a9ee16c31 100644
--- a/pkg/home/context.go
+++ b/pkg/home/context.go
@@ -110,7 +110,10 @@ func (m *generalManager) ContextCreate(
 	default:
 		return errors.New("unknown builder type")
 	}
-	return m.ContextUse(name)
+	if use {
+		return m.ContextUse(name)
+	}
+	return m.dumpContext()
 }
 
 func (m *generalManager) ContextRemove(name string) error {


Test patch:
diff --git a/pkg/home/context_test.go b/pkg/home/context_test.go
new file mode 100644
index 000000000..df9025b21
--- /dev/null
+++ b/pkg/home/context_test.go
@@ -0,0 +1,85 @@
+// Copyright 2022 The envd Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package home
+
+import (
+	. "github.com/onsi/ginkgo/v2"
+	. "github.com/onsi/gomega"
+
+	"github.com/tensorchord/envd/pkg/types"
+)
+
+var _ = Describe("context test", func() {
+	defaultContext := "default"
+	testContext := "envd_home_test"
+	testSocket := "0.0.0.0:12345"
+	testBuilder := types.BuilderTypeTCP
+
+	BeforeEach(func() {
+		Expect(Initialize()).To(Succeed())
+	})
+
+	Describe("create with use", Ordered, func() {
+		BeforeAll(func() {
+			err := GetManager().ContextCreate(testContext, testBuilder, testSocket, true)
+			Expect(err).NotTo(HaveOccurred())
+		})
+
+		It("current context should be the new one", func() {
+			contexts, err := GetManager().ContextList()
+			Expect(err).NotTo(HaveOccurred())
+			Expect(contexts.Current).To(Equal(testContext))
+			builder, socket, err := GetManager().ContextGetCurrent()
+			Expect(err).NotTo(HaveOccurred())
+			Expect(builder).To(Equal(testBuilder))
+			Expect(socket).To(Equal(testSocket))
+		})
+
+		It("cannot delete the current context", func() {
+			err := GetManager().ContextRemove(testContext)
+			Expect(err).To(HaveOccurred())
+		})
+
+		AfterAll(func() {
+			Expect(GetManager().ContextUse(defaultContext)).To(Succeed())
+			contexts, err := GetManager().ContextList()
+			Expect(err).NotTo(HaveOccurred())
+			Expect(contexts.Current).To(Equal(defaultContext))
+			Expect(GetManager().ContextRemove(testContext)).To(Succeed())
+		})
+	})
+
+	Describe("create without use", Ordered, func() {
+		BeforeAll(func() {
+			err := GetManager().ContextCreate(testContext, testBuilder, testSocket, false)
+			Expect(err).NotTo(HaveOccurred())
+		})
+
+		It("should not be able to create the same context", func() {
+			err := GetManager().ContextCreate(testContext, testBuilder, testSocket, false)
+			Expect(err).To(HaveOccurred())
+		})
+
+		It("should use the default context", func() {
+			contexts, err := GetManager().ContextList()
+			Expect(err).NotTo(HaveOccurred())
+			Expect(contexts.Current).To(Equal(defaultContext))
+		})
+
+		AfterAll(func() {
+			Expect(GetManager().ContextRemove(testContext)).To(Succeed())
+		})
+	})
+})