drbz99867 2016-07-03 06:34
浏览 7

如何测试/重写标签启用功能?

I have a code that uses labels and doesn't separate logic and view (dialog-based). There are bugs and aren't any line of unittests =(

func UiNetworks(ui *gui.DialogUi, data *xmlinput.XMLInputData, allowedNics host.NICList, gconf *guest.Config) error {
    guestPciSlotCounter := data.GuestNic.PCI.FirstSlot
    lastGuestPciSlotCounter := guestPciSlotCounter
    portCounter := 1
    lastPortCounter := portCounter
    i := 0

MainLoop:
    for i < len(data.Networks.Configs) {
        net := data.Networks.Configs[i]
    PolicyLoop:
        for {
            var modes []xmlinput.ConnectionMode

            if net.UiModeBinding == nil || len(net.UiModeBinding) == 0 {
                for _, mode := range net.Modes {
                    modes = append(modes, mode.Type)
                }
            } else {
                var err error
                modes, err = uiNetworkPolicySelector(ui, net)
                if err != nil {
                    switch err.Error() {
                    case gui.DialogMoveBack:
                        gconf.Networks = gconf.Networks[:i]
                        gconf.NICLists = gconf.NICLists[:i]
                        portCounter = lastPortCounter - 1
                        guestPciSlotCounter = lastGuestPciSlotCounter - 1
                        if i == 0 {
                            return err
                        }
                        i--
                        continue MainLoop
                    case gui.DialogNext:
                        i++
                        continue MainLoop
                    case gui.DialogExit:
                        os.Exit(1)
                    default:
                        return err
                    }

                }
            }

            retainedNics, err := host_hwfilter.NicsByType(allowedNics, modes)
            if err != nil {
                return utils.FormatError(err)
            }
            if len(retainedNics) == 0 {
                ui.Output(gui.Warning, "No interfaces have been found.", "Press <OK> to return to menu.")
                continue MainLoop
            }
            if net.UiResetCounter {
                portCounter = 1
            }
            list, err := uiNicSelectMenu(ui, data, &portCounter, &guestPciSlotCounter, retainedNics, net, i)
            if err != nil {
                switch err.Error() {
                case gui.DialogMoveBack:
                    if i == 0 {
                        return err
                    }
                    gconf.Networks = gconf.Networks[:i]
                    gconf.NICLists = gconf.NICLists[:i]
                    continue PolicyLoop
                case gui.DialogExit:
                    os.Exit(1)
                }
            }

            gconf.Networks = append(gconf.Networks, net)
            gconf.NICLists = append(gconf.NICLists, list)
            lastPortCounter = portCounter
            lastGuestPciSlotCounter = guestPciSlotCounter
            i++
            break
        }
    }
    return nil
}

How I can test it? Or rewrite it?

Regards.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制