Test the execution example in Go
This commit is contained in:
28
examples/go-library/run/main_test.go
Normal file
28
examples/go-library/run/main_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRunExample(t *testing.T) {
|
||||
var output bytes.Buffer
|
||||
if err := run(t.Context(), ".", &output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var got struct {
|
||||
Output string `json:"output"`
|
||||
Valid *bool `json:"is_valid"`
|
||||
Status string `json:"validation_status"`
|
||||
Model string `json:"model"`
|
||||
Tokens *int `json:"total_tokens"`
|
||||
}
|
||||
if err := json.Unmarshal(output.Bytes(), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Output != "Ada finished the migration review." || got.Valid == nil || !*got.Valid ||
|
||||
got.Status != "passed" || got.Model != "offline-model" || got.Tokens == nil || *got.Tokens != 18 {
|
||||
t.Fatalf("unexpected execution summary: %+v", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user