diff --git a/do/do.go b/do/do.go index 2939bf3..5549521 100644 --- a/do/do.go +++ b/do/do.go @@ -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 { @@ -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 @@ -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 @@ -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 diff --git a/do/do_test.go b/do/do_test.go index 8cd673d..68dc6f3 100644 --- a/do/do_test.go +++ b/do/do_test.go @@ -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 } @@ -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 } @@ -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 } diff --git a/ipprovider/ipify/ipify_test.go b/ipprovider/ipify/ipify_test.go index a511859..fea5c36 100644 --- a/ipprovider/ipify/ipify_test.go +++ b/ipprovider/ipify/ipify_test.go @@ -3,7 +3,6 @@ package ipify import ( "net/http" "net/http/httptest" - "strings" "testing" ) @@ -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) -} diff --git a/updater/updater.go b/updater/updater.go index 0b7fa13..257f01b 100644 --- a/updater/updater.go +++ b/updater/updater.go @@ -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 @@ -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()) } } diff --git a/updater/updater_test.go b/updater/updater_test.go index 6d273dc..e0834a0 100644 --- a/updater/updater_test.go +++ b/updater/updater_test.go @@ -48,7 +48,7 @@ func TestSyncRecordsCreateNew(t *testing.T) { ID: 123, Type: "A", Name: "test", - Data: "127.0.0.1", + Data: record.Data, }, nil } @@ -56,7 +56,7 @@ func TestSyncRecordsCreateNew(t *testing.T) { ID: 124, Type: "TXT", Name: "neo", - Data: "127.0.0.1 and text", + Data: record.Data, }, nil } @@ -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 } @@ -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 @@ -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 @@ -146,7 +144,7 @@ func TestSyncRecordsUpdateRecord(t *testing.T) { ID: 123, Type: "A", Name: "test", - Data: "127.0.0.1", + Data: record.Data, }, nil } @@ -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 @@ -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 @@ -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 } @@ -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 @@ -272,7 +267,7 @@ func TestCheckAndUpdateOnlyUpdate(t *testing.T) { ID: 123, Type: "A", Name: "test", - Data: "127.0.0.1", + Data: record.Data, }, nil } @@ -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 @@ -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