Skip to content

Commit f37ac6a

Browse files
committed
feat: fix docker image version
fix docker image version fix docker image version
1 parent 31e24c5 commit f37ac6a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.22.0 AS build
1+
FROM golang:1.22.4 AS build
22
WORKDIR /app
33
COPY go.mod go.sum Makefile ./
44
ADD . ./

tests/controllers/blogs_controller_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,28 @@ func TestBlogIndex(t *testing.T) {
6262
assert.Equal(t, result.Blogs[0].Title, blog2.Title)
6363
assert.Equal(t, result.Blogs[0].Content, blog2.Content)
6464
}
65+
66+
func TestBlogIndexWithEmptyTable(t *testing.T) {
67+
gin.SetMode(gin.TestMode)
68+
req := httptest.NewRequest(http.MethodGet, "/blogs?format=json", nil)
69+
w := httptest.NewRecorder()
70+
ctx, _ := gin.CreateTestContext(w)
71+
ctx.Request = req
72+
models_test.TRdb.Db.Exec("DELETE * FROM blogs;")
73+
74+
store := blog.NewBlogStore(models_test.TRdb)
75+
hdr := blog.NewHandler(store)
76+
hdr.BlogIndex(ctx)
77+
78+
res := w.Result()
79+
defer res.Body.Close()
80+
// Check the status code
81+
assert.Equal(t, res.StatusCode, http.StatusOK, "API should return 200 stauts code")
82+
83+
// Read data from the body and parse the JSON
84+
var result Response
85+
err := json.NewDecoder(res.Body).Decode(&result)
86+
assert.NoError(t, err)
87+
// Check the length of the blogs array
88+
assert.Len(t, result.Blogs, 0)
89+
}

0 commit comments

Comments
 (0)