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

时间:2016-07-03 06:34:29

标签: go

我有一个使用标签的代码,并没有分离逻辑和视图(基于对话框)。有任何错误,并不是任何单位测试线=(

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
}

我如何测试它?或者改写它?

问候。

0 个答案:

没有答案