Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mryashbhardwaj committed Dec 18, 2024
1 parent 8f62751 commit bf881d3
Showing 1 changed file with 6 additions and 52 deletions.
58 changes: 6 additions & 52 deletions ext/store/maxcompute/external_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package maxcompute_test

import (
"errors"
"fmt"
"testing"

"github.com/aliyun/aliyun-odps-go-sdk/odps"
Expand Down Expand Up @@ -76,62 +75,17 @@ func TestExternalTableHandle(t *testing.T) {
assert.NotNil(t, err)
assert.ErrorContains(t, err, "invalid resource name: "+projectName+"."+schemaName)
})
t.Run("returns error when failed to create schema", func(t *testing.T) {
table := new(mockExternalTable)
schema := new(mockMaxComputeSchema)
schema.On("Create", schemaName, true, mock.Anything).Return(fmt.Errorf("error while creating schema on maxcompute"))
defer schema.AssertExpectations(t)
odpsIns := new(mockOdpsIns)
odpsIns.On("CurrentSchemaName").Return(schemaName)
defer odpsIns.AssertExpectations(t)
tableHandle := maxcompute.NewExternalTableHandle(odpsIns, schema, table)

res, err := resource.NewResource(fullName, maxcompute.KindExternalTable, mcStore, tnnt, &metadata, spec)
assert.Nil(t, err)

err = tableHandle.Create(res)
assert.NotNil(t, err)
assert.ErrorContains(t, err, "error while creating schema on maxcompute")
})
t.Run("returns error when use invalid table schema data type", func(t *testing.T) {
table := new(mockExternalTable)
schema := new(mockMaxComputeSchema)
schema.On("Create", schemaName, true, mock.Anything).Return(nil)
defer schema.AssertExpectations(t)
odpsIns := new(mockOdpsIns)
odpsIns.On("CurrentSchemaName").Return(schemaName)
defer odpsIns.AssertExpectations(t)
tableHandle := maxcompute.NewExternalTableHandle(odpsIns, schema, table)

spec := map[string]any{
"description": "test create",
"source": map[string]any{
"type": "csv",
},
"schema": []map[string]any{
{
"name": "customer_id",
"type": "STRING_ERROR",
},
},
}
res, err := resource.NewResource(fullName, maxcompute.KindExternalTable, mcStore, tnnt, &metadata, spec)
assert.Nil(t, err)

err = tableHandle.Create(res)
assert.NotNil(t, err)
assert.ErrorContains(t, err, "failed to build table schema to create for "+fullName)
})
t.Run("returns error when table already present on maxcompute", func(t *testing.T) {
existTableErr := errors.New("Table or view already exists - table or view proj.test_table is already defined")
table := new(mockExternalTable)
table.On("CreateExternal", mock.Anything, false, emptyStringMap, emptyJars, emptyStringMap, emptyStringMap).Return(existTableErr)
defer table.AssertExpectations(t)
schema := new(mockMaxComputeSchema)
schema.On("Create", schemaName, true, mock.Anything).Return(nil)

defer schema.AssertExpectations(t)
odpsIns := new(mockOdpsIns)
odpsIns.On("CurrentSchemaName").Return(schemaName)

defer odpsIns.AssertExpectations(t)
tableHandle := maxcompute.NewExternalTableHandle(odpsIns, schema, table)

Expand All @@ -147,10 +101,10 @@ func TestExternalTableHandle(t *testing.T) {
table.On("CreateExternal", mock.Anything, false, emptyStringMap, emptyJars, emptyStringMap, emptyStringMap).Return(errors.New("some error"))
defer table.AssertExpectations(t)
schema := new(mockMaxComputeSchema)
schema.On("Create", schemaName, true, mock.Anything).Return(nil)

defer schema.AssertExpectations(t)
odpsIns := new(mockOdpsIns)
odpsIns.On("CurrentSchemaName").Return(schemaName)

defer odpsIns.AssertExpectations(t)
tableHandle := maxcompute.NewExternalTableHandle(odpsIns, schema, table)

Expand All @@ -166,10 +120,10 @@ func TestExternalTableHandle(t *testing.T) {
table.On("CreateExternal", mock.Anything, false, emptyStringMap, emptyJars, emptyStringMap, emptyStringMap).Return(nil)
defer table.AssertExpectations(t)
schema := new(mockMaxComputeSchema)
schema.On("Create", schemaName, true, mock.Anything).Return(nil)

defer schema.AssertExpectations(t)
odpsIns := new(mockOdpsIns)
odpsIns.On("CurrentSchemaName").Return(schemaName)

defer odpsIns.AssertExpectations(t)
tableHandle := maxcompute.NewExternalTableHandle(odpsIns, schema, table)

Expand Down

0 comments on commit bf881d3

Please sign in to comment.