Skip TestLiveOpenAiApi for non-master branches to allow dependabot PRs to pass GH actions

This commit is contained in:
David Dworken 2025-03-02 10:49:29 -08:00
parent 56d5189538
commit 42f9659b47
No known key found for this signature in database
2 changed files with 15 additions and 1 deletions

View File

@ -13,7 +13,7 @@ import (
// A basic sanity test that our integration with the OpenAI API is correct and is returning reasonable results (at least for a very basic query)
func TestLiveOpenAiApi(t *testing.T) {
if os.Getenv("OPENAI_API_KEY") == "" {
if testutils.IsGithubAction() {
if testutils.IsGithubAction() && testutils.GetCurrentGitBranch(t) == testutils.DefaultGitBranchName {
t.Fatal("OPENAI_API_KEY is not set, cannot run TestLiveOpenAiApi")
} else {
t.Skip("Skipping test since OPENAI_API_KEY is not set")

View File

@ -425,3 +425,17 @@ func GetOsVersion(t *testing.T) string {
version := unix.ByteSliceToString(uts.Release[:])
return strings.Split(version, ".")[0]
}
const DefaultGitBranchName = "master"
func GetCurrentGitBranch(t *testing.T) string {
cmd := exec.Command("git", "symbolic-ref", "--short", "HEAD")
var out bytes.Buffer
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
t.Fatalf("failed to get current git branch: %v", err)
}
return strings.TrimSpace(out.String())
}