-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
49 lines (42 loc) · 1.33 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"os"
"testing"
)
func TestCheckEnvVar(t *testing.T) {
// Backup original environment variable value
originalKey := os.Getenv("OPEN_AI_KEY")
defer os.Setenv("OPEN_AI_KEY", originalKey)
// Test with OPEN_AI_KEY set
os.Setenv("OPEN_AI_KEY", "test_key")
checkEnvVar()
// Test with OPEN_AI_KEY not set
os.Setenv("OPEN_AI_KEY", "")
defer func() {
if r := recover(); r == nil {
t.Errorf("checkEnvVar() should panic when OPEN_AI_KEY is not set")
}
}()
checkEnvVar()
}
func TestExtractShellCommand(t *testing.T) {
response := "Action: Shell[[[echo 'FROM mcr.microsoft.com/dotnet/sdk:5.0\nWORKDIR /app\nCOPY . .\nRUN dotnet publish -c Release -o out\nENTRYPOINT [\"dotnet\", \"out/MyApp.dll\"]' > Dockerfile]]]"
expected := "echo 'FROM mcr.microsoft.com/dotnet/sdk:5.0\nWORKDIR /app\nCOPY . .\nRUN dotnet publish -c Release -o out\nENTRYPOINT [\"dotnet\", \"out/MyApp.dll\"]' > Dockerfile"
result, err := extractShellCommand(response)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if result != expected {
t.Errorf("Expected: %s, got: %s", expected, result)
}
response = "Action: Finish[]"
_, err = extractShellCommand(response)
if err == nil {
t.Error("Expected an error, got nil")
}
response = ""
_, err = extractShellCommand(response)
if err == nil {
t.Error("Expected an error, got nil")
}
}