1package azure
2
3import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7)
8
9func TestParseAzureURL(t *testing.T) {
10 tests := []struct {
11 name string
12 input string
13 expected string
14 }{
15 {
16 name: "full https openai azure url",
17 input: "https://my-resource.openai.azure.com",
18 expected: "https://my-resource.openai.azure.com/openai/v1",
19 },
20 {
21 name: "full https openai azure url with trailing slash",
22 input: "https://my-resource.openai.azure.com/",
23 expected: "https://my-resource.openai.azure.com/openai/v1",
24 },
25 {
26 name: "full https cognitiveservices azure url",
27 input: "https://my-resource.cognitiveservices.azure.com",
28 expected: "https://my-resource.openai.azure.com/openai/v1",
29 },
30 {
31 name: "full https services.ai azure url with path",
32 input: "https://fantasy-playground-resource.services.ai.azure.com/api/projects/fantasy-playground",
33 expected: "https://fantasy-playground-resource.openai.azure.com/openai/v1",
34 },
35 {
36 name: "openai azure url without protocol",
37 input: "my-resource.openai.azure.com",
38 expected: "https://my-resource.openai.azure.com/openai/v1",
39 },
40 {
41 name: "cognitiveservices azure url without protocol",
42 input: "my-resource.cognitiveservices.azure.com",
43 expected: "https://my-resource.openai.azure.com/openai/v1",
44 },
45 {
46 name: "services.ai azure url without protocol",
47 input: "fantasy-playground-resource.services.ai.azure.com/api/projects/fantasy-playground",
48 expected: "https://fantasy-playground-resource.openai.azure.com/openai/v1",
49 },
50 {
51 name: "resource with hyphens",
52 input: "https://my-complex-resource-123.openai.azure.com",
53 expected: "https://my-complex-resource-123.openai.azure.com/openai/v1",
54 },
55 {
56 name: "openai azure url with trailing slash",
57 input: "https://fantasy-playground-resource.openai.azure.com/",
58 expected: "https://fantasy-playground-resource.openai.azure.com/openai/v1",
59 },
60 {
61 name: "cognitiveservices azure url with trailing slash",
62 input: "https://fantasy-playground-resource.cognitiveservices.azure.com/",
63 expected: "https://fantasy-playground-resource.openai.azure.com/openai/v1",
64 },
65 {
66 name: "malformed url - non azure domain",
67 input: "https://non.sense.com",
68 expected: "https://non.sense.com",
69 },
70 {
71 name: "malformed url - simple domain",
72 input: "example.com",
73 expected: "https://example.com",
74 },
75 {
76 name: "custom endpoint with protocol",
77 input: "https://custom-endpoint.example.com",
78 expected: "https://custom-endpoint.example.com",
79 },
80 {
81 name: "custom endpoint without protocol",
82 input: "custom-endpoint.example.com",
83 expected: "https://custom-endpoint.example.com",
84 },
85 {
86 name: "localhost",
87 input: "http://localhost:8080",
88 expected: "http://localhost:8080",
89 },
90 }
91
92 for _, tt := range tests {
93 t.Run(tt.name, func(t *testing.T) {
94 result := parseAzureURL(tt.input)
95 assert.Equal(t, tt.expected, result)
96 })
97 }
98}