๐พ Archived View for source.community โบ ckaznocha โบ gemini โบ blob โบ main โบ status_test.go captured on 2024-05-10 at 11:04:28. Gemini links have been rewritten to link to archived content
โฌ ๏ธ Previous capture (2024-02-05)
-=-=-=-=-=-=-
. ,-. ,-. . . ,-. ,-. ,-. ,-. ,-. ,-,-. ,-,-. . . ,-. . |- . . `-. | | | | | | |-' | | | | | | | | | | | | | | | | | `-' `-' `-^ ' `-' `-' :: `-' `-' ' ' ' ' ' ' `-^ ' ' ' `' `-| /| `-'
git clone https://source.community/ckaznocha/gemini.git
View raw contents of /status_test.go (main)
โโโโโฎ 1โ package gemini_test 2โ 3โ import ( 4โ "reflect" 5โ "testing" 6โ 7โ "source.community/ckaznocha/gemini" 8โ ) 9โ 10โ func TestCategory_ToCode(t *testing.T) { 11โ t.Parallel() 12โ 13โ tests := []struct { 14โ name string 15โ c gemini.StatusCodeCategory 16โ want gemini.StatusCode 17โ }{ 18โ { 19โ name: "", 20โ c: gemini.StatusCategoryPermanentFailure, 21โ want: gemini.StatusPermanentFailure, 22โ }, 23โ { 24โ name: "", 25โ c: 10, 26โ want: 0, 27โ }, 28โ } 29โ 30โ for _, tt := range tests { 31โ tt := tt 32โ t.Run(tt.name, func(t *testing.T) { 33โ t.Parallel() 34โ if got := tt.c.ToCode(); got != tt.want { 35โ t.Errorf("Category.ToCode() = %v, want %v", got, tt.want) 36โ } 37โ }) 38โ } 39โ } 40โ 41โ func TestCategory_String(t *testing.T) { 42โ t.Parallel() 43โ 44โ tests := []struct { 45โ name string 46โ c gemini.StatusCodeCategory 47โ want string 48โ }{ 49โ { 50โ name: "", 51โ c: gemini.StatusCategoryPermanentFailure, 52โ want: "PERMANENT FAILURE", 53โ }, 54โ { 55โ name: "", 56โ c: 10, 57โ want: "StatusCodeCategory(10)", 58โ }, 59โ } 60โ 61โ for _, tt := range tests { 62โ tt := tt 63โ t.Run(tt.name, func(t *testing.T) { 64โ t.Parallel() 65โ if got := tt.c.String(); got != tt.want { 66โ t.Errorf("Category.String() = %v, want %v", got, tt.want) 67โ } 68โ }) 69โ } 70โ } 71โ 72โ func TestCode_MarshalText(t *testing.T) { 73โ t.Parallel() 74โ 75โ tests := []struct { 76โ name string 77โ want []byte 78โ c gemini.StatusCode 79โ wantErr bool 80โ }{ 81โ { 82โ name: "", 83โ want: []byte("59"), 84โ c: gemini.StatusBadRequest, 85โ wantErr: false, 86โ }, 87โ { 88โ name: "", 89โ want: []byte("00"), 90โ c: 100, 91โ wantErr: false, 92โ }, 93โ } 94โ 95โ for _, tt := range tests { 96โ tt := tt 97โ t.Run(tt.name, func(t *testing.T) { 98โ t.Parallel() 99โ got, err := tt.c.MarshalText() 100โ if (err != nil) != tt.wantErr { 101โ t.Errorf("Code.MarshalText() error = %v, wantErr %v", err, tt.wantErr) 102โ 103โ return 104โ } 105โ if !reflect.DeepEqual(got, tt.want) { 106โ t.Errorf("Code.MarshalText() = %v, want %v", got, tt.want) 107โ } 108โ }) 109โ } 110โ } 111โ 112โ func TestCode_ToCategory(t *testing.T) { 113โ t.Parallel() 114โ 115โ tests := []struct { 116โ name string 117โ c gemini.StatusCode 118โ want gemini.StatusCodeCategory 119โ }{ 120โ { 121โ name: "", 122โ c: gemini.StatusBadRequest, 123โ want: gemini.StatusCategoryPermanentFailure, 124โ }, 125โ { 126โ name: "", 127โ c: 100, 128โ want: gemini.StatusCategoryUndefined, 129โ }, 130โ } 131โ 132โ for _, tt := range tests { 133โ tt := tt 134โ t.Run(tt.name, func(t *testing.T) { 135โ t.Parallel() 136โ if got := tt.c.ToCategory(); got != tt.want { 137โ t.Errorf("Code.ToCategory() = %v, want %v", got, tt.want) 138โ } 139โ }) 140โ } 141โ } 142โ 143โ func TestCode_Description(t *testing.T) { 144โ t.Parallel() 145โ 146โ tests := []struct { 147โ name string 148โ want string 149โ c gemini.StatusCode 150โ }{ 151โ { 152โ name: "", 153โ want: "The server was unable to parse the client's request, presumably due to a malformed request.", 154โ c: gemini.StatusBadRequest, 155โ }, 156โ } 157โ 158โ for _, tt := range tests { 159โ tt := tt 160โ t.Run(tt.name, func(t *testing.T) { 161โ t.Parallel() 162โ if got := tt.c.Description(); got != tt.want { 163โ t.Errorf("Code.Description() = %v, want %v", got, tt.want) 164โ } 165โ }) 166โ } 167โ } 168โ 169โ func TestCode_String(t *testing.T) { 170โ t.Parallel() 171โ 172โ tests := []struct { 173โ name string 174โ want string 175โ c gemini.StatusCode 176โ }{ 177โ { 178โ name: "", 179โ want: "INPUT", 180โ c: gemini.StatusCategoryInput.ToCode(), 181โ }, 182โ { 183โ name: "", 184โ want: "SUCCESS", 185โ c: gemini.StatusCategorySuccess.ToCode(), 186โ }, 187โ { 188โ name: "", 189โ want: "REDIRECT - TEMPORARY", 190โ c: gemini.StatusCategoryRedirect.ToCode(), 191โ }, 192โ { 193โ name: "", 194โ want: "TEMPORARY FAILURE", 195โ c: gemini.StatusCategoryTemporaryFailure.ToCode(), 196โ }, 197โ { 198โ name: "", 199โ want: "PERMANENT FAILURE", 200โ c: gemini.StatusCategoryPermanentFailure.ToCode(), 201โ }, 202โ { 203โ name: "", 204โ want: "CLIENT CERTIFICATE REQUIRED", 205โ c: gemini.StatusCategoryClientCertificateRequired.ToCode(), 206โ }, 207โ { 208โ name: "", 209โ want: "StatusCode(0)", 210โ c: 0, 211โ }, 212โ } 213โ 214โ for _, tt := range tests { 215โ tt := tt 216โ t.Run(tt.name, func(t *testing.T) { 217โ t.Parallel() 218โ if got := tt.c.String(); got != tt.want { 219โ t.Errorf("Code.String() = %v, want %v", got, tt.want) 220โ } 221โ }) 222โ } 223โ } โโโโโฏ
ยท ยท ยท
ยฉ 2024 source.community