Skip to content

Commit

Permalink
fix some typos and static check notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Kibish committed May 2, 2021
1 parent 474d3cb commit be164ff
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 42 deletions.
10 changes: 5 additions & 5 deletions do/do.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ var name = "digitalocean"

var url = "https://api.digitalocean.com/v2"

// ErrorRequset is returned when some request failed
var ErrorRequset = errors.New("Request Failed")
// ErrorRequest is returned when some request failed
var ErrorRequest = errors.New("request Failed")

// Record describe record structure
type Record struct {
Expand Down Expand Up @@ -72,7 +72,7 @@ func (d *DigitalOcean) GetDomainRecords() ([]Record, error) {
defer res.Body.Close()

if !misc.Success(res.StatusCode) {
return nil, fmt.Errorf("%s: %s", name, ErrorRequset.Error())
return nil, fmt.Errorf("%s: %s", name, ErrorRequest.Error())
}

var records domainRecords
Expand Down Expand Up @@ -104,7 +104,7 @@ func (d *DigitalOcean) CreateRecord(record Record) (*Record, error) {
defer res.Body.Close()

if !misc.Success(res.StatusCode) {
return nil, fmt.Errorf("%s: %s", name, ErrorRequset.Error())
return nil, fmt.Errorf("%s: %s", name, ErrorRequest.Error())
}

var resRecord domainRecord
Expand Down Expand Up @@ -136,7 +136,7 @@ func (d *DigitalOcean) UpdateRecord(record Record) (*Record, error) {
defer res.Body.Close()

if !misc.Success(res.StatusCode) {
return nil, fmt.Errorf("%s: %s", name, ErrorRequset.Error())
return nil, fmt.Errorf("%s: %s", name, ErrorRequest.Error())
}

var resRecord domainRecord
Expand Down
6 changes: 3 additions & 3 deletions do/do_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func TestGetDomainRecordsSuccess(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {

if "Bearer amazingtoken" != r.Header.Get("Authorization") {
if r.Header.Get("Authorization") != "Bearer amazingtoken" {
t.Error("Not correct Authorization value")
return
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestGetDomainRecordsParseError(t *testing.T) {
func TestCreateRecordSuccess(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {

if "Bearer amazingtoken" != r.Header.Get("Authorization") {
if r.Header.Get("Authorization") != "Bearer amazingtoken" {
t.Error("Not correct Authorization value")
return
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestCreateRecordParseError(t *testing.T) {
func TestUpdateRecordSuccess(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {

if "Bearer amazingtoken" != r.Header.Get("Authorization") {
if r.Header.Get("Authorization") != "Bearer amazingtoken" {
t.Error("Not correct Authorization value")
return
}
Expand Down
5 changes: 0 additions & 5 deletions ipprovider/ipify/ipify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ipify
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)

Expand Down Expand Up @@ -124,7 +123,3 @@ func TestIpifyFailedOnGet(t *testing.T) {
return
}
}

func isMatchingErrorMessage(message string, prefix, suffix string) bool {
return strings.HasPrefix(message, prefix) && strings.HasSuffix(message, suffix)
}
15 changes: 6 additions & 9 deletions updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func New(hc *http.Client, ipprovider *ipprovider.IPProvider, cfg *conf.Configura
var ok bool
u.storage, ok = copyForStorage.(*conf.Configuration)
if !ok {
return nil, errors.New("Failed to convert interface{} to conf.Configuration")
return nil, errors.New("failed to convert interface{} to conf.Configuration")
}
u.config = cfg

Expand Down Expand Up @@ -73,16 +73,13 @@ func (u *Updater) Start() (err error) {

periodC := time.NewTicker(u.updateTick).C

// start main proceess
// start main process
go func() {
// for defined period of time, perform IP check
for {
select {
case <-periodC:
errCheck := u.checkAndUpdate()
if errCheck != nil {
log.Errorf("failed to update: %s", errCheck.Error())
}
for range periodC {
errCheck := u.checkAndUpdate()
if errCheck != nil {
log.Errorf("failed to update: %s", errCheck.Error())
}
}

Expand Down
33 changes: 13 additions & 20 deletions updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ func TestSyncRecordsCreateNew(t *testing.T) {
ID: 123,
Type: "A",
Name: "test",
Data: "127.0.0.1",
Data: record.Data,
}, nil
}

return &do.Record{
ID: 124,
Type: "TXT",
Name: "neo",
Data: "127.0.0.1 and text",
Data: record.Data,
}, nil
}

Expand All @@ -65,7 +65,7 @@ func TestSyncRecordsCreateNew(t *testing.T) {
ID: 124,
Type: "TXT",
Name: "neo",
Data: "127.0.0.1 and text",
Data: record.Data,
}, nil
}

Expand All @@ -90,8 +90,7 @@ func TestSyncRecordsCreateNew(t *testing.T) {

u.ip = "127.0.0.1"

var errSync error
errSync = u.syncRecords(allRecords)
errSync := u.syncRecords(allRecords)
if errSync != nil {
t.Error(errSync)
return
Expand Down Expand Up @@ -131,8 +130,7 @@ func TestSyncRecordsCreateError(t *testing.T) {

u.ip = "127.0.0.1"

var errSync error
errSync = u.syncRecords(allRecords)
errSync := u.syncRecords(allRecords)
if errSync == nil {
t.Error("Should be error, but everything is OK.")
return
Expand All @@ -146,7 +144,7 @@ func TestSyncRecordsUpdateRecord(t *testing.T) {
ID: 123,
Type: "A",
Name: "test",
Data: "127.0.0.1",
Data: record.Data,
}, nil
}

Expand All @@ -168,8 +166,7 @@ func TestSyncRecordsUpdateRecord(t *testing.T) {

u.ip = "127.0.0.1"

var errSync error
errSync = u.syncRecords(allRecords)
errSync := u.syncRecords(allRecords)
if errSync != nil {
t.Error(errSync)
return
Expand Down Expand Up @@ -210,8 +207,7 @@ func TestSyncRecordsUpdateError(t *testing.T) {

u.ip = "127.0.0.1"

var errSync error
errSync = u.syncRecords(allRecords)
errSync := u.syncRecords(allRecords)
if errSync == nil {
t.Error("Should be error, but everything is OK.")
return
Expand All @@ -233,7 +229,7 @@ func TestCheckAndUpdateOnlyCheck(t *testing.T) {
ID: 124,
Type: "TXT",
Name: "neo",
Data: "127.0.0.1 and text",
Data: record.Data,
}, nil
}

Expand All @@ -252,8 +248,7 @@ func TestCheckAndUpdateOnlyCheck(t *testing.T) {

u.ip = "127.0.0.1"

var errCheck error
errCheck = u.checkAndUpdate()
errCheck := u.checkAndUpdate()
if errCheck != nil {
t.Error(errCheck)
return
Expand All @@ -272,7 +267,7 @@ func TestCheckAndUpdateOnlyUpdate(t *testing.T) {
ID: 123,
Type: "A",
Name: "test",
Data: "127.0.0.1",
Data: record.Data,
}, nil
}

Expand Down Expand Up @@ -302,8 +297,7 @@ func TestCheckAndUpdateOnlyUpdate(t *testing.T) {
ip: "127.0.0.1",
}

var errUpdate error
errUpdate = u.checkAndUpdate()
errUpdate := u.checkAndUpdate()
if errUpdate != nil {
t.Error(errUpdate)
return
Expand Down Expand Up @@ -343,8 +337,7 @@ func TestCheckAndUpdateError(t *testing.T) {
ip: "127.0.0.1",
}

var errUpdate error
errUpdate = u.checkAndUpdate()
errUpdate := u.checkAndUpdate()
if errUpdate == nil {
t.Error("Should be error, but everything is OK")
return
Expand Down

0 comments on commit be164ff

Please sign in to comment.