@@ -72,7 +72,7 @@ func (f *fakeClient) Close() error {
7272 return nil
7373}
7474
75- func TestCreateEmbededTextsWithClient (t * testing.T ) {
75+ func TestCreateCodeSampleEmbeddings (t * testing.T ) {
7676 ctx := context .Background ()
7777
7878 goMysqlMigrationConcept = []byte (`[
@@ -87,14 +87,14 @@ func TestCreateEmbededTextsWithClient(t *testing.T) {
8787 ]` )
8888
8989 client := & fakeClient {}
90- concepts , err := createEmbededTextsWithClient (ctx , client , "test-proj" , "us-central1" , "mock-model" , "go-sql-driver/mysql_go-sql-spanner" )
90+ concepts , err := createCodeSampleEmbeddings (ctx , client , "test-proj" , "us-central1" , "mock-model" , "go-sql-driver/mysql_go-sql-spanner" )
9191
9292 assert .NoError (t , err )
9393 assert .Len (t , concepts , 1 )
9494 assert .InDeltaSlice (t , []float32 {0.1 , 0.2 , 0.3 }, concepts [0 ].Embedding , 0.001 )
9595}
9696
97- func TestCreateEmbededTextsWithClientJava (t * testing.T ) {
97+ func TestCreateCodeSampleEmbeddingsJava (t * testing.T ) {
9898 ctx := context .Background ()
9999
100100 javaMysqlMigrationConcept = []byte (`[
@@ -109,41 +109,41 @@ func TestCreateEmbededTextsWithClientJava(t *testing.T) {
109109 ]` )
110110
111111 client := & fakeClient {}
112- concepts , err := createEmbededTextsWithClient (ctx , client , "test-proj" , "us-central1" , "mock-model" , "jdbc_jdbc" )
112+ concepts , err := createCodeSampleEmbeddings (ctx , client , "test-proj" , "us-central1" , "mock-model" , "jdbc_jdbc" )
113113
114114 assert .NoError (t , err )
115115 assert .Len (t , concepts , 1 )
116116 assert .InDeltaSlice (t , []float32 {0.1 , 0.2 , 0.3 }, concepts [0 ].Embedding , 0.001 )
117117}
118118
119- func TestCreateEmbededTextsWithClient_UnsupportedLanguage (t * testing.T ) {
119+ func TestCreateCodeSampleEmbeddings_UnsupportedLanguage (t * testing.T ) {
120120 ctx := context .Background ()
121121 client := & fakeClient {}
122122
123- concepts , err := createEmbededTextsWithClient (ctx , client , "test-proj" , "us-central1" , "mock-model" , "python" )
123+ concepts , err := createCodeSampleEmbeddings (ctx , client , "test-proj" , "us-central1" , "mock-model" , "python" )
124124
125125 assert .Nil (t , concepts )
126126 assert .Error (t , err )
127127 assert .Contains (t , err .Error (), "unsupported sourceTargetFramework" )
128128}
129- func TestCreateEmbededTextsWithClient_PredictError (t * testing.T ) {
129+ func TestCreateCodeSampleEmbeddings_PredictError (t * testing.T ) {
130130 ctx := context .Background ()
131131 client := & fakeClient {predictErr : errors .New ("predict failure" )}
132132
133- _ , err := createEmbededTextsWithClient (ctx , client , "test-proj" , "us-central1" , "mock-model" , "go-sql-driver/mysql_go-sql-spanner" )
133+ _ , err := createCodeSampleEmbeddings (ctx , client , "test-proj" , "us-central1" , "mock-model" , "go-sql-driver/mysql_go-sql-spanner" )
134134 assert .Error (t , err )
135135 assert .Contains (t , err .Error (), "predict failure" )
136136}
137137
138- func TestCreateEmbededTextsWithClient_InvalidJSON (t * testing.T ) {
138+ func TestCreateCodeSampleEmbeddings_InvalidJSON (t * testing.T ) {
139139 ctx := context .Background ()
140140 // Temporarily assign invalid JSON
141141 oldGoConcept := goMysqlMigrationConcept
142142 goMysqlMigrationConcept = []byte ("invalid json" )
143143 defer func () { goMysqlMigrationConcept = oldGoConcept }()
144144
145145 client := & fakeClient {}
146- _ , err := createEmbededTextsWithClient (ctx , client , "test-proj" , "us-central1" , "mock-model" , "go-sql-driver/mysql_go-sql-spanner" )
146+ _ , err := createCodeSampleEmbeddings (ctx , client , "test-proj" , "us-central1" , "mock-model" , "go-sql-driver/mysql_go-sql-spanner" )
147147 assert .Error (t , err )
148148 assert .Contains (t , err .Error (), "invalid character" )
149149}
@@ -154,3 +154,25 @@ func TestFakeClient_CloseCalled(t *testing.T) {
154154 assert .NoError (t , err )
155155 assert .True (t , client .closeCalled )
156156}
157+
158+ func TestCreateQueryExampleEmbeddingsWithClient (t * testing.T ) {
159+ oldMysqlQueryExamples := mysqlQueryExamples
160+ defer func () { mysqlQueryExamples = oldMysqlQueryExamples }()
161+ mysqlQueryExamples = []byte (`[
162+ {
163+ "id": "1",
164+ "example": "SELECT * FROM employees",
165+ "rewrite": {
166+ "theory": "simple select",
167+ "options": [{"mysql_code": "SELECT * FROM employees", "spanner_code": "SELECT * FROM employees"}]
168+ }
169+ }
170+ ]` )
171+ ctx := context .Background ()
172+ client := & fakeClient {}
173+ concepts , err := createQuerySampleEmbeddings (ctx , client , "test-proj" , "us-central1" , "mock-model" )
174+ assert .NoError (t , err )
175+ assert .Len (t , concepts , 1 )
176+ assert .Equal (t , "1" , concepts [0 ].ID )
177+ assert .InDeltaSlice (t , []float32 {0.1 , 0.2 , 0.3 }, concepts [0 ].Embedding , 0.001 )
178+ }
0 commit comments