package chain import "testing" func TestChain(t *testing.T) { // 创建患者实例 patient := &Patient{name: "张三"} // 创建看病处理者链 hospital := &HospitalChainHandler{} // 设置病人看病的链路 processes := []PatientHandler{ &Reception{}, &Clinic{}, &Cashier{}, &Pharmacy{}, } var current PatientHandler = hospital for _, process := range processes { current = current.SetNext(process) } // 执行处理链 if err := hospital.Execute(patient); err != nil { t.Errorf("处理患者失败: %v", err) } // 检查最终状态 if patient.status != PatientStatusPharmacy { t.Errorf("患者状态不正确,期望 %d,实际 %d", PatientStatusPharmacy, patient.status) } }