package main import ( "context" "fmt" "log" "time" "git.x2erp.com/qdy/go-base/model/request/queryreq" "git.x2erp.com/qdy/go-base/sdk/configure" ) func main() { fmt.Println("Testing Configure SDK...") // 1. 测试创建客户端 client, err := configure.NewBasicAuthClient("http://localhost:8080", "admin", "123") if err != nil { log.Fatalf("Failed to create client: %v", err) } fmt.Printf("Client created successfully: URL=%s\n", client.GetConfig().BaseURL) // 2. 测试查询列表 fmt.Println("\nTesting ListTables...") query := &configure.DicTableQueryRequest{ QueryRequest: queryreq.QueryRequest{ Page: 0, PageSize: 10, }, } ctx1, cancel1 := context.WithTimeout(context.Background(), 10*time.Second) defer cancel1() result, err := client.ListTables(ctx1, query) if err != nil { log.Fatalf("Failed to list tables: %v", err) } fmt.Printf("ListTables success: TotalCount=%d, LastPage=%d\n", result.TotalCount, result.LastPage) fmt.Printf("Tables count: %d\n", len(result.Data)) // 3. 测试创建表 fmt.Println("\nTesting SaveTable...") req := &configure.DicTableRequest{ TableID: "sdk_test_table_001", TableType: "实体表", Name: "SDK测试表001", Description: "SDK集成测试表", Fields: []configure.DicTableFieldRequest{ { FieldID: "sdk_test_table_001.id", TableID: "sdk_test_table_001", FiledType: "实际字段", DataType: "数值型", FieldName: "id", FieldNameCN: "主键ID", Description: "SDK测试主键字段", }, { FieldID: "sdk_test_table_001.name", TableID: "sdk_test_table_001", FiledType: "实际字段", DataType: "字符型", FieldName: "name", FieldNameCN: "名称", Description: "SDK测试名称字段", }, }, } ctx2, cancel2 := context.WithTimeout(context.Background(), 10*time.Second) defer cancel2() detail, err := client.SaveTable(ctx2, req) if err != nil { log.Fatalf("Failed to save table: %v", err) } fmt.Printf("SaveTable success: TableID=%s, Name=%s, Fields=%d\n", detail.Table.TableID, detail.Table.Name, len(detail.Fields)) // 4. 测试查询详情 fmt.Println("\nTesting GetTable...") ctx3, cancel3 := context.WithTimeout(context.Background(), 10*time.Second) defer cancel3() tableDetail, err := client.GetTable(ctx3, "sdk_test_table_001") if err != nil { log.Fatalf("Failed to get table: %v", err) } fmt.Printf("GetTable success: TableID=%s, Description=%s\n", tableDetail.Table.TableID, tableDetail.Table.Description) fmt.Printf("Fields in detail: %d\n", len(tableDetail.Fields)) // 5. 测试更新表 fmt.Println("\nTesting UpdateTable...") ctx4, cancel4 := context.WithTimeout(context.Background(), 10*time.Second) defer cancel4() req.Description = "更新后的SDK测试表描述" req.Name = "更新后的SDK测试表001" // 添加一个新字段 req.Fields = append(req.Fields, configure.DicTableFieldRequest{ FieldID: "sdk_test_table_001.status", TableID: "sdk_test_table_001", FiledType: "实际字段", DataType: "字符型", FieldName: "status", FieldNameCN: "状态", Description: "SDK测试状态字段", }) updatedDetail, err := client.SaveTable(ctx4, req) if err != nil { log.Fatalf("Failed to update table: %v", err) } fmt.Printf("UpdateTable success: Description=%s, Fields=%d\n", updatedDetail.Table.Description, len(updatedDetail.Fields)) // 6. 测试删除表 fmt.Println("\nTesting DeleteTable...") ctx5, cancel5 := context.WithTimeout(context.Background(), 10*time.Second) defer cancel5() if err := client.DeleteTable(ctx5, "sdk_test_table_001"); err != nil { log.Fatalf("Failed to delete table: %v", err) } fmt.Println("DeleteTable success") // 7. 验证删除 fmt.Println("\nVerifying deletion...") ctx6, cancel6 := context.WithTimeout(context.Background(), 10*time.Second) defer cancel6() _, err = client.GetTable(ctx6, "sdk_test_table_001") if err == configure.ErrNotFound { fmt.Println("Table deleted successfully (NotFound error as expected)") } else if err != nil { fmt.Printf("Unexpected error: %v\n", err) } else { fmt.Println("ERROR: Table still exists after deletion!") } fmt.Println("\nAll tests passed!") }