@@ -18,52 +18,39 @@ import { expect } from 'chai';
18
18
import { AI_TYPE } from './constants' ;
19
19
import { encodeInstanceIdentifier , decodeInstanceIdentifier } from './helpers' ;
20
20
import { AIError } from './errors' ;
21
- import { BackendType } from './public-types' ;
22
- import { InstanceIdentifier } from './types/internal' ;
23
21
import { AIErrorCode } from './types' ;
22
+ import { GoogleAIBackend , VertexAIBackend } from './backend' ;
24
23
25
24
describe ( 'Identifier Encoding/Decoding' , ( ) => {
26
25
describe ( 'encodeInstanceIdentifier' , ( ) => {
27
26
it ( 'should encode Vertex AI identifier with a specific location' , ( ) => {
28
- const identifier : InstanceIdentifier = {
29
- backendType : BackendType . VERTEX_AI ,
30
- location : 'us-central1'
31
- } ;
27
+ const backend = new VertexAIBackend ( 'us-central1' ) ;
32
28
const expected = `${ AI_TYPE } /vertexai/us-central1` ;
33
- expect ( encodeInstanceIdentifier ( identifier ) ) . to . equal ( expected ) ;
29
+ expect ( encodeInstanceIdentifier ( backend ) ) . to . equal ( expected ) ;
34
30
} ) ;
35
31
36
32
it ( 'should encode Vertex AI identifier using empty location' , ( ) => {
37
- const identifier : InstanceIdentifier = {
38
- backendType : BackendType . VERTEX_AI ,
39
- location : ''
40
- } ;
33
+ const backend = new VertexAIBackend ( '' ) ;
41
34
const expected = `${ AI_TYPE } /vertexai/` ;
42
- expect ( encodeInstanceIdentifier ( identifier ) ) . to . equal ( expected ) ;
35
+ expect ( encodeInstanceIdentifier ( backend ) ) . to . equal ( expected ) ;
43
36
} ) ;
44
37
45
38
it ( 'should encode Google AI identifier' , ( ) => {
46
- const identifier : InstanceIdentifier = {
47
- backendType : BackendType . GOOGLE_AI
48
- } ;
39
+ const backend = new GoogleAIBackend ( ) ;
49
40
const expected = `${ AI_TYPE } /googleai` ;
50
- expect ( encodeInstanceIdentifier ( identifier ) ) . to . equal ( expected ) ;
41
+ expect ( encodeInstanceIdentifier ( backend ) ) . to . equal ( expected ) ;
51
42
} ) ;
52
43
53
44
it ( 'should throw AIError for unknown backend type' , ( ) => {
54
- const identifier = {
55
- backendType : 'some-future-backend'
56
- } as any ; // bypass type checking for the test
57
-
58
- expect ( ( ) => encodeInstanceIdentifier ( identifier ) ) . to . throw ( AIError ) ;
45
+ expect ( ( ) => encodeInstanceIdentifier ( { } as any ) ) . to . throw ( AIError ) ;
59
46
60
47
try {
61
- encodeInstanceIdentifier ( identifier ) ;
48
+ encodeInstanceIdentifier ( { } as any ) ;
62
49
expect . fail ( 'Expected encodeInstanceIdentifier to throw' ) ;
63
50
} catch ( e ) {
64
51
expect ( e ) . to . be . instanceOf ( AIError ) ;
65
52
const error = e as AIError ;
66
- expect ( error . message ) . to . contain ( `Unknown backend` ) ;
53
+ expect ( error . message ) . to . contain ( 'Invalid backend' ) ;
67
54
expect ( error . code ) . to . equal ( AIErrorCode . ERROR ) ;
68
55
}
69
56
} ) ;
@@ -72,11 +59,8 @@ describe('Identifier Encoding/Decoding', () => {
72
59
describe ( 'decodeInstanceIdentifier' , ( ) => {
73
60
it ( 'should decode Vertex AI identifier with location' , ( ) => {
74
61
const encoded = `${ AI_TYPE } /vertexai/europe-west1` ;
75
- const expected : InstanceIdentifier = {
76
- backendType : BackendType . VERTEX_AI ,
77
- location : 'europe-west1'
78
- } ;
79
- expect ( decodeInstanceIdentifier ( encoded ) ) . to . deep . equal ( expected ) ;
62
+ const backend = new VertexAIBackend ( 'europe-west1' ) ;
63
+ expect ( decodeInstanceIdentifier ( encoded ) ) . to . deep . equal ( backend ) ;
80
64
} ) ;
81
65
82
66
it ( 'should throw an error if Vertex AI identifier string without explicit location part' , ( ) => {
@@ -98,10 +82,8 @@ describe('Identifier Encoding/Decoding', () => {
98
82
99
83
it ( 'should decode Google AI identifier' , ( ) => {
100
84
const encoded = `${ AI_TYPE } /googleai` ;
101
- const expected : InstanceIdentifier = {
102
- backendType : BackendType . GOOGLE_AI
103
- } ;
104
- expect ( decodeInstanceIdentifier ( encoded ) ) . to . deep . equal ( expected ) ;
85
+ const backend = new GoogleAIBackend ( ) ;
86
+ expect ( decodeInstanceIdentifier ( encoded ) ) . to . deep . equal ( backend ) ;
105
87
} ) ;
106
88
107
89
it ( 'should throw AIError for invalid backend string' , ( ) => {
0 commit comments