-
Notifications
You must be signed in to change notification settings - Fork 28
/
log.go
148 lines (108 loc) · 3.17 KB
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// SPDX-License-Identifier: Apache-2.0
package server
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/go-vela/types"
"github.com/go-vela/types/library"
)
const (
// LogResp represents a JSON return for a single log.
LogResp = `{
"id": 1,
"build_id": 1,
"repo_id": 1,
"service_id": 1,
"step_id": 1,
"data": "SGVsbG8sIFdvcmxkIQ=="
}`
)
// getServiceLog has a param :service returns mock JSON for a http GET.
//
// Pass "0" to :step to test receiving a http 404 response.
func getServiceLog(c *gin.Context) {
s := c.Param("service")
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Log %s does not exist", s)
c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
return
}
data := []byte(LogResp)
var body library.Log
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
}
// addServiceLog returns mock JSON for a http GET.
func addServiceLog(c *gin.Context) {
c.JSON(http.StatusCreated, nil)
}
// updateServiceLog has a param :service returns mock JSON for a http PUT.
//
// Pass "0" to :step to test receiving a http 404 response.
func updateServiceLog(c *gin.Context) {
s := c.Param("service")
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Log %s does not exist", s)
c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
return
}
c.JSON(http.StatusOK, nil)
}
// removeServiceLog has a param :service returns mock JSON for a http DELETE.
//
// Pass "0" to :step to test receiving a http 404 response.
func removeServiceLog(c *gin.Context) {
s := c.Param("service")
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Log %s does not exist", s)
c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
return
}
c.JSON(http.StatusOK, fmt.Sprintf("Log %s removed", s))
}
// getStepLog has a param :step returns mock JSON for a http GET.
//
// Pass "0" to :step to test receiving a http 404 response.
func getStepLog(c *gin.Context) {
s := c.Param("step")
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Log %s does not exist", s)
c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
return
}
data := []byte(LogResp)
var body library.Log
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
}
// addStepLog returns mock JSON for a http GET.
func addStepLog(c *gin.Context) {
c.JSON(http.StatusCreated, nil)
}
// updateStepLog has a param :step returns mock JSON for a http PUT.
//
// Pass "0" to :step to test receiving a http 404 response.
func updateStepLog(c *gin.Context) {
s := c.Param("step")
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Log %s does not exist", s)
c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
return
}
c.JSON(http.StatusOK, nil)
}
// removeStepLog has a param :step returns mock JSON for a http DELETE.
//
// Pass "0" to :step to test receiving a http 404 response.
func removeStepLog(c *gin.Context) {
s := c.Param("step")
if strings.EqualFold(s, "0") {
msg := fmt.Sprintf("Log %s does not exist", s)
c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
return
}
c.JSON(http.StatusOK, fmt.Sprintf("Log %s removed", s))
}