github.com/searKing/golang/go@v1.2.117/net/http/warn_test.go (about) 1 // Copyright 2023 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package http 6 7 import ( 8 "strings" 9 "testing" 10 "time" 11 ) 12 13 type respWriteTest struct { 14 Resp Warn 15 Raw string 16 } 17 18 func TestWarn_Write(t *testing.T) { 19 respWriteTests := []respWriteTest{ 20 { 21 Warn{ 22 WarnCode: WarnTransformationApplied, 23 }, 24 25 `214 - "Transformation Applied"`, 26 }, 27 { 28 Warn{ 29 Warn: "cache down", 30 WarnCode: WarnDisconnectedOperation, 31 Date: time.Date(2015, 10, 21, 7, 28, 0, 0, time.UTC), 32 }, 33 34 `112 - "cache down" "Wed, 21 Oct 2015 07:28:00 GMT"`, 35 }, 36 { 37 Warn{ 38 Warn: "Arbitrary information that should be presented to a user or logged.", 39 WarnCode: WarnMiscellaneousWarning, 40 Agent: "Go-http-client/1.1", 41 }, 42 43 `199 Go-http-client/1.1 "Arbitrary information that should be presented to a user or logged."`, 44 }, 45 { 46 Warn{ 47 Warn: "Arbitrary information that should be presented to a user or logged. " + 48 "This warn-code is similar to the warn-code 199 and additionally indicates a persistent warning.", 49 WarnCode: WarnMiscellaneousPersistentWarning, 50 Date: time.Date(2011, 11, 23, 1, 5, 3, 0, time.UTC), 51 }, 52 53 `299 - "Arbitrary information that should be presented to a user or logged. This warn-code is similar to the warn-code 199 and additionally indicates a persistent warning." "Wed, 23 Nov 2011 01:05:03 GMT"`, 54 }, 55 } 56 57 for i := range respWriteTests { 58 tt := &respWriteTests[i] 59 var braw strings.Builder 60 err := tt.Resp.Write(&braw) 61 if err != nil { 62 t.Errorf("error writing #%d: %s", i, err) 63 continue 64 } 65 sraw := braw.String() 66 if sraw != tt.Raw { 67 t.Errorf("Test %d, expecting:\n%q\nGot:\n%q\n", i, tt.Raw, sraw) 68 continue 69 } 70 } 71 }