New lint rules

This commit is contained in:
Jamie Curnow
2024-11-21 19:07:36 +10:00
parent 4e6d65645f
commit 152b7666d8
85 changed files with 385 additions and 259 deletions

View File

@ -151,14 +151,14 @@ func ConfigureUpstream(u upstream.Model) error {
return u.Save(true)
}
func getHostFilename(h host.Model, append string) string {
func getHostFilename(h host.Model, appends string) string {
confDir := fmt.Sprintf("%s/nginx/hosts", config.Configuration.DataFolder)
return fmt.Sprintf("%s/host_%d.conf%s", confDir, h.ID, append)
return fmt.Sprintf("%s/host_%d.conf%s", confDir, h.ID, appends)
}
func getUpstreamFilename(u upstream.Model, append string) string {
func getUpstreamFilename(u upstream.Model, appends string) string {
confDir := fmt.Sprintf("%s/nginx/upstreams", config.Configuration.DataFolder)
return fmt.Sprintf("%s/upstream_%d.conf%s", confDir, u.ID, append)
return fmt.Sprintf("%s/upstream_%d.conf%s", confDir, u.ID, appends)
}
func removeHostFiles(h host.Model) {

View File

@ -1,10 +1,11 @@
package nginx
import (
"testing"
"npm/internal/entity/host"
"npm/internal/model"
"npm/internal/test"
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
@ -24,7 +25,7 @@ func TestGetHostFilename(t *testing.T) {
{
"test1",
host.Model{
ModelBase: model.ModelBase{
Base: model.Base{
ID: 10,
},
},
@ -34,7 +35,7 @@ func TestGetHostFilename(t *testing.T) {
{
"test2",
host.Model{
ModelBase: model.ModelBase{
Base: model.Base{
ID: 10,
},
},

View File

@ -54,7 +54,7 @@ server {
IsDisabled: false,
},
cert: certificate.Model{
ModelBase: model.ModelBase{
Base: model.Base{
ID: 77,
},
Status: certificate.StatusProvided,
@ -79,7 +79,7 @@ server {
IsDisabled: false,
},
cert: certificate.Model{
ModelBase: model.ModelBase{
Base: model.Base{
ID: 66,
},
Status: certificate.StatusProvided,
@ -108,18 +108,18 @@ server {
},
}
for _, test := range tests {
t.Run(test.name, func(st *testing.T) {
for _, tst := range tests {
t.Run(tst.name, func(st *testing.T) {
templateData := TemplateData{
ConfDir: "/etc/nginx/conf.d",
DataDir: "/data",
Host: test.host.GetTemplate(),
Certificate: test.cert.GetTemplate(),
Host: tst.host.GetTemplate(),
Certificate: tst.cert.GetTemplate(),
}
output, err := renderTemplate(template, templateData)
assert.Equal(t, test.want.err, err)
assert.Equal(t, test.want.output, output)
assert.Equal(st, tst.want.err, err)
assert.Equal(st, tst.want.output, output)
})
}
}