Skip to content

Commit

Permalink
fix(lint): Fixed golang linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dvjsharma committed Jan 11, 2024
1 parent ee4be56 commit b08411a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
6 changes: 4 additions & 2 deletions cmd/laas/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ func main() {
log.Fatalf("Failed to automigrate database: %v", err)
}

if *populatedb == true {
if *populatedb {
db.Populatedb(*datafile)
}

r := api.Router()

r.Run()
if err := r.Run(); err != nil {
log.Fatalf("Error while running the server: %v", err)
}
}
44 changes: 32 additions & 12 deletions pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ func TestGetLicense(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)

var res models.LicenseResponse
json.Unmarshal(w.Body.Bytes(), &res)
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
t.Errorf("Error unmarshalling JSON: %v", err)
return
}

assert.Equal(t, expectLicense, res.Data[0])

Expand All @@ -83,12 +86,12 @@ func TestCreateLicense(t *testing.T) {
}
w := makeRequest("POST", "/api/licenses", License, true)
assert.Equal(t, http.StatusCreated, w.Code)
type response struct {
Data models.LicenseDB `json:"data"`
}

var res models.LicenseResponse
json.Unmarshal(w.Body.Bytes(), &res)
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
t.Errorf("Error unmarshalling JSON: %v", err)
return
}

assert.Equal(t, License, res.Data[0])

Expand All @@ -114,7 +117,10 @@ func TestUpdateLicense(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)

var res models.LicenseResponse
json.Unmarshal(w.Body.Bytes(), &res)
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
t.Errorf("Error unmarshalling JSON: %v", err)
return
}

assert.Equal(t, expectedLicense, res.Data[0])

Expand Down Expand Up @@ -142,7 +148,10 @@ func TestSearchInLicense(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)

var res models.LicenseResponse
json.Unmarshal(w.Body.Bytes(), &res)
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
t.Errorf("Error unmarshalling JSON: %v", err)
return
}

assert.Equal(t, expectLicense, res.Data[0])

Expand Down Expand Up @@ -186,38 +195,49 @@ func TestSearchInLicense2(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)

var res models.LicenseResponse
json.Unmarshal(w.Body.Bytes(), &res)
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
t.Errorf("Error unmarshalling JSON: %v", err)
return
}

assert.Equal(t, expectLicense, res.Data)
}

func TestGetUser(t *testing.T) {
password := "fossy"
expectUser := models.User{
Username: "fossy",
Userpassword: "fossy",
Userpassword: &password,
Userlevel: "admin",
}
w := makeRequest("GET", "/api/user/1", nil, false)
assert.Equal(t, http.StatusOK, w.Code)

var res models.UserResponse
json.Unmarshal(w.Body.Bytes(), &res)
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
t.Errorf("Error unmarshalling JSON: %v", err)
return
}

assert.Equal(t, expectUser, res.Data[0])

}

func TestCreateUser(t *testing.T) {
password := "abc123"
user := models.User{
Username: "general_user",
Userpassword: "abc123",
Userpassword: &password,
Userlevel: "participant",
}
w := makeRequest("POST", "/api/user", user, true)
assert.Equal(t, http.StatusOK, w.Code)

var res models.UserResponse
json.Unmarshal(w.Body.Bytes(), &res)
if err := json.Unmarshal(w.Body.Bytes(), &res); err != nil {
t.Errorf("Error unmarshalling JSON: %v", err)
return
}

assert.Equal(t, user, res.Data[0])
}
2 changes: 1 addition & 1 deletion pkg/api/licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func UpdateLicense(c *gin.Context) {
c.JSON(http.StatusBadRequest, er)
return
}
if update.Text != "" && oldlicense.TextUpdatable == false && oldlicense.Text != update.Text {
if update.Text != "" && !oldlicense.TextUpdatable && oldlicense.Text != update.Text {
er := models.LicenseError{
Status: http.StatusBadRequest,
Message: "Text is not updatable",
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/obligations.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func UpdateObligation(c *gin.Context) {
c.JSON(http.StatusBadRequest, er)
return
}
if oldobligation.TextUpdatable == false && update.Text != "" && update.Text != oldobligation.Text {
if !oldobligation.TextUpdatable && update.Text != "" && update.Text != oldobligation.Text {
er := models.LicenseError{
Status: http.StatusBadRequest,
Message: "Can not update obligation text",
Expand Down

0 comments on commit b08411a

Please sign in to comment.