mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-02-17 02:22:30 -05:00
## Description > Should include a concise description of the changes (bug or feature), it's > impact, along with a summary of the solution ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [x] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
// 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 main
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
var goldenKeywords = []string{"Hilton Basel", "Hyatt Regency", "book"}
|
|
|
|
func TestQuickstartSample(t *testing.T) {
|
|
framework := os.Getenv("ORCH_NAME")
|
|
if framework == "" {
|
|
t.Skip("Skipping test: ORCH_NAME environment variable is not set.")
|
|
}
|
|
|
|
t.Logf("--- Testing: %s ---", framework)
|
|
|
|
if framework == "openAI" {
|
|
if os.Getenv("OPENAI_API_KEY") == "" {
|
|
t.Skip("Skipping test: OPENAI_API_KEY environment variable is not set for openAI framework.")
|
|
}
|
|
} else {
|
|
if os.Getenv("GOOGLE_API_KEY") == "" {
|
|
t.Skipf("Skipping test for %s: GOOGLE_API_KEY environment variable is not set.", framework)
|
|
}
|
|
}
|
|
|
|
sampleDir := filepath.Join(".", framework)
|
|
if _, err := os.Stat(sampleDir); os.IsNotExist(err) {
|
|
t.Fatalf("Test setup failed: directory for framework '%s' not found.", framework)
|
|
}
|
|
|
|
cmd := exec.Command("go", "run", ".")
|
|
cmd.Dir = sampleDir
|
|
var stdout, stderr bytes.Buffer
|
|
cmd.Stdout = &stdout
|
|
cmd.Stderr = &stderr
|
|
|
|
err := cmd.Run()
|
|
actualOutput := stdout.String()
|
|
|
|
if err != nil {
|
|
t.Fatalf("Script execution failed with error: %v\n--- STDERR ---\n%s", err, stderr.String())
|
|
}
|
|
if len(actualOutput) == 0 {
|
|
t.Fatal("Script ran successfully but produced no output.")
|
|
}
|
|
|
|
var missingKeywords []string
|
|
outputLower := strings.ToLower(actualOutput)
|
|
|
|
for _, keyword := range goldenKeywords {
|
|
kw := strings.TrimSpace(keyword)
|
|
if kw != "" && !strings.Contains(outputLower, strings.ToLower(kw)) {
|
|
missingKeywords = append(missingKeywords, kw)
|
|
}
|
|
}
|
|
|
|
if len(missingKeywords) > 0 {
|
|
t.Fatalf("FAIL: The following keywords were missing from the output: [%s]", strings.Join(missingKeywords, ", "))
|
|
}
|
|
}
|