Skip to content

Commit 2012ba3

Browse files
committed
test: add credential override test
Signed-off-by: Nick Hale <[email protected]>
1 parent 9aad7f3 commit 2012ba3

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

gptscript_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,35 @@ func TestStreamRun(t *testing.T) {
345345
}
346346
}
347347

348+
func TestCredentialOverride(t *testing.T) {
349+
wd, err := os.Getwd()
350+
if err != nil {
351+
t.Fatalf("Error getting working directory: %v", err)
352+
}
353+
354+
run, err := g.Run(context.Background(), wd+"/test/credential-override.gpt", Options{
355+
CredentialOverrides: []string{
356+
"test.ts.credential_override:TEST_CRED=foo",
357+
},
358+
})
359+
if err != nil {
360+
t.Fatalf("Error executing file: %v", err)
361+
}
362+
363+
out, err := run.Text()
364+
if err != nil {
365+
t.Errorf("Error reading output: %v", err)
366+
}
367+
368+
if !strings.Contains(out, "foo") {
369+
t.Errorf("Unexpected output: %s", out)
370+
}
371+
372+
if len(run.ErrorOutput()) != 0 {
373+
t.Error("Should have no stderr output")
374+
}
375+
}
376+
348377
func TestParseSimpleFile(t *testing.T) {
349378
wd, err := os.Getwd()
350379
if err != nil {

test/credential-override.gpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
credentials: github.com/gptscript-ai/credential as test.ts.credential_override with TEST_CRED as env
2+
3+
#!/usr/bin/env bash
4+
5+
echo "${TEST_CRED}"

0 commit comments

Comments
 (0)