github.com/lestrrat-go/jwx/v2@v2.0.21/jwa/content_encryption_gen_test.go (about) 1 // Code generated by tools/cmd/genjwa/main.go. DO NOT EDIT 2 3 package jwa_test 4 5 import ( 6 "testing" 7 8 "github.com/lestrrat-go/jwx/v2/jwa" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestContentEncryptionAlgorithm(t *testing.T) { 13 t.Parallel() 14 t.Run(`accept jwa constant A128CBC_HS256`, func(t *testing.T) { 15 t.Parallel() 16 var dst jwa.ContentEncryptionAlgorithm 17 if !assert.NoError(t, dst.Accept(jwa.A128CBC_HS256), `accept is successful`) { 18 return 19 } 20 if !assert.Equal(t, jwa.A128CBC_HS256, dst, `accepted value should be equal to constant`) { 21 return 22 } 23 }) 24 t.Run(`accept the string A128CBC-HS256`, func(t *testing.T) { 25 t.Parallel() 26 var dst jwa.ContentEncryptionAlgorithm 27 if !assert.NoError(t, dst.Accept("A128CBC-HS256"), `accept is successful`) { 28 return 29 } 30 if !assert.Equal(t, jwa.A128CBC_HS256, dst, `accepted value should be equal to constant`) { 31 return 32 } 33 }) 34 t.Run(`accept fmt.Stringer for A128CBC-HS256`, func(t *testing.T) { 35 t.Parallel() 36 var dst jwa.ContentEncryptionAlgorithm 37 if !assert.NoError(t, dst.Accept(stringer{src: "A128CBC-HS256"}), `accept is successful`) { 38 return 39 } 40 if !assert.Equal(t, jwa.A128CBC_HS256, dst, `accepted value should be equal to constant`) { 41 return 42 } 43 }) 44 t.Run(`stringification for A128CBC-HS256`, func(t *testing.T) { 45 t.Parallel() 46 if !assert.Equal(t, "A128CBC-HS256", jwa.A128CBC_HS256.String(), `stringified value matches`) { 47 return 48 } 49 }) 50 t.Run(`accept jwa constant A128GCM`, func(t *testing.T) { 51 t.Parallel() 52 var dst jwa.ContentEncryptionAlgorithm 53 if !assert.NoError(t, dst.Accept(jwa.A128GCM), `accept is successful`) { 54 return 55 } 56 if !assert.Equal(t, jwa.A128GCM, dst, `accepted value should be equal to constant`) { 57 return 58 } 59 }) 60 t.Run(`accept the string A128GCM`, func(t *testing.T) { 61 t.Parallel() 62 var dst jwa.ContentEncryptionAlgorithm 63 if !assert.NoError(t, dst.Accept("A128GCM"), `accept is successful`) { 64 return 65 } 66 if !assert.Equal(t, jwa.A128GCM, dst, `accepted value should be equal to constant`) { 67 return 68 } 69 }) 70 t.Run(`accept fmt.Stringer for A128GCM`, func(t *testing.T) { 71 t.Parallel() 72 var dst jwa.ContentEncryptionAlgorithm 73 if !assert.NoError(t, dst.Accept(stringer{src: "A128GCM"}), `accept is successful`) { 74 return 75 } 76 if !assert.Equal(t, jwa.A128GCM, dst, `accepted value should be equal to constant`) { 77 return 78 } 79 }) 80 t.Run(`stringification for A128GCM`, func(t *testing.T) { 81 t.Parallel() 82 if !assert.Equal(t, "A128GCM", jwa.A128GCM.String(), `stringified value matches`) { 83 return 84 } 85 }) 86 t.Run(`accept jwa constant A192CBC_HS384`, func(t *testing.T) { 87 t.Parallel() 88 var dst jwa.ContentEncryptionAlgorithm 89 if !assert.NoError(t, dst.Accept(jwa.A192CBC_HS384), `accept is successful`) { 90 return 91 } 92 if !assert.Equal(t, jwa.A192CBC_HS384, dst, `accepted value should be equal to constant`) { 93 return 94 } 95 }) 96 t.Run(`accept the string A192CBC-HS384`, func(t *testing.T) { 97 t.Parallel() 98 var dst jwa.ContentEncryptionAlgorithm 99 if !assert.NoError(t, dst.Accept("A192CBC-HS384"), `accept is successful`) { 100 return 101 } 102 if !assert.Equal(t, jwa.A192CBC_HS384, dst, `accepted value should be equal to constant`) { 103 return 104 } 105 }) 106 t.Run(`accept fmt.Stringer for A192CBC-HS384`, func(t *testing.T) { 107 t.Parallel() 108 var dst jwa.ContentEncryptionAlgorithm 109 if !assert.NoError(t, dst.Accept(stringer{src: "A192CBC-HS384"}), `accept is successful`) { 110 return 111 } 112 if !assert.Equal(t, jwa.A192CBC_HS384, dst, `accepted value should be equal to constant`) { 113 return 114 } 115 }) 116 t.Run(`stringification for A192CBC-HS384`, func(t *testing.T) { 117 t.Parallel() 118 if !assert.Equal(t, "A192CBC-HS384", jwa.A192CBC_HS384.String(), `stringified value matches`) { 119 return 120 } 121 }) 122 t.Run(`accept jwa constant A192GCM`, func(t *testing.T) { 123 t.Parallel() 124 var dst jwa.ContentEncryptionAlgorithm 125 if !assert.NoError(t, dst.Accept(jwa.A192GCM), `accept is successful`) { 126 return 127 } 128 if !assert.Equal(t, jwa.A192GCM, dst, `accepted value should be equal to constant`) { 129 return 130 } 131 }) 132 t.Run(`accept the string A192GCM`, func(t *testing.T) { 133 t.Parallel() 134 var dst jwa.ContentEncryptionAlgorithm 135 if !assert.NoError(t, dst.Accept("A192GCM"), `accept is successful`) { 136 return 137 } 138 if !assert.Equal(t, jwa.A192GCM, dst, `accepted value should be equal to constant`) { 139 return 140 } 141 }) 142 t.Run(`accept fmt.Stringer for A192GCM`, func(t *testing.T) { 143 t.Parallel() 144 var dst jwa.ContentEncryptionAlgorithm 145 if !assert.NoError(t, dst.Accept(stringer{src: "A192GCM"}), `accept is successful`) { 146 return 147 } 148 if !assert.Equal(t, jwa.A192GCM, dst, `accepted value should be equal to constant`) { 149 return 150 } 151 }) 152 t.Run(`stringification for A192GCM`, func(t *testing.T) { 153 t.Parallel() 154 if !assert.Equal(t, "A192GCM", jwa.A192GCM.String(), `stringified value matches`) { 155 return 156 } 157 }) 158 t.Run(`accept jwa constant A256CBC_HS512`, func(t *testing.T) { 159 t.Parallel() 160 var dst jwa.ContentEncryptionAlgorithm 161 if !assert.NoError(t, dst.Accept(jwa.A256CBC_HS512), `accept is successful`) { 162 return 163 } 164 if !assert.Equal(t, jwa.A256CBC_HS512, dst, `accepted value should be equal to constant`) { 165 return 166 } 167 }) 168 t.Run(`accept the string A256CBC-HS512`, func(t *testing.T) { 169 t.Parallel() 170 var dst jwa.ContentEncryptionAlgorithm 171 if !assert.NoError(t, dst.Accept("A256CBC-HS512"), `accept is successful`) { 172 return 173 } 174 if !assert.Equal(t, jwa.A256CBC_HS512, dst, `accepted value should be equal to constant`) { 175 return 176 } 177 }) 178 t.Run(`accept fmt.Stringer for A256CBC-HS512`, func(t *testing.T) { 179 t.Parallel() 180 var dst jwa.ContentEncryptionAlgorithm 181 if !assert.NoError(t, dst.Accept(stringer{src: "A256CBC-HS512"}), `accept is successful`) { 182 return 183 } 184 if !assert.Equal(t, jwa.A256CBC_HS512, dst, `accepted value should be equal to constant`) { 185 return 186 } 187 }) 188 t.Run(`stringification for A256CBC-HS512`, func(t *testing.T) { 189 t.Parallel() 190 if !assert.Equal(t, "A256CBC-HS512", jwa.A256CBC_HS512.String(), `stringified value matches`) { 191 return 192 } 193 }) 194 t.Run(`accept jwa constant A256GCM`, func(t *testing.T) { 195 t.Parallel() 196 var dst jwa.ContentEncryptionAlgorithm 197 if !assert.NoError(t, dst.Accept(jwa.A256GCM), `accept is successful`) { 198 return 199 } 200 if !assert.Equal(t, jwa.A256GCM, dst, `accepted value should be equal to constant`) { 201 return 202 } 203 }) 204 t.Run(`accept the string A256GCM`, func(t *testing.T) { 205 t.Parallel() 206 var dst jwa.ContentEncryptionAlgorithm 207 if !assert.NoError(t, dst.Accept("A256GCM"), `accept is successful`) { 208 return 209 } 210 if !assert.Equal(t, jwa.A256GCM, dst, `accepted value should be equal to constant`) { 211 return 212 } 213 }) 214 t.Run(`accept fmt.Stringer for A256GCM`, func(t *testing.T) { 215 t.Parallel() 216 var dst jwa.ContentEncryptionAlgorithm 217 if !assert.NoError(t, dst.Accept(stringer{src: "A256GCM"}), `accept is successful`) { 218 return 219 } 220 if !assert.Equal(t, jwa.A256GCM, dst, `accepted value should be equal to constant`) { 221 return 222 } 223 }) 224 t.Run(`stringification for A256GCM`, func(t *testing.T) { 225 t.Parallel() 226 if !assert.Equal(t, "A256GCM", jwa.A256GCM.String(), `stringified value matches`) { 227 return 228 } 229 }) 230 t.Run(`bail out on random integer value`, func(t *testing.T) { 231 t.Parallel() 232 var dst jwa.ContentEncryptionAlgorithm 233 if !assert.Error(t, dst.Accept(1), `accept should fail`) { 234 return 235 } 236 }) 237 t.Run(`do not accept invalid (totally made up) string value`, func(t *testing.T) { 238 t.Parallel() 239 var dst jwa.ContentEncryptionAlgorithm 240 if !assert.Error(t, dst.Accept(`totallyInvfalidValue`), `accept should fail`) { 241 return 242 } 243 }) 244 t.Run(`check list of elements`, func(t *testing.T) { 245 t.Parallel() 246 var expected = map[jwa.ContentEncryptionAlgorithm]struct{}{ 247 jwa.A128CBC_HS256: {}, 248 jwa.A128GCM: {}, 249 jwa.A192CBC_HS384: {}, 250 jwa.A192GCM: {}, 251 jwa.A256CBC_HS512: {}, 252 jwa.A256GCM: {}, 253 } 254 for _, v := range jwa.ContentEncryptionAlgorithms() { 255 if _, ok := expected[v]; !assert.True(t, ok, `%s should be in the expected list`, v) { 256 return 257 } 258 delete(expected, v) 259 } 260 if !assert.Len(t, expected, 0) { 261 return 262 } 263 }) 264 }