github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/ee/backup/handler_test.go (about) 1 // +build !oss 2 3 /* 4 * Copyright 2018 Dgraph Labs, Inc. and Contributors 5 * 6 * Licensed under the Dgraph Community License (the "License"); you 7 * may not use this file except in compliance with the License. You 8 * may obtain a copy of the License at 9 * 10 * https://github.com/dgraph-io/dgraph/blob/master/licenses/DCL.txt 11 */ 12 13 package backup 14 15 import ( 16 "testing" 17 18 "github.com/stretchr/testify/require" 19 ) 20 21 func TestGetHandler(t *testing.T) { 22 tests := []struct { 23 in string 24 out UriHandler 25 }{ 26 {in: "file", out: &fileHandler{}}, 27 {in: "minio", out: &s3Handler{}}, 28 {in: "s3", out: &s3Handler{}}, 29 {in: "", out: &fileHandler{}}, 30 {in: "something", out: nil}, 31 } 32 for _, tc := range tests { 33 actual := getHandler(tc.in) 34 require.Equal(t, tc.out, actual) 35 } 36 } 37 38 func TestFilterManifestDefault(t *testing.T) { 39 manifests := []*Manifest{ 40 { 41 Type: "full", 42 BackupId: "aa", 43 BackupNum: 1, 44 }, 45 { 46 Type: "full", 47 BackupId: "ab", 48 BackupNum: 1, 49 }, 50 } 51 expected := []*Manifest{ 52 { 53 Type: "full", 54 BackupId: "ab", 55 BackupNum: 1, 56 }, 57 } 58 manifests, err := filterManifests(manifests, "") 59 require.NoError(t, err) 60 require.Equal(t, manifests, expected) 61 } 62 63 func TestFilterManifestSelectSeries(t *testing.T) { 64 manifests := []*Manifest{ 65 { 66 Type: "full", 67 BackupId: "aa", 68 BackupNum: 1, 69 }, 70 { 71 Type: "full", 72 BackupId: "ab", 73 BackupNum: 1, 74 }, 75 } 76 expected := []*Manifest{ 77 { 78 Type: "full", 79 BackupId: "aa", 80 BackupNum: 1, 81 }, 82 } 83 manifests, err := filterManifests(manifests, "aa") 84 require.NoError(t, err) 85 require.Equal(t, manifests, expected) 86 } 87 88 func TestFilterManifestMissingBackup(t *testing.T) { 89 manifests := []*Manifest{ 90 { 91 Type: "full", 92 BackupId: "aa", 93 BackupNum: 1, 94 }, 95 { 96 Type: "incremental", 97 BackupId: "aa", 98 BackupNum: 3, 99 }, 100 } 101 _, err := filterManifests(manifests, "aa") 102 require.Error(t, err) 103 require.Contains(t, err.Error(), "found a manifest with backup number") 104 } 105 106 func TestFilterManifestMissingFirstBackup(t *testing.T) { 107 manifests := []*Manifest{ 108 { 109 Type: "incremental", 110 BackupId: "aa", 111 BackupNum: 2, 112 }, 113 { 114 Type: "incremental", 115 BackupId: "aa", 116 BackupNum: 3, 117 }, 118 } 119 _, err := filterManifests(manifests, "aa") 120 require.Error(t, err) 121 require.Contains(t, err.Error(), "expected a BackupNum value of 1 for first manifest") 122 } 123 124 func TestFilterManifestDifferentSeries(t *testing.T) { 125 manifests := []*Manifest{ 126 { 127 Type: "full", 128 BackupId: "aa", 129 BackupNum: 1, 130 }, 131 { 132 Type: "incremental", 133 BackupId: "ab", 134 BackupNum: 2, 135 }, 136 } 137 _, err := filterManifests(manifests, "") 138 require.Error(t, err) 139 require.Contains(t, err.Error(), "found a manifest with backup ID") 140 }