Use linter formatting

This commit is contained in:
Fredrik Berntsson
2025-04-20 21:53:57 +02:00
committed by lovelaze
parent dcd44b726a
commit cf3ec1706c
34 changed files with 140 additions and 93 deletions
+2 -1
View File
@@ -1,9 +1,10 @@
package cmd
import (
"github.com/spf13/cobra"
"github.com/lovelaze/nebula-sync/internal/log"
"github.com/lovelaze/nebula-sync/version"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
+3 -2
View File
@@ -1,10 +1,11 @@
package cmd
import (
"github.com/lovelaze/nebula-sync/internal/config"
"github.com/lovelaze/nebula-sync/internal/service"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/lovelaze/nebula-sync/internal/config"
"github.com/lovelaze/nebula-sync/internal/service"
)
var envFile string
+2 -1
View File
@@ -3,10 +3,11 @@ package e2e
import (
"context"
"fmt"
"time"
"github.com/docker/go-connections/nat"
tc "github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"time"
)
const startupTimeout = 30 * time.Second
+4 -2
View File
@@ -1,9 +1,11 @@
package e2e
import (
"github.com/lovelaze/nebula-sync/internal/service"
"github.com/stretchr/testify/suite"
"testing"
"github.com/stretchr/testify/suite"
"github.com/lovelaze/nebula-sync/internal/service"
)
type testSuite struct {
+4 -3
View File
@@ -3,15 +3,16 @@ package config
import (
"crypto/tls"
"fmt"
"github.com/kelseyhightower/envconfig"
"net/http"
"time"
"github.com/kelseyhightower/envconfig"
)
type Client struct {
SkipTLSVerification bool `default:"false" envconfig:"CLIENT_SKIP_TLS_VERIFICATION"`
RetryDelay int64 `default:"1" envconfig:"CLIENT_RETRY_DELAY_SECONDS"`
Timeout int64 `default:"20" envconfig:"CLIENT_TIMEOUT_SECONDS"`
RetryDelay int64 `default:"1" envconfig:"CLIENT_RETRY_DELAY_SECONDS"`
Timeout int64 `default:"20" envconfig:"CLIENT_TIMEOUT_SECONDS"`
}
func (c *Config) loadClient() error {
+2 -1
View File
@@ -1,9 +1,10 @@
package config
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)
func TestConfig_LoadClient(t *testing.T) {
+23 -22
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/kelseyhightower/envconfig"
"github.com/lovelaze/nebula-sync/internal/pihole/model"
"github.com/lovelaze/nebula-sync/internal/sync/filter"
)
@@ -11,17 +12,17 @@ import (
type Config struct {
Primary model.PiHole `required:"true" envconfig:"PRIMARY"`
Replicas []model.PiHole `required:"true" envconfig:"REPLICAS"`
Client *Client `ignored:"true"`
Sync *Sync `ignored:"true"`
Client *Client ` ignored:"true"`
Sync *Sync ` ignored:"true"`
}
type Sync struct {
FullSync bool `required:"true" envconfig:"FULL_SYNC"`
Cron *string `envconfig:"CRON"`
RunGravity bool `default:"false" envconfig:"RUN_GRAVITY"`
Cron *string ` envconfig:"CRON"`
RunGravity bool ` envconfig:"RUN_GRAVITY" default:"false"`
GravitySettings *GravitySettings
ConfigSettings *ConfigSettings `ignored:"true"`
WebhookSettings *WebhookSettings `ignored:"true"`
ConfigSettings *ConfigSettings ` ignored:"true"`
WebhookSettings *WebhookSettings ` ignored:"true"`
}
type GravitySettings struct {
@@ -49,28 +50,28 @@ type ConfigSettings struct {
type RawConfigSettings struct {
DNS bool `default:"false" envconfig:"SYNC_CONFIG_DNS"`
DNSInclude []string `envconfig:"SYNC_CONFIG_DNS_INCLUDE"`
DNSExclude []string `envconfig:"SYNC_CONFIG_DNS_EXCLUDE"`
DNSInclude []string ` envconfig:"SYNC_CONFIG_DNS_INCLUDE"`
DNSExclude []string ` envconfig:"SYNC_CONFIG_DNS_EXCLUDE"`
DHCP bool `default:"false" envconfig:"SYNC_CONFIG_DHCP"`
DHCPInclude []string `envconfig:"SYNC_CONFIG_DHCP_INCLUDE"`
DHCPExclude []string `envconfig:"SYNC_CONFIG_DHCP_EXCLUDE"`
DHCPInclude []string ` envconfig:"SYNC_CONFIG_DHCP_INCLUDE"`
DHCPExclude []string ` envconfig:"SYNC_CONFIG_DHCP_EXCLUDE"`
NTP bool `default:"false" envconfig:"SYNC_CONFIG_NTP"`
NTPInclude []string `envconfig:"SYNC_CONFIG_NTP_INCLUDE"`
NTPExclude []string `envconfig:"SYNC_CONFIG_NTP_EXCLUDE"`
NTPInclude []string ` envconfig:"SYNC_CONFIG_NTP_INCLUDE"`
NTPExclude []string ` envconfig:"SYNC_CONFIG_NTP_EXCLUDE"`
Resolver bool `default:"false" envconfig:"SYNC_CONFIG_RESOLVER"`
ResolverInclude []string `envconfig:"SYNC_CONFIG_RESOLVER_INCLUDE"`
ResolverExclude []string `envconfig:"SYNC_CONFIG_RESOLVER_EXCLUDE"`
ResolverInclude []string ` envconfig:"SYNC_CONFIG_RESOLVER_INCLUDE"`
ResolverExclude []string ` envconfig:"SYNC_CONFIG_RESOLVER_EXCLUDE"`
Database bool `default:"false" envconfig:"SYNC_CONFIG_DATABASE"`
DatabaseInclude []string `envconfig:"SYNC_CONFIG_DATABASE_INCLUDE"`
DatabaseExclude []string `envconfig:"SYNC_CONFIG_DATABASE_EXCLUDE"`
Webserver bool `default:"false" ignored:"true"` // ignore for now
Files bool `default:"false" ignored:"true"` // ignore for now
DatabaseInclude []string ` envconfig:"SYNC_CONFIG_DATABASE_INCLUDE"`
DatabaseExclude []string ` envconfig:"SYNC_CONFIG_DATABASE_EXCLUDE"`
Webserver bool `default:"false" ignored:"true"` // ignore for now
Files bool `default:"false" ignored:"true"` // ignore for now
Misc bool `default:"false" envconfig:"SYNC_CONFIG_MISC"`
MiscInclude []string `envconfig:"SYNC_CONFIG_MISC_INCLUDE"`
MiscExclude []string `envconfig:"SYNC_CONFIG_MISC_EXCLUDE"`
MiscInclude []string ` envconfig:"SYNC_CONFIG_MISC_INCLUDE"`
MiscExclude []string ` envconfig:"SYNC_CONFIG_MISC_EXCLUDE"`
Debug bool `default:"false" envconfig:"SYNC_CONFIG_DEBUG"`
DebugInclude []string `envconfig:"SYNC_CONFIG_DEBUG_INCLUDE"`
DebugExclude []string `envconfig:"SYNC_CONFIG_DEBUG_EXCLUDE"`
DebugInclude []string ` envconfig:"SYNC_CONFIG_DEBUG_INCLUDE"`
DebugExclude []string ` envconfig:"SYNC_CONFIG_DEBUG_EXCLUDE"`
}
func (raw *RawConfigSettings) Validate() error {
+2 -1
View File
@@ -3,9 +3,10 @@ package config
import (
"testing"
"github.com/lovelaze/nebula-sync/internal/sync/filter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/lovelaze/nebula-sync/internal/sync/filter"
)
func TestConfig_Load(t *testing.T) {
+3 -2
View File
@@ -1,10 +1,11 @@
package config
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestConfig_LoadEnvFile(t *testing.T) {
+3 -2
View File
@@ -2,9 +2,10 @@ package config
import (
"fmt"
"github.com/lovelaze/nebula-sync/internal/pihole/model"
"os"
"strings"
"github.com/lovelaze/nebula-sync/internal/pihole/model"
)
func (c *Config) loadTargets() error {
@@ -70,7 +71,7 @@ func parseMultiple(values []string) ([]model.PiHole, error) {
if err != nil {
return nil, err
}
replicas = append(replicas, *ph)
}
return replicas, nil
+3 -2
View File
@@ -1,10 +1,11 @@
package config
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestConfig_Load_Target(t *testing.T) {
+1 -1
View File
@@ -19,7 +19,7 @@ type WebhookClient struct {
type WebhookRequest struct {
Body string `envconfig:"BODY"`
Headers map[string]string `envconfig:"HEADERS"`
Method string `default:"POST" envconfig:"METHOD"`
Method string `envconfig:"METHOD" default:"POST"`
URL string `envconfig:"URL"`
}
+4 -1
View File
@@ -11,7 +11,10 @@ func TestWebhookSettings_Load_Success(t *testing.T) {
t.Setenv("WEBHOOK_SYNC_SUCCESS_URL", "http://success.example.com")
t.Setenv("WEBHOOK_SYNC_SUCCESS_METHOD", "POST")
t.Setenv("WEBHOOK_SYNC_SUCCESS_BODY", "{\"status\":\"ok\"}")
t.Setenv("WEBHOOK_SYNC_SUCCESS_HEADERS", "Content-Type:application/json,Authorization:Bearer token,X-Custom-Header: CustomValue")
t.Setenv(
"WEBHOOK_SYNC_SUCCESS_HEADERS",
"Content-Type:application/json,Authorization:Bearer token,X-Custom-Header: CustomValue",
)
conf := Config{
Sync: &Sync{},
+3 -2
View File
@@ -1,12 +1,13 @@
package log
import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"io"
"os"
"strconv"
"time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
type LevelWriter struct {
+2 -1
View File
@@ -1,9 +1,10 @@
package log
import (
"testing"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"testing"
)
func TestInit_info(t *testing.T) {
+19 -10
View File
@@ -6,18 +6,18 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/lovelaze/nebula-sync/internal/pihole/model"
"github.com/lovelaze/nebula-sync/version"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"io"
"mime/multipart"
"net/http"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/lovelaze/nebula-sync/internal/pihole/model"
"github.com/lovelaze/nebula-sync/version"
)
var (
userAgent = fmt.Sprintf("nebula-sync/%s", version.Version)
)
var userAgent = fmt.Sprintf("nebula-sync/%s", version.Version)
type Client interface {
PostAuth() error
@@ -71,8 +71,12 @@ func (client *client) PostAuth() error {
return client.wrapError(err, nil)
}
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, client.APIPath("/auth"), bytes.NewReader(reqBytes))
req, err := http.NewRequestWithContext(
context.Background(),
http.MethodPost,
client.APIPath("/auth"),
bytes.NewReader(reqBytes),
)
if err != nil {
return client.wrapError(err, req)
}
@@ -264,7 +268,12 @@ func (client *client) PatchConfig(patchRequest *model.PatchConfigRequest) error
return client.wrapError(err, nil)
}
req, err := http.NewRequestWithContext(context.Background(), http.MethodPatch, client.APIPath("config"), bytes.NewReader(reqBytes))
req, err := http.NewRequestWithContext(
context.Background(),
http.MethodPatch,
client.APIPath("config"),
bytes.NewReader(reqBytes),
)
if err != nil {
return client.wrapError(err, req)
}
+8 -5
View File
@@ -3,14 +3,16 @@ package pihole
import (
"context"
"fmt"
"github.com/lovelaze/nebula-sync/e2e"
"github.com/lovelaze/nebula-sync/internal/pihole/model"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
tc "github.com/testcontainers/testcontainers-go"
"net/http"
"testing"
"github.com/lovelaze/nebula-sync/e2e"
"github.com/lovelaze/nebula-sync/internal/pihole/model"
)
const (
@@ -93,7 +95,8 @@ func (suite *clientTestSuite) TestClient_PatchConfig() {
Database: nil,
Misc: nil,
Debug: nil,
}}
},
}
err := suite.client.PatchConfig(&request)
suite.Require().NoError(err)
+2 -2
View File
@@ -3,9 +3,10 @@ package model
import (
"errors"
"fmt"
"github.com/rs/zerolog/log"
"net/url"
"strings"
"github.com/rs/zerolog/log"
)
type PiHole struct {
@@ -37,7 +38,6 @@ func (ph *PiHole) Decode(value string) error {
}
parsedURL, err := url.Parse(uri)
if err != nil {
return fmt.Errorf("parse url: %w", err)
}
+3 -2
View File
@@ -2,10 +2,11 @@ package model
import (
"fmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPiHole_Decode(t *testing.T) {
+1
View File
@@ -2,6 +2,7 @@ package model
import (
"fmt"
"github.com/rs/zerolog/log"
)
+5 -4
View File
@@ -2,15 +2,16 @@ package service
import (
"fmt"
"github.com/lovelaze/nebula-sync/internal/sync/retry"
"github.com/lovelaze/nebula-sync/internal/webhook"
"github.com/robfig/cron/v3"
"github.com/rs/zerolog/log"
"github.com/lovelaze/nebula-sync/internal/config"
"github.com/lovelaze/nebula-sync/internal/pihole"
"github.com/lovelaze/nebula-sync/internal/sync"
"github.com/lovelaze/nebula-sync/internal/sync/retry"
"github.com/lovelaze/nebula-sync/internal/webhook"
"github.com/lovelaze/nebula-sync/version"
"github.com/robfig/cron/v3"
"github.com/rs/zerolog/log"
)
type Service struct {
+2 -1
View File
@@ -4,10 +4,11 @@ import (
"errors"
"testing"
"github.com/stretchr/testify/require"
"github.com/lovelaze/nebula-sync/internal/config"
syncmock "github.com/lovelaze/nebula-sync/internal/mocks/sync"
"github.com/lovelaze/nebula-sync/internal/pihole/model"
"github.com/stretchr/testify/require"
)
func TestRun_full(t *testing.T) {
+2 -1
View File
@@ -2,8 +2,9 @@ package filter
import (
"fmt"
"github.com/rs/zerolog/log"
"strings"
"github.com/rs/zerolog/log"
)
type Type int
+3 -2
View File
@@ -2,12 +2,13 @@ package filter
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"maps"
"os"
"slices"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFilter_ByType_Include(t *testing.T) {
+4 -3
View File
@@ -3,12 +3,13 @@ package sync
import (
"testing"
"github.com/lovelaze/nebula-sync/internal/config"
piholemock "github.com/lovelaze/nebula-sync/internal/mocks/pihole"
"github.com/lovelaze/nebula-sync/internal/pihole"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/lovelaze/nebula-sync/internal/config"
piholemock "github.com/lovelaze/nebula-sync/internal/mocks/pihole"
"github.com/lovelaze/nebula-sync/internal/pihole"
)
func TestTarget_FullSync(t *testing.T) {
+3 -4
View File
@@ -2,11 +2,12 @@ package retry
import (
"fmt"
"github.com/lovelaze/nebula-sync/internal/config"
"time"
"github.com/avast/retry-go"
"github.com/rs/zerolog/log"
"github.com/lovelaze/nebula-sync/internal/config"
)
const (
@@ -17,9 +18,7 @@ const (
AttemptsDeleteSession = 3
)
var (
delay time.Duration
)
var delay time.Duration
func Init(clientConfig *config.Client) {
delay = time.Duration(clientConfig.RetryDelay) * time.Second
+3 -2
View File
@@ -2,12 +2,13 @@ package retry
import (
"errors"
"github.com/lovelaze/nebula-sync/internal/config"
"github.com/stretchr/testify/require"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/lovelaze/nebula-sync/internal/config"
)
// Test that the retries are actually causing the expected
+3 -2
View File
@@ -3,11 +3,12 @@ package sync
import (
"testing"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/lovelaze/nebula-sync/internal/config"
piholemock "github.com/lovelaze/nebula-sync/internal/mocks/pihole"
"github.com/lovelaze/nebula-sync/internal/pihole"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func TestTarget_SelectiveSync(t *testing.T) {
+3 -1
View File
@@ -2,12 +2,14 @@ package sync
import (
"fmt"
"github.com/rs/zerolog/log"
"github.com/lovelaze/nebula-sync/internal/config"
"github.com/lovelaze/nebula-sync/internal/pihole"
"github.com/lovelaze/nebula-sync/internal/pihole/model"
"github.com/lovelaze/nebula-sync/internal/sync/filter"
"github.com/lovelaze/nebula-sync/internal/sync/retry"
"github.com/rs/zerolog/log"
)
type Target interface {
+2 -1
View File
@@ -3,11 +3,12 @@ package sync
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/lovelaze/nebula-sync/internal/config"
piholemock "github.com/lovelaze/nebula-sync/internal/mocks/pihole"
"github.com/lovelaze/nebula-sync/internal/pihole"
"github.com/lovelaze/nebula-sync/internal/pihole/model"
"github.com/stretchr/testify/assert"
)
func Test_target_authenticate(t *testing.T) {
+10 -3
View File
@@ -8,9 +8,10 @@ import (
"strings"
"time"
"github.com/rs/zerolog/log"
"github.com/lovelaze/nebula-sync/internal/config"
"github.com/lovelaze/nebula-sync/version"
"github.com/rs/zerolog/log"
)
const (
@@ -32,7 +33,8 @@ func NewClient(c *config.WebhookSettings) *Client {
Timeout: timeout,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: c.Client.SkipTLSVerification},
}},
},
},
}
}
@@ -68,7 +70,12 @@ func invoke(client *http.Client, settings config.WebhookRequest) error {
Interface("headers", settings.Headers).
Msg("Invoking webhook")
req, err := http.NewRequestWithContext(context.Background(), settings.Method, settings.URL, strings.NewReader(settings.Body))
req, err := http.NewRequestWithContext(
context.Background(),
settings.Method,
settings.URL,
strings.NewReader(settings.Body),
)
if err != nil {
return fmt.Errorf("create webhook request: %w", err)
}
+3 -2
View File
@@ -6,10 +6,11 @@ import (
"net/http/httptest"
"testing"
"github.com/lovelaze/nebula-sync/internal/config"
"github.com/lovelaze/nebula-sync/version"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/lovelaze/nebula-sync/internal/config"
"github.com/lovelaze/nebula-sync/version"
)
func TestWebhook(t *testing.T) {
+2 -1
View File
@@ -1,8 +1,9 @@
package main
import (
"github.com/lovelaze/nebula-sync/cmd"
"os"
"github.com/lovelaze/nebula-sync/cmd"
)
func main() {
+1 -3
View File
@@ -1,5 +1,3 @@
package version
var (
Version = "dev"
)
var Version = "dev"