-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Oleg S <[email protected]>
- Loading branch information
Showing
4 changed files
with
101 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,39 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"log" | ||
"net/http/httptest" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/redhat-et/copilot-ops/pkg/ai/gpt3" | ||
"github.com/redhat-et/copilot-ops/pkg/cmd" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var _ = Describe("Edit", func() { | ||
var c *cobra.Command | ||
|
||
BeforeEach(func() { | ||
// create command | ||
c = cmd.NewEditCmd() | ||
Expect(c).NotTo(BeNil()) | ||
}) | ||
|
||
When("OpenAI server exists", func() { | ||
var ts *httptest.Server | ||
BeforeEach(func() { | ||
ts = OpenAITestServer() | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
ts.Start() | ||
err := c.Flags().Set(cmd.FlagOpenAIURLFull, ts.URL+gpt3.OpenAIEndpointV1) | ||
Expect(err).To(BeNil()) | ||
}) | ||
|
||
AfterEach(func() { | ||
defer ts.Close() | ||
}) | ||
|
||
It("works", func() { | ||
log.Printf("requesting the following url: %q\n", ts.URL) | ||
err := cmd.RunEdit(c, []string{}) | ||
Expect(err).To(BeNil()) | ||
}) | ||
|
||
}) | ||
// var c *cobra.Command | ||
|
||
// BeforeEach(func() { | ||
// // create command | ||
// c = cmd.NewEditCmd() | ||
// Expect(c).NotTo(BeNil()) | ||
// }) | ||
|
||
// When("OpenAI server exists", func() { | ||
// var ts *httptest.Server | ||
// BeforeEach(func() { | ||
// ts = OpenAITestServer() | ||
// }) | ||
|
||
// JustBeforeEach(func() { | ||
// ts.Start() | ||
// err := c.Flags().Set(cmd.FlagOpenAIURLFull, ts.URL+gpt3.OpenAIEndpointV1) | ||
// Expect(err).To(BeNil()) | ||
// }) | ||
|
||
// AfterEach(func() { | ||
// defer ts.Close() | ||
// }) | ||
|
||
// It("works", func() { | ||
// log.Printf("requesting the following url: %q\n", ts.URL) | ||
// err := cmd.RunEdit(c, []string{}) | ||
// Expect(err).To(BeNil()) | ||
// }) | ||
|
||
// }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,56 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"log" | ||
"net/http/httptest" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/redhat-et/copilot-ops/pkg/ai" | ||
"github.com/redhat-et/copilot-ops/pkg/ai/gpt3" | ||
"github.com/redhat-et/copilot-ops/pkg/cmd" | ||
) | ||
|
||
var _ = Describe("Generate command", func() { | ||
var c *cobra.Command | ||
var ts *httptest.Server | ||
|
||
BeforeEach(func() { | ||
c = cmd.NewGenerateCmd() | ||
}) | ||
|
||
When("server is created", func() { | ||
BeforeEach(func() { | ||
ts = OpenAITestServer() | ||
|
||
Expect(c).NotTo(BeNil()) | ||
err := c.Flags().Set(cmd.FlagNTokensFull, "1") | ||
Expect(err).To(BeNil()) | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
ts.Start() | ||
log.Println("using server URL: ", ts.URL) | ||
err := c.Flags().Set(cmd.FlagOpenAIURLFull, ts.URL+gpt3.OpenAIEndpointV1) | ||
Expect(err).To(BeNil()) | ||
err = c.Flags().Set(cmd.FlagAIBackendFull, string(ai.GPT3)) | ||
Expect(err).To(BeNil()) | ||
}) | ||
AfterEach(func() { | ||
ts.Close() | ||
}) | ||
|
||
It("executes properly", func() { | ||
err := cmd.RunGenerate(c, []string{}) | ||
// use the minimum amount of tokens from OpenAI | ||
Expect(err).To(BeNil()) | ||
}) | ||
// TODO: add more tests for expected success | ||
}) | ||
|
||
When("OpenAI server is down", func() { | ||
BeforeEach(func() { | ||
// set a port that isn't taken | ||
err := c.Flags().Set(cmd.FlagOpenAIURLFull, "http://localhost:23423") | ||
Expect(err).To(BeNil()) | ||
}) | ||
It("fails", func() { | ||
err := cmd.RunGenerate(c, []string{}) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
// TODO: add more cases that should fail | ||
}) | ||
// var c *cobra.Command | ||
// var ts *httptest.Server | ||
|
||
// BeforeEach(func() { | ||
// c = cmd.NewGenerateCmd() | ||
// }) | ||
|
||
// When("server is created", func() { | ||
// BeforeEach(func() { | ||
// ts = OpenAITestServer() | ||
|
||
// Expect(c).NotTo(BeNil()) | ||
// err := c.Flags().Set(cmd.FlagNTokensFull, "1") | ||
// Expect(err).To(BeNil()) | ||
// }) | ||
|
||
// JustBeforeEach(func() { | ||
// ts.Start() | ||
// log.Println("using server URL: ", ts.URL) | ||
// err := c.Flags().Set(cmd.FlagOpenAIURLFull, ts.URL+gpt3.OpenAIEndpointV1) | ||
// Expect(err).To(BeNil()) | ||
// err = c.Flags().Set(cmd.FlagAIBackendFull, string(ai.GPT3)) | ||
// Expect(err).To(BeNil()) | ||
// }) | ||
// AfterEach(func() { | ||
// ts.Close() | ||
// }) | ||
|
||
// It("executes properly", func() { | ||
// err := cmd.RunGenerate(c, []string{}) | ||
// // use the minimum amount of tokens from OpenAI | ||
// Expect(err).To(BeNil()) | ||
// }) | ||
// // TODO: add more tests for expected success | ||
// }) | ||
|
||
// When("OpenAI server is down", func() { | ||
// // BeforeEach(func() { | ||
// // // set a port that isn't taken | ||
// // err := c.Flags().Set(cmd.FlagOpenAIURLFull, "http://localhost:23423") | ||
// // Expect(err).To(BeNil()) | ||
// // }) | ||
// // It("fails", func() { | ||
// // err := cmd.RunGenerate(c, []string{}) | ||
// // Expect(err).To(HaveOccurred()) | ||
// // }) | ||
// // // TODO: add more cases that should fail | ||
// }) | ||
}) |