Skip to content

Commit e1ccf96

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

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

gptscript_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,36 @@ 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+
DisableCache: true,
356+
CredentialOverrides: []string{
357+
"test.ts.credential_override:TEST_CRED=foo",
358+
},
359+
})
360+
if err != nil {
361+
t.Fatalf("Error executing file: %v", err)
362+
}
363+
364+
out, err := run.Text()
365+
if err != nil {
366+
t.Errorf("Error reading output: %v", err)
367+
}
368+
369+
if !strings.Contains(out, "foo") {
370+
t.Errorf("Unexpected output: %s", out)
371+
}
372+
373+
if len(run.ErrorOutput()) != 0 {
374+
t.Error("Should have no stderr output")
375+
}
376+
}
377+
348378
func TestParseSimpleFile(t *testing.T) {
349379
wd, err := os.Getwd()
350380
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)