Skip to content

Commit

Permalink
chore: code style, update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
davidramiro committed Feb 11, 2024
1 parent d407a4a commit 51e7c51
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 42 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/objx v0.5.1 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand All @@ -39,7 +39,7 @@ require (
)

require (
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
github.com/labstack/echo/v4 v4.11.4
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down
12 changes: 7 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -56,11 +56,13 @@ github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0=
github.com/stretchr/objx v0.5.1/go.mod h1:/iHQpkQwBD6DLUmQ4pE+s1TXdob1mORJ4/UFdrifcy0=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
Expand All @@ -73,8 +75,8 @@ go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
Expand Down
24 changes: 12 additions & 12 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"encoding/json"
"errors"
"fmt"
mock_services "github.com/davidramiro/frigabun/mocks/github.com/davidramiro/frigabun/services"
mock_factory "github.com/davidramiro/frigabun/mocks/github.com/davidramiro/frigabun/services/factory"
mockservices "github.com/davidramiro/frigabun/mocks/github.com/davidramiro/frigabun/services"
mockfactory "github.com/davidramiro/frigabun/mocks/github.com/davidramiro/frigabun/services/factory"
"github.com/davidramiro/frigabun/services"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
Expand All @@ -28,7 +28,7 @@ func TestStatusEndpointOk(t *testing.T) {
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)

sf := mock_factory.NewMockServiceFactory(t)
sf := mockfactory.NewMockServiceFactory(t)
sf.On("ListServices").Return([]services.Registrar{"cloudflare", "gandi"}).Once()

updateApi = NewUpdateApi(sf)
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestUpdateEndpointMissingSubdomain(t *testing.T) {
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)

sf := mock_factory.NewMockServiceFactory(t)
sf := mockfactory.NewMockServiceFactory(t)
updateApi = NewUpdateApi(sf)

if assert.NoError(t, updateApi.HandleUpdateRequest(c)) {
Expand All @@ -80,7 +80,7 @@ func TestUpdateEndpointInvalidIP(t *testing.T) {
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)

sf := mock_factory.NewMockServiceFactory(t)
sf := mockfactory.NewMockServiceFactory(t)
updateApi = NewUpdateApi(sf)

if assert.NoError(t, updateApi.HandleUpdateRequest(c)) {
Expand All @@ -102,7 +102,7 @@ func TestUpdateEndpointInvalidRegistrar(t *testing.T) {
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)

sf := mock_factory.NewMockServiceFactory(t)
sf := mockfactory.NewMockServiceFactory(t)
sf.On("Find", services.Registrar("porkbun")).Return(nil, errors.New("cannot find registrar porkbun"))

updateApi = NewUpdateApi(sf)
Expand All @@ -126,10 +126,10 @@ func TestUpdateEndpointFailureInService(t *testing.T) {
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)

cs := mock_services.NewMockDnsUpdateService(t)
cs := mockservices.NewMockDnsUpdateService(t)
cs.On("UpdateRecord", mock.Anything).Return(errors.New("failed to update")).Once()

sf := mock_factory.NewMockServiceFactory(t)
sf := mockfactory.NewMockServiceFactory(t)
sf.On("Find", services.Registrar("cloudflare")).Return(cs, nil).Once()

updateApi = NewUpdateApi(sf)
Expand All @@ -153,10 +153,10 @@ func TestUpdateEndpointSuccessSingleSubdomain(t *testing.T) {
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)

cs := mock_services.NewMockDnsUpdateService(t)
cs := mockservices.NewMockDnsUpdateService(t)
cs.On("UpdateRecord", mock.Anything).Return(nil).Once()

sf := mock_factory.NewMockServiceFactory(t)
sf := mockfactory.NewMockServiceFactory(t)
sf.On("Find", services.Registrar("cloudflare")).Return(cs, nil).Once()

updateApi = NewUpdateApi(sf)
Expand All @@ -180,10 +180,10 @@ func TestUpdateEndpointSuccessThreeSubdomains(t *testing.T) {
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)

cs := mock_services.NewMockDnsUpdateService(t)
cs := mockservices.NewMockDnsUpdateService(t)
cs.On("UpdateRecord", mock.Anything).Return(nil).Times(3)

sf := mock_factory.NewMockServiceFactory(t)
sf := mockfactory.NewMockServiceFactory(t)
sf.On("Find", services.Registrar("cloudflare")).Return(cs, nil).Once().Times(3)

updateApi = NewUpdateApi(sf)
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func main() {
}))
e.Use(middleware.Recover())

factory, err := factory.NewDnsUpdateServiceFactory()
serviceFactory, err := factory.NewDnsUpdateServiceFactory()
if err != nil {
log.Fatal().Err(err).Msg("cannot init service factory")
log.Fatal().Err(err).Msg("cannot init service serviceFactory")
}

updateApi := api.NewUpdateApi(factory)
updateApi := api.NewUpdateApi(serviceFactory)
g := e.Group("/api")
g.GET("/update", updateApi.HandleUpdateRequest)
g.GET("/status", updateApi.HandleStatusCheck)
Expand Down
18 changes: 9 additions & 9 deletions services/cloudflare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
mock_services "github.com/davidramiro/frigabun/mocks/github.com/davidramiro/frigabun/services"
mockservices "github.com/davidramiro/frigabun/mocks/github.com/davidramiro/frigabun/services"
"github.com/davidramiro/frigabun/services"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -46,7 +46,7 @@ func TestCloudflareDnsUpdateService_Registrar(t *testing.T) {

func TestCloudflareDnsUpdateService_UpdateRecord_RequestError(t *testing.T) {
setupCloudflareConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)
h.On("Do", mock.AnythingOfType("*http.Request")).Return(nil, errors.New("cf api request error")).Once()

registrar, err := services.NewCloudflareDnsUpdateService(h)
Expand All @@ -67,7 +67,7 @@ func TestCloudflareDnsUpdateService_UpdateRecord_RequestError(t *testing.T) {

func TestCloudflareDnsUpdateService_UpdateRecord_QueryError(t *testing.T) {
setupCloudflareConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

resp := &services.CloudflareQueryResponse{
Errors: []struct {
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestCloudflareDnsUpdateService_UpdateRecord_QueryError(t *testing.T) {

func TestCloudflareDnsUpdateService_UpdateRecord_ExistingRecord(t *testing.T) {
setupCloudflareConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

resp := &services.CloudflareQueryResponse{
Errors: []struct {
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestCloudflareDnsUpdateService_UpdateRecord_ExistingRecord(t *testing.T) {

func TestCloudflareDnsUpdateService_UpdateRecord_NewRecord(t *testing.T) {
setupCloudflareConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

resp := &services.CloudflareQueryResponse{
Errors: []struct {
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestCloudflareDnsUpdateService_UpdateRecord_NewRecord(t *testing.T) {

func TestCloudflareDnsUpdateService_UpdateRecord_NewRecord_ApiError(t *testing.T) {
setupCloudflareConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

resp := &services.CloudflareQueryResponse{
Errors: []struct {
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestCloudflareDnsUpdateService_UpdateRecord_NewRecord_ApiError(t *testing.T

func TestCloudflareDnsUpdateService_UpdateRecord_ExistingRecord_ApiError(t *testing.T) {
setupCloudflareConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

resp := &services.CloudflareQueryResponse{
Errors: []struct {
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestCloudflareDnsUpdateService_UpdateRecord_ExistingRecord_ApiError(t *test

func TestCloudflareDnsUpdateService_UpdateRecord_ExistingRecord_RequestError(t *testing.T) {
setupCloudflareConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

resp := &services.CloudflareQueryResponse{
Errors: []struct {
Expand Down Expand Up @@ -326,7 +326,7 @@ func TestCloudflareDnsUpdateService_UpdateRecord_ExistingRecord_RequestError(t *

func TestCloudflareDnsUpdateService_UpdateRecord_NewRecord_RequestError(t *testing.T) {
setupCloudflareConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

resp := &services.CloudflareQueryResponse{
Errors: []struct {
Expand Down
8 changes: 4 additions & 4 deletions services/gandi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
mock_services "github.com/davidramiro/frigabun/mocks/github.com/davidramiro/frigabun/services"
mockservices "github.com/davidramiro/frigabun/mocks/github.com/davidramiro/frigabun/services"
"github.com/davidramiro/frigabun/services"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestGandiDnsUpdateService_Registrar(t *testing.T) {

func TestGandiDnsUpdateService_UpdateRecord_RequestError(t *testing.T) {
setupGandiConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)
h.On("Do", mock.AnythingOfType("*http.Request")).Return(nil, errors.New("gd api request error")).Once()

registrar, err := services.NewGandiDnsUpdateService(h)
Expand All @@ -65,7 +65,7 @@ func TestGandiDnsUpdateService_UpdateRecord_RequestError(t *testing.T) {

func TestGandiDnsUpdateService_UpdateRecord_ApiError(t *testing.T) {
setupGandiConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

resp := &services.CloudflareQueryResponse{
Errors: []struct {
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestGandiDnsUpdateService_UpdateRecord_ApiError(t *testing.T) {

func TestGandiDnsUpdateService_UpdateRecord_Success(t *testing.T) {
setupGandiConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

resp := &services.CloudflareQueryResponse{
Errors: []struct {
Expand Down
12 changes: 6 additions & 6 deletions services/porkbun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
mock_services "github.com/davidramiro/frigabun/mocks/github.com/davidramiro/frigabun/services"
mockservices "github.com/davidramiro/frigabun/mocks/github.com/davidramiro/frigabun/services"
"github.com/davidramiro/frigabun/services"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -46,7 +46,7 @@ func TestPorkbunDnsUpdateService_Registrar(t *testing.T) {

func TestPorkbunDnsUpdateService_UpdateRecord_RequestError(t *testing.T) {
setupPorkbunConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)
h.On("Do", mock.AnythingOfType("*http.Request")).Return(nil, errors.New("pb api request error")).Once()

registrar, err := services.NewPorkbunDnsUpdateService(h)
Expand All @@ -67,7 +67,7 @@ func TestPorkbunDnsUpdateService_UpdateRecord_RequestError(t *testing.T) {

func TestPorkbunDnsUpdateService_UpdateRecord_ApiError(t *testing.T) {
setupPorkbunConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

resp := &services.PorkbunQueryResponse{
Status: "ERROR",
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestPorkbunDnsUpdateService_UpdateRecord_ApiError(t *testing.T) {

func TestPorkbunDnsUpdateService_UpdateRecord_Exists_Success(t *testing.T) {
setupPorkbunConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

queryResp := &services.PorkbunQueryResponse{
Status: "SUCCESS",
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestPorkbunDnsUpdateService_UpdateRecord_Exists_Success(t *testing.T) {

func TestPorkbunDnsUpdateService_UpdateRecord_Exists_Failure_On_Update(t *testing.T) {
setupPorkbunConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

queryResp := &services.PorkbunQueryResponse{
Status: "SUCCESS",
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestPorkbunDnsUpdateService_UpdateRecord_Exists_Failure_On_Update(t *testin

func TestPorkbunDnsUpdateService_UpdateRecord_NotExists_Failure_On_Create(t *testing.T) {
setupPorkbunConfig()
h := mock_services.NewMockHTTPClient(t)
h := mockservices.NewMockHTTPClient(t)

queryResp := &services.PorkbunQueryResponse{
Status: "SUCCESS",
Expand Down

0 comments on commit 51e7c51

Please # to comment.