github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/bucket/lifecycle/transition_test.go (about) 1 // Copyright (c) 2015-2021 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package lifecycle 19 20 import ( 21 "encoding/xml" 22 "testing" 23 ) 24 25 func TestTransitionUnmarshalXML(t *testing.T) { 26 trTests := []struct { 27 input string 28 err error 29 }{ 30 { 31 input: `<Transition> 32 <Days>0</Days> 33 <StorageClass>S3TIER-1</StorageClass> 34 </Transition>`, 35 err: nil, 36 }, 37 { 38 input: `<Transition> 39 <Days>1</Days> 40 <Date>2021-01-01T00:00:00Z</Date> 41 <StorageClass>S3TIER-1</StorageClass> 42 </Transition>`, 43 err: errTransitionInvalid, 44 }, 45 { 46 input: `<Transition> 47 <Days>1</Days> 48 </Transition>`, 49 err: errXMLNotWellFormed, 50 }, 51 } 52 53 for i, tc := range trTests { 54 var tr Transition 55 err := xml.Unmarshal([]byte(tc.input), &tr) 56 if err != nil { 57 t.Fatalf("%d: xml unmarshal failed with %v", i+1, err) 58 } 59 if err = tr.Validate(); err != tc.err { 60 t.Fatalf("%d: Invalid transition %v: err %v", i+1, tr, err) 61 } 62 } 63 64 ntrTests := []struct { 65 input string 66 err error 67 }{ 68 { 69 input: `<NoncurrentVersionTransition> 70 <NoncurrentDays>0</NoncurrentDays> 71 <StorageClass>S3TIER-1</StorageClass> 72 </NoncurrentVersionTransition>`, 73 err: nil, 74 }, 75 { 76 input: `<NoncurrentVersionTransition> 77 <Days>1</Days> 78 </NoncurrentVersionTransition>`, 79 err: errXMLNotWellFormed, 80 }, 81 } 82 83 for i, tc := range ntrTests { 84 var ntr NoncurrentVersionTransition 85 err := xml.Unmarshal([]byte(tc.input), &ntr) 86 if err != nil { 87 t.Fatalf("%d: xml unmarshal failed with %v", i+1, err) 88 } 89 if err = ntr.Validate(); err != tc.err { 90 t.Fatalf("%d: Invalid noncurrent version transition %v: err %v", i+1, ntr, err) 91 } 92 } 93 }