github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/amztime/iso8601_time_test.go (about) 1 // Copyright (c) 2015-2022 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 amztime 19 20 import ( 21 "testing" 22 "time" 23 ) 24 25 func TestISO8601Format(t *testing.T) { 26 testCases := []struct { 27 date time.Time 28 expectedOutput string 29 }{ 30 { 31 date: time.Date(2009, time.November, 13, 4, 51, 1, 940303531, time.UTC), 32 expectedOutput: "2009-11-13T04:51:01.940Z", 33 }, 34 { 35 date: time.Date(2009, time.November, 13, 4, 51, 1, 901303531, time.UTC), 36 expectedOutput: "2009-11-13T04:51:01.901Z", 37 }, 38 { 39 date: time.Date(2009, time.November, 13, 4, 51, 1, 900303531, time.UTC), 40 expectedOutput: "2009-11-13T04:51:01.900Z", 41 }, 42 { 43 date: time.Date(2009, time.November, 13, 4, 51, 1, 941303531, time.UTC), 44 expectedOutput: "2009-11-13T04:51:01.941Z", 45 }, 46 } 47 48 for _, testCase := range testCases { 49 testCase := testCase 50 t.Run(testCase.expectedOutput, func(t *testing.T) { 51 gotOutput := ISO8601Format(testCase.date) 52 t.Log("Go", testCase.date.Format(iso8601TimeFormat)) 53 if gotOutput != testCase.expectedOutput { 54 t.Errorf("Expected %s, got %s", testCase.expectedOutput, gotOutput) 55 } 56 }) 57 } 58 }