Skip to content

Commit

Permalink
Handle 404 http code in responses of delete backup (#8)
Browse files Browse the repository at this point in the history
* Handle 404 HTTP Code in responses of "Delete Backup"
* Add test for 404 http code in delete backup
* Fix syntax errors
* Update dbaas adapter core version
  • Loading branch information
mchekalov authored Feb 11, 2025
1 parent e496763 commit 6c04fc6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
10 changes: 6 additions & 4 deletions adapter/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var generatorMutex = sync.Mutex{}
func newPostgresAdapterBackupActionTrack(task *PostgresBackupStatus) dao.DatabaseAdapterBaseTrack {
var details *dao.DatabasesBackupAdapt = nil

if "Successful" == task.Status {
if task.Status == "Successful" {
details = &dao.DatabasesBackupAdapt{
LocalId: task.BackupId,
}
Expand Down Expand Up @@ -275,13 +275,15 @@ func (ba BackupAdapter) getRestoreStatus(ctx context.Context, trackId string) (*
return &restoreStatus, true
}

func (ba BackupAdapter) EvictBackup(ctx context.Context, backupId string) string {
func (ba BackupAdapter) EvictBackup(ctx context.Context, backupId string) (string, bool) {
logger := util.ContextLogger(ctx)
response, err := ba.sendRequest(ctx, Post, "/delete/"+backupId, nil)
if err != nil {
panic(err)
}

if response.Status == http.StatusNotFound {
return "", false
}
var deleteResponse PostgresBackupDeleteResponse
err = json.Unmarshal(response.Body, &deleteResponse)
if err != nil {
Expand All @@ -298,7 +300,7 @@ func (ba BackupAdapter) EvictBackup(ctx context.Context, backupId string) string
}
}
//todo
return status
return status, true

}

Expand Down
27 changes: 18 additions & 9 deletions adapter/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func startTestServer() {
}

//EVictBackup
EvictBackupPrefix := "/delete/"
EvictBackupPrefix := "/delete/20240105T0836"
if strings.HasPrefix(r.URL.Path, EvictBackupPrefix) {
trackId := strings.TrimPrefix(r.URL.Path, EvictBackupPrefix)

Expand Down Expand Up @@ -271,11 +271,6 @@ func TestTrackBackupTest(t *testing.T) {

statusRequestBody := PostgresBackupStatus{
BackupId: "20240105T0836",
Status: "Successful",
Databases: map[string]PostgresDatabaseBackupStatus{
"db1": {Status: "Successful"},
"db2": {Status: "In progress"},
},
}

backupAdapater := NewServiceAdapter(nil, aggAddress, "", false, "", "", "")
Expand All @@ -300,7 +295,6 @@ func TestTrackRestoreStatus(t *testing.T) {

statusRequestBody := PostgresRestoreStatus{
TrackingId: "20240105T0836",
Status: "SUCCESS",
}

backupAdapater := NewServiceAdapter(nil, aggAddress, "", false, "", "", "")
Expand All @@ -325,10 +319,25 @@ func TestEvictBackupStatus(t *testing.T) {

backupAdapater := NewServiceAdapter(nil, aggAddress, "", false, "", "", "")

backupStatus := backupAdapater.EvictBackup(context.Background(), "20240105T0836")
backupStatus, isFound := backupAdapater.EvictBackup(context.Background(), "20240105T0836")

fmt.Printf("Backup EVICT NEwStatus: %v\n", backupStatus)
fmt.Printf("Backup EVICT NewStatus: %v\n", backupStatus)
assert.Equal(t, backupStatus, "SUCCESS")
assert.Equal(t, true, isFound)

}

func TestEvictBackupIdNotFound(t *testing.T) {

aggAddress := "http://localhost:8080"

backupAdapater := NewServiceAdapter(nil, aggAddress, "", false, "", "", "")

backupStatus, isFound := backupAdapater.EvictBackup(context.Background(), "20240105T0833")

fmt.Printf("Backup EVICT NewStatus: %v\n", backupStatus)
assert.Equal(t, backupStatus, "")
assert.Equal(t, false, isFound)

}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Netcracker/pgskipper-dbaas-adapter/postgresql-dbaas-adapter
go 1.21

require (
github.com/Netcracker/qubership-dbaas-adapter-core v0.9.4
github.com/Netcracker/qubership-dbaas-adapter-core v0.9.5
github.com/gofiber/fiber/v2 v2.52.5
github.com/jackc/pgconn v1.14.3
github.com/jackc/pgx/v4 v4.18.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/Netcracker/qubership-dbaas-adapter-core v0.9.4 h1:YEigbUpPnfcPBAALwB2+Zu4DTVojmJsbmMhyaS3z6Kc=
github.com/Netcracker/qubership-dbaas-adapter-core v0.9.4/go.mod h1:dEXm/aZmbDHVkkMqmcU901I1akukhL+3y4bPoTWBWFQ=
github.com/Netcracker/qubership-dbaas-adapter-core v0.9.5 h1:fv6sMasCFsQAPggYT38Peh8khCSc8oZOEz5kiVZCzfc=
github.com/Netcracker/qubership-dbaas-adapter-core v0.9.5/go.mod h1:dEXm/aZmbDHVkkMqmcU901I1akukhL+3y4bPoTWBWFQ=
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
Expand Down

0 comments on commit 6c04fc6

Please sign in to comment.