github.com/minio/madmin-go@v1.7.5/policy-commands_test.go (about) 1 // 2 // MinIO Object Storage (c) 2021 MinIO, Inc. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 package madmin 18 19 import ( 20 "bytes" 21 "encoding/json" 22 "testing" 23 "time" 24 ) 25 26 var ( 27 withCreateDate = []byte(`{"PolicyName":"readwrite","Policy":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["admin:*"]},{"Effect":"Allow","Action":["s3:*"],"Resource":["arn:aws:s3:::*"]}]},"CreateDate":"2020-03-15T10:10:10Z","UpdateDate":"2021-03-15T10:10:10Z"}`) 28 withoutCreateDate = []byte(`{"PolicyName":"readwrite","Policy":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["admin:*"]},{"Effect":"Allow","Action":["s3:*"],"Resource":["arn:aws:s3:::*"]}]}}`) 29 ) 30 31 func TestPolicyInfo(t *testing.T) { 32 testCases := []struct { 33 pi *PolicyInfo 34 expectedBuf []byte 35 }{ 36 { 37 &PolicyInfo{ 38 PolicyName: "readwrite", 39 Policy: []byte(`{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["admin:*"]},{"Effect":"Allow","Action":["s3:*"],"Resource":["arn:aws:s3:::*"]}]}`), 40 CreateDate: time.Date(2020, time.March, 15, 10, 10, 10, 0, time.UTC), 41 UpdateDate: time.Date(2021, time.March, 15, 10, 10, 10, 0, time.UTC), 42 }, 43 withCreateDate, 44 }, 45 { 46 &PolicyInfo{ 47 PolicyName: "readwrite", 48 Policy: []byte(`{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["admin:*"]},{"Effect":"Allow","Action":["s3:*"],"Resource":["arn:aws:s3:::*"]}]}`), 49 }, 50 withoutCreateDate, 51 }, 52 } 53 54 for _, testCase := range testCases { 55 testCase := testCase 56 t.Run("", func(t *testing.T) { 57 buf, err := json.Marshal(testCase.pi) 58 if err != nil { 59 t.Error(err) 60 } 61 if !bytes.Equal(buf, testCase.expectedBuf) { 62 t.Errorf("expected %s, got %s", string(testCase.expectedBuf), string(buf)) 63 } 64 }) 65 } 66 }