teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

追加

2019/09/07 09:32

投稿

jpskgc
jpskgc

スコア19

title CHANGED
File without changes
body CHANGED
@@ -10,15 +10,15 @@
10
10
  $ go test -v
11
11
  --- FAIL: TestDaoSuite (0.00s)
12
12
  --- FAIL: TestDaoSuite/TestDeleteArticleDao (0.00s)
13
- dao_test.go:227:
13
+ dao_test.go:221:
14
- Error Trace: dao_test.go:227
14
+ Error Trace: dao_test.go:221
15
15
  suite.go:122
16
16
  panic.go:522
17
17
  panic.go:82
18
18
  signal_unix.go:390
19
- s3.go:71
19
+ s3.go:66
20
- dao.go:64
20
+ dao.go:74
21
- dao_test.go:162
21
+ dao_test.go:156
22
22
  Error: Received unexpected error:
23
23
  there is a remaining expectation which was not matched: ExpectedBegin => expecting database transaction Begin
24
24
  Test: TestDaoSuite/TestDeleteArticleDao
@@ -147,4 +147,11 @@
147
147
  ・ci-tool: travis
148
148
  ・deploy: aws elastic beanstalk
149
149
  ```
150
- 以上お手数ですが、ご教授いただけると幸いです。よろしくお願いいたします。
150
+ 以上お手数ですが、ご教授いただけると幸いです。よろしくお願いいたします。
151
+
152
+ ### 追記(全ソース版)
153
+ 上記3ファイルの全ソースを追記いたします。
154
+ 文字数制限に引っかかるため、コードは以下のgithubをご参照下さい。(ブランチ:`fix-test-dao`)
155
+ [https://github.com/jpskgc/article/tree/fix-test-dao](https://github.com/jpskgc/article/tree/fix-test-dao)
156
+
157
+ 以上よろしくお願いいたいます。

1

修正

2019/09/07 09:32

投稿

jpskgc
jpskgc

スコア19

title CHANGED
File without changes
body CHANGED
@@ -6,14 +6,23 @@
6
6
 
7
7
  ### 発生している問題・エラーメッセージ
8
8
  `dao_test.go`のテストを実行すると以下のエラーが発生して、テストがfailします。
9
- ```
9
+ ```command
10
10
  $ go test -v
11
11
  --- FAIL: TestDaoSuite (0.00s)
12
12
  --- FAIL: TestDaoSuite/TestDeleteArticleDao (0.00s)
13
+ dao_test.go:227:
14
+ Error Trace: dao_test.go:227
15
+ suite.go:122
16
+ panic.go:522
17
+ panic.go:82
18
+ signal_unix.go:390
19
+ s3.go:71
20
+ dao.go:64
21
+ dao_test.go:162
22
+ Error: Received unexpected error:
23
+ there is a remaining expectation which was not matched: ExpectedBegin => expecting database transaction Begin
24
+ Test: TestDaoSuite/TestDeleteArticleDao
13
25
  suite.go:61: test panicked: runtime error: invalid memory address or nil pointer dereference
14
- FAIL
15
- exit status 1
16
- FAIL article/api/dao 0.077s
17
26
  ```
18
27
 
19
28
  ### 該当のソースコード
@@ -69,7 +78,7 @@
69
78
  // some method
70
79
 
71
80
  // DeleteArticleDaoは別パッケージのメソッドのため、呼び出しの際に落ちてしまいます。
72
- s.dao.DeleteArticleDao(context)
81
+ s.dao.DeleteArticleDao("1")
73
82
  }
74
83
 
75
84
  func (s *DaoSuite) TearDownTest() {
@@ -93,11 +102,11 @@
93
102
  return objs
94
103
  }
95
104
 
96
- func (d *Dao) DeleteArticleDao(c *gin.Context) {
105
+ func (d *Dao) DeleteArticleDao(id string) {
97
- //imageNamesの生成
106
+ //imageNameの生成
98
107
 
99
108
  //ここで、別パッケージのメソッドを呼び出しています。ここでテストが落ちます。
100
- d.s3.DeleteS3Image(imageNames)
109
+ d.s3.DeleteS3Image(imageName)
101
110
 
102
111
  }
103
112
  ```
@@ -114,8 +123,7 @@
114
123
  }
115
124
 
116
125
  type DaoInterface interface {
117
- PostImageToS3(c *gin.Context) []util.ImageName
118
- DeleteS3Image(imageNames []util.ImageName)
126
+ DeleteS3Image(imageName util.ImageName) error
119
127
  }
120
128
 
121
129
  func NewS3(appid, secret string) *S3 {
@@ -124,7 +132,7 @@
124
132
  }
125
133
 
126
134
  //このメソッドがうまく呼び出せずに落ちています。おそらくモックにすべきなのですが方法がわかっていません。
127
- func (objs *S3) DeleteS3Image(imageNames []util.ImageName) {
135
+ func (objs *S3) DeleteS3Image(imageName util.ImageName) error {
128
136
  // method
129
137
  }
130
138
  ```