小编Dis*_*uan的帖子

Golang 模拟函数被调用两次

我正在编写单元测试来测试 main.go ,并且在函数内部调用 Get 函数( DeviceRepo.Get() )两次,然后我想模拟返回不同的 Get 函数,但我可以在第一次调用时进行模拟,所以我不知道如何第二次模拟 Get 函数?

main.go:

type DeviceInterface interface {}
type DeviceStruct struct{}

var DeviceRepo repositories.DeviceRepoInterface =  &repositories.DeviceRepoStruct{}

func (d *DeviceStruct) CheckDevice(familyname string, name string, firmwareversion string) string {
deviceList, deviceListErr := DeviceRepo.Get(familyname, name, firmwareversion)

if deviceListErr != "" {
    return "some error"
}

if len(deviceList) == 0 {
    deviceList, _ := DeviceRepo.Get(familyname, name, "")

    if len(deviceList) > 0 {
        return "Invalid firmware version."
    } else {
        return "Unknown device."
    }
}

return "Success" …
Run Code Online (Sandbox Code Playgroud)

unit-testing go

5
推荐指数
2
解决办法
9532
查看次数

为什么使用 Docker 容器的 NextJS 在更改开发环境的代码后没有重新加载?

我正在尝试使用 Dockerfile 在 Docker 容器上运行 NextJS,并通过 docker-compose 运行,在我更改了 JS 文件(例如 index.js)中的代码后,Next 服务器没有重新加载。

但是,当我尝试在不使用 Docker 的情况下在室外运行时(通过直接执行“npm run dev”命令),Next 服务器确实顺利重新加载。

我还尝试通过“nodemon”命令(在容器内)运行服务器,它也没有成功。

Dockerfile:

FROM node:10.14.2-alpine
COPY . /home/next_app
WORKDIR /home/next_app
RUN npm install
Run Code Online (Sandbox Code Playgroud)

docker-compose.yml:

version: "3.6"
services:
  self_nextjs:
    container_name: self_nextjs
    build:
        context: ./app
        dockerfile: Dockerfile
    ports:
        - 3000:3000
    volumes:
        - ./app:/home/next_app
        - /home/next_app/node_modules
    networks:
        - zen_frontend
    restart: always
    command: npm run dev

networks:
  zen_frontend:
      name: zen_frontend
      driver: bridge
Run Code Online (Sandbox Code Playgroud)

任何建议,将不胜感激。

node.js docker reactjs docker-compose next.js

5
推荐指数
3
解决办法
3644
查看次数

标签 统计

docker ×1

docker-compose ×1

go ×1

next.js ×1

node.js ×1

reactjs ×1

unit-testing ×1