Watson-Sei / watson-sei-official

watson-sei.tokyoがドメインのなんでもサイト
2 stars 1 forks source link

Unit Test #17

Open Watson-Sei opened 3 years ago

Watson-Sei commented 3 years ago

ユニットテストのコードを早めに実装してください。

Watson-Sei commented 3 years ago

Model側のテストは完了 残りは、Controllerのテスト

Watson-Sei commented 3 years ago

GetAll, Createは完了。 ByIDとUpdateが両方とも同時編集なのが大変

Watson-Sei commented 3 years ago

以下のエラーが出て、GetArticleById, UpdateArticle, DeleteArticleの引数を使うメソッドが使えない 原因はuint64という引数が問題らしいがいまだにわからないので正月明けに質問する

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

--- FAIL: TestDeleteArticleController_DeleteArticle (0.00s)
panic: 

mock: Unexpected Method Call
-----------------------------

DeleteArticle(uint64)
                0: 0x0

The closest call I have is: 

DeleteArticle(uint64)
                0: 0x1

Diff: 0: FAIL:  (uint64=0) != (uint64=1) [recovered]
        panic: 

mock: Unexpected Method Call
-----------------------------

DeleteArticle(uint64)
                0: 0x0

The closest call I have is: 

DeleteArticle(uint64)
                0: 0x1

Diff: 0: FAIL:  (uint64=0) != (uint64=1)

goroutine 25 [running]:
testing.tRunner.func1.1(0x13d3b00, 0xc000432730)
        /usr/local/Cellar/go/1.15.5/libexec/src/testing/testing.go:1072 +0x30d
testing.tRunner.func1(0xc000426600)
        /usr/local/Cellar/go/1.15.5/libexec/src/testing/testing.go:1075 +0x41a
panic(0x13d3b00, 0xc000432730)
        /usr/local/Cellar/go/1.15.5/libexec/src/runtime/panic.go:969 +0x1b9
github.com/stretchr/testify/mock.(*Mock).fail(0xc0003eb4f0, 0x14732bf, 0x6f, 0xc0003e1940, 0x4, 0x4)
        /Users/watson-sei/go/src/github.com/Watson-Sei/watson-sei-official/pkg/mod/github.com/stretchr/testify@v1.5.1/mock/mock.go:236 +0x17f
github.com/stretchr/testify/mock.(*Mock).MethodCalled(0xc0003eb4f0, 0x16b46a2, 0xd, 0xc0004325a0, 0x1, 0x1, 0xc0003e1900, 0x4, 0x4)
        /Users/watson-sei/go/src/github.com/Watson-Sei/watson-sei-official/pkg/mod/github.com/stretchr/testify@v1.5.1/mock/mock.go:366 +0x65d
github.com/stretchr/testify/mock.(*Mock).Called(0xc0003eb4f0, 0xc0004325a0, 0x1, 0x1, 0xc000438960, 0xc0000d14d0, 0x145bba9)
        /Users/watson-sei/go/src/github.com/Watson-Sei/watson-sei-official/pkg/mod/github.com/stretchr/testify@v1.5.1/mock/mock.go:338 +0x1ab
github.com/Watson-Sei/watson-sei-official/api_v1/Controllers.(*ModelMock).DeleteArticle(0xc0003eb4f0, 0x0, 0xa, 0x40)
        /Users/watson-sei/go/src/github.com/Watson-Sei/watson-sei-official/api_v1/Controllers/Config_test.go:141 +0x91
github.com/Watson-Sei/watson-sei-official/api_v1/Controllers.DeleteArticleController.DeleteArticle(0x14e1d00, 0xc0003eb4f0, 0xc000438960)
        /Users/watson-sei/go/src/github.com/Watson-Sei/watson-sei-official/api_v1/Controllers/Article.go:76 +0xb2
github.com/Watson-Sei/watson-sei-official/api_v1/Controllers.TestDeleteArticleController_DeleteArticle(0xc000426600)
        /Users/watson-sei/go/src/github.com/Watson-Sei/watson-sei-official/api_v1/Controllers/Config_test.go:160 +0x205
testing.tRunner(0xc000426600, 0x147a1c0)
        /usr/local/Cellar/go/1.15.5/libexec/src/testing/testing.go:1123 +0xef
created by testing.(*T).Run
        /usr/local/Cellar/go/1.15.5/libexec/src/testing/testing.go:1168 +0x2b3
exit status 2
FAIL    github.com/Watson-Sei/watson-sei-official/api_v1/Controllers    0.313s