How to use Errorf method of got Package

Best Got code snippet using got.Errorf

integration_test.go

Source:integration_test.go Github

copy

Full Screen

...44 return nil45 },46 ),47 ); err != nil {48 t.Errorf("gw.Run() failed with %v; want success", err)49 return50 }51 }()52 time.Sleep(100 * time.Millisecond)53 testEcho(t, 8081, "application/vnd.docker.plugins.v1.1+json")54}55func testEcho(t *testing.T, port int, contentType string) {56 url := fmt.Sprintf("http://localhost:%d/v1/example/echo/myid", port)57 resp, err := http.Post(url, "application/json", strings.NewReader("{}"))58 if err != nil {59 t.Errorf("http.Post(%q) failed with %v; want success", url, err)60 return61 }62 defer resp.Body.Close()63 buf, err := ioutil.ReadAll(resp.Body)64 if err != nil {65 t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)66 return67 }68 if got, want := resp.StatusCode, http.StatusOK; got != want {69 t.Errorf("resp.StatusCode = %d; want %d", got, want)70 t.Logf("%s", buf)71 }72 var msg gw.SimpleMessage73 if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {74 t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)75 return76 }77 if got, want := msg.Id, "myid"; got != want {78 t.Errorf("msg.Id = %q; want %q", got, want)79 }80 if value := resp.Header.Get("Content-Type"); value != contentType {81 t.Errorf("Content-Type was %s, wanted %s", value, contentType)82 }83}84func testEchoBody(t *testing.T, port int) {85 sent := gw.SimpleMessage{Id: "example"}86 var m jsonpb.Marshaler87 payload, err := m.MarshalToString(&sent)88 if err != nil {89 t.Fatalf("m.MarshalToString(%#v) failed with %v; want success", payload, err)90 }91 url := fmt.Sprintf("http://localhost:%d/v1/example/echo_body", port)92 resp, err := http.Post(url, "", strings.NewReader(payload))93 if err != nil {94 t.Errorf("http.Post(%q) failed with %v; want success", url, err)95 return96 }97 defer resp.Body.Close()98 buf, err := ioutil.ReadAll(resp.Body)99 if err != nil {100 t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)101 return102 }103 if got, want := resp.StatusCode, http.StatusOK; got != want {104 t.Errorf("resp.StatusCode = %d; want %d", got, want)105 t.Logf("%s", buf)106 }107 var received gw.SimpleMessage108 if err := jsonpb.UnmarshalString(string(buf), &received); err != nil {109 t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)110 return111 }112 if got, want := received, sent; !reflect.DeepEqual(got, want) {113 t.Errorf("msg.Id = %q; want %q", got, want)114 }115 if got, want := resp.Header.Get("Grpc-Metadata-Foo"), "foo1"; got != want {116 t.Errorf("Grpc-Metadata-Foo was %q, wanted %q", got, want)117 }118 if got, want := resp.Header.Get("Grpc-Metadata-Bar"), "bar1"; got != want {119 t.Errorf("Grpc-Metadata-Bar was %q, wanted %q", got, want)120 }121 if got, want := resp.Trailer.Get("Grpc-Trailer-Foo"), "foo2"; got != want {122 t.Errorf("Grpc-Trailer-Foo was %q, wanted %q", got, want)123 }124 if got, want := resp.Trailer.Get("Grpc-Trailer-Bar"), "bar2"; got != want {125 t.Errorf("Grpc-Trailer-Bar was %q, wanted %q", got, want)126 }127}128func TestABE(t *testing.T) {129 if testing.Short() {130 t.Skip()131 return132 }133 testABECreate(t, 8080)134 testABECreateBody(t, 8080)135 testABEBulkCreate(t, 8080)136 testABELookup(t, 8080)137 testABELookupNotFound(t, 8080)138 testABEList(t, 8080)139 testABEBulkEcho(t, 8080)140 testABEBulkEchoZeroLength(t, 8080)141 testAdditionalBindings(t, 8080)142}143func testABECreate(t *testing.T, port int) {144 want := gw.ABitOfEverything{145 FloatValue: 1.5,146 DoubleValue: 2.5,147 Int64Value: 4294967296,148 Uint64Value: 9223372036854775807,149 Int32Value: -2147483648,150 Fixed64Value: 9223372036854775807,151 Fixed32Value: 4294967295,152 BoolValue: true,153 StringValue: "strprefix/foo",154 Uint32Value: 4294967295,155 Sfixed32Value: 2147483647,156 Sfixed64Value: -4611686018427387904,157 Sint32Value: 2147483647,158 Sint64Value: 4611686018427387903,159 NonConventionalNameValue: "camelCase",160 }161 url := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything/%f/%f/%d/separator/%d/%d/%d/%d/%v/%s/%d/%d/%d/%d/%d/%s", port, want.FloatValue, want.DoubleValue, want.Int64Value, want.Uint64Value, want.Int32Value, want.Fixed64Value, want.Fixed32Value, want.BoolValue, want.StringValue, want.Uint32Value, want.Sfixed32Value, want.Sfixed64Value, want.Sint32Value, want.Sint64Value, want.NonConventionalNameValue)162 resp, err := http.Post(url, "application/json", strings.NewReader("{}"))163 if err != nil {164 t.Errorf("http.Post(%q) failed with %v; want success", url, err)165 return166 }167 defer resp.Body.Close()168 buf, err := ioutil.ReadAll(resp.Body)169 if err != nil {170 t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)171 return172 }173 if got, want := resp.StatusCode, http.StatusOK; got != want {174 t.Errorf("resp.StatusCode = %d; want %d", got, want)175 t.Logf("%s", buf)176 }177 var msg gw.ABitOfEverything178 if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {179 t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)180 return181 }182 if msg.Uuid == "" {183 t.Error("msg.Uuid is empty; want not empty")184 }185 msg.Uuid = ""186 if got := msg; !reflect.DeepEqual(got, want) {187 t.Errorf("msg= %v; want %v", &got, &want)188 }189}190func testABECreateBody(t *testing.T, port int) {191 want := gw.ABitOfEverything{192 FloatValue: 1.5,193 DoubleValue: 2.5,194 Int64Value: 4294967296,195 Uint64Value: 9223372036854775807,196 Int32Value: -2147483648,197 Fixed64Value: 9223372036854775807,198 Fixed32Value: 4294967295,199 BoolValue: true,200 StringValue: "strprefix/foo",201 Uint32Value: 4294967295,202 Sfixed32Value: 2147483647,203 Sfixed64Value: -4611686018427387904,204 Sint32Value: 2147483647,205 Sint64Value: 4611686018427387903,206 NonConventionalNameValue: "camelCase",207 Nested: []*gw.ABitOfEverything_Nested{208 {209 Name: "bar",210 Amount: 10,211 },212 {213 Name: "baz",214 Amount: 20,215 },216 },217 RepeatedStringValue: []string{"a", "b", "c"},218 OneofValue: &gw.ABitOfEverything_OneofString{219 OneofString: "x",220 },221 MapValue: map[string]gw.NumericEnum{222 "a": gw.NumericEnum_ONE,223 "b": gw.NumericEnum_ZERO,224 },225 MappedStringValue: map[string]string{226 "a": "x",227 "b": "y",228 },229 MappedNestedValue: map[string]*gw.ABitOfEverything_Nested{230 "a": {Name: "x", Amount: 1},231 "b": {Name: "y", Amount: 2},232 },233 }234 url := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything", port)235 var m jsonpb.Marshaler236 payload, err := m.MarshalToString(&want)237 if err != nil {238 t.Fatalf("m.MarshalToString(%#v) failed with %v; want success", want, err)239 }240 resp, err := http.Post(url, "application/json", strings.NewReader(payload))241 if err != nil {242 t.Errorf("http.Post(%q) failed with %v; want success", url, err)243 return244 }245 defer resp.Body.Close()246 buf, err := ioutil.ReadAll(resp.Body)247 if err != nil {248 t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)249 return250 }251 if got, want := resp.StatusCode, http.StatusOK; got != want {252 t.Errorf("resp.StatusCode = %d; want %d", got, want)253 t.Logf("%s", buf)254 }255 var msg gw.ABitOfEverything256 if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {257 t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)258 return259 }260 if msg.Uuid == "" {261 t.Error("msg.Uuid is empty; want not empty")262 }263 msg.Uuid = ""264 if got := msg; !reflect.DeepEqual(got, want) {265 t.Errorf("msg= %v; want %v", &got, &want)266 }267}268func testABEBulkCreate(t *testing.T, port int) {269 count := 0270 r, w := io.Pipe()271 go func(w io.WriteCloser) {272 defer func() {273 if cerr := w.Close(); cerr != nil {274 t.Errorf("w.Close() failed with %v; want success", cerr)275 }276 }()277 for _, val := range []string{278 "foo", "bar", "baz", "qux", "quux",279 } {280 want := gw.ABitOfEverything{281 FloatValue: 1.5,282 DoubleValue: 2.5,283 Int64Value: 4294967296,284 Uint64Value: 9223372036854775807,285 Int32Value: -2147483648,286 Fixed64Value: 9223372036854775807,287 Fixed32Value: 4294967295,288 BoolValue: true,289 StringValue: fmt.Sprintf("strprefix/%s", val),290 Uint32Value: 4294967295,291 Sfixed32Value: 2147483647,292 Sfixed64Value: -4611686018427387904,293 Sint32Value: 2147483647,294 Sint64Value: 4611686018427387903,295 NonConventionalNameValue: "camelCase",296 Nested: []*gw.ABitOfEverything_Nested{297 {298 Name: "hoge",299 Amount: 10,300 },301 {302 Name: "fuga",303 Amount: 20,304 },305 },306 }307 var m jsonpb.Marshaler308 if err := m.Marshal(w, &want); err != nil {309 t.Fatalf("m.Marshal(%#v, w) failed with %v; want success", want, err)310 }311 if _, err := io.WriteString(w, "\n"); err != nil {312 t.Errorf("w.Write(%q) failed with %v; want success", "\n", err)313 return314 }315 count++316 }317 }(w)318 url := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything/bulk", port)319 resp, err := http.Post(url, "application/json", r)320 if err != nil {321 t.Errorf("http.Post(%q) failed with %v; want success", url, err)322 return323 }324 defer resp.Body.Close()325 buf, err := ioutil.ReadAll(resp.Body)326 if err != nil {327 t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)328 return329 }330 if got, want := resp.StatusCode, http.StatusOK; got != want {331 t.Errorf("resp.StatusCode = %d; want %d", got, want)332 t.Logf("%s", buf)333 }334 var msg empty.Empty335 if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {336 t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)337 return338 }339 if got, want := resp.Header.Get("Grpc-Metadata-Count"), fmt.Sprintf("%d", count); got != want {340 t.Errorf("Grpc-Metadata-Count was %q, wanted %q", got, want)341 }342 if got, want := resp.Trailer.Get("Grpc-Trailer-Foo"), "foo2"; got != want {343 t.Errorf("Grpc-Trailer-Foo was %q, wanted %q", got, want)344 }345 if got, want := resp.Trailer.Get("Grpc-Trailer-Bar"), "bar2"; got != want {346 t.Errorf("Grpc-Trailer-Bar was %q, wanted %q", got, want)347 }348}349func testABELookup(t *testing.T, port int) {350 url := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything", port)351 cresp, err := http.Post(url, "application/json", strings.NewReader(`352 {"bool_value": true, "string_value": "strprefix/example"}353 `))354 if err != nil {355 t.Errorf("http.Post(%q) failed with %v; want success", url, err)356 return357 }358 defer cresp.Body.Close()359 buf, err := ioutil.ReadAll(cresp.Body)360 if err != nil {361 t.Errorf("iotuil.ReadAll(cresp.Body) failed with %v; want success", err)362 return363 }364 if got, want := cresp.StatusCode, http.StatusOK; got != want {365 t.Errorf("resp.StatusCode = %d; want %d", got, want)366 t.Logf("%s", buf)367 return368 }369 var want gw.ABitOfEverything370 if err := jsonpb.UnmarshalString(string(buf), &want); err != nil {371 t.Errorf("jsonpb.UnmarshalString(%s, &want) failed with %v; want success", buf, err)372 return373 }374 url = fmt.Sprintf("%s/%s", url, want.Uuid)375 resp, err := http.Get(url)376 if err != nil {377 t.Errorf("http.Get(%q) failed with %v; want success", url, err)378 return379 }380 defer resp.Body.Close()381 buf, err = ioutil.ReadAll(resp.Body)382 if err != nil {383 t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err)384 return385 }386 var msg gw.ABitOfEverything387 if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {388 t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)389 return390 }391 if got := msg; !reflect.DeepEqual(got, want) {392 t.Errorf("msg= %v; want %v", &got, &want)393 }394 if got, want := resp.Header.Get("Grpc-Metadata-Uuid"), want.Uuid; got != want {395 t.Errorf("Grpc-Metadata-Uuid was %s, wanted %s", got, want)396 }397}398func testABELookupNotFound(t *testing.T, port int) {399 url := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything", port)400 uuid := "not_exist"401 url = fmt.Sprintf("%s/%s", url, uuid)402 resp, err := http.Get(url)403 if err != nil {404 t.Errorf("http.Get(%q) failed with %v; want success", url, err)405 return406 }407 defer resp.Body.Close()408 buf, err := ioutil.ReadAll(resp.Body)409 if err != nil {410 t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err)411 return412 }413 if got, want := resp.StatusCode, http.StatusNotFound; got != want {414 t.Errorf("resp.StatusCode = %d; want %d", got, want)415 t.Logf("%s", buf)416 return417 }418 var msg errorBody419 if err := json.Unmarshal(buf, &msg); err != nil {420 t.Errorf("json.Unmarshal(%s, &msg) failed with %v; want success", buf, err)421 return422 }423 if got, want := msg.Code, int(codes.NotFound); got != want {424 t.Errorf("msg.Code = %d; want %d", got, want)425 return426 }427 if got, want := msg.Error, "not found"; got != want {428 t.Errorf("msg.Error = %s; want %s", got, want)429 return430 }431 if got, want := resp.Header.Get("Grpc-Metadata-Uuid"), uuid; got != want {432 t.Errorf("Grpc-Metadata-Uuid was %s, wanted %s", got, want)433 }434 if got, want := resp.Trailer.Get("Grpc-Trailer-Foo"), "foo2"; got != want {435 t.Errorf("Grpc-Trailer-Foo was %q, wanted %q", got, want)436 }437 if got, want := resp.Trailer.Get("Grpc-Trailer-Bar"), "bar2"; got != want {438 t.Errorf("Grpc-Trailer-Bar was %q, wanted %q", got, want)439 }440}441func testABEList(t *testing.T, port int) {442 url := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything", port)443 resp, err := http.Get(url)444 if err != nil {445 t.Errorf("http.Get(%q) failed with %v; want success", url, err)446 return447 }448 defer resp.Body.Close()449 dec := json.NewDecoder(resp.Body)450 var i int451 for i = 0; ; i++ {452 var item struct {453 Result json.RawMessage `json:"result"`454 Error map[string]interface{} `json:"error"`455 }456 err := dec.Decode(&item)457 if err == io.EOF {458 break459 }460 if err != nil {461 t.Errorf("dec.Decode(&item) failed with %v; want success; i = %d", err, i)462 }463 if len(item.Error) != 0 {464 t.Errorf("item.Error = %#v; want empty; i = %d", item.Error, i)465 continue466 }467 var msg gw.ABitOfEverything468 if err := jsonpb.UnmarshalString(string(item.Result), &msg); err != nil {469 t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", item.Result, err)470 }471 }472 if i <= 0 {473 t.Errorf("i == %d; want > 0", i)474 }475 value := resp.Header.Get("Grpc-Metadata-Count")476 if value == "" {477 t.Errorf("Grpc-Metadata-Count should not be empty")478 }479 count, err := strconv.Atoi(value)480 if err != nil {481 t.Errorf("failed to Atoi %q: %v", value, err)482 }483 if count <= 0 {484 t.Errorf("count == %d; want > 0", count)485 }486}487func testABEBulkEcho(t *testing.T, port int) {488 reqr, reqw := io.Pipe()489 var wg sync.WaitGroup490 var want []*sub.StringMessage491 wg.Add(1)492 go func() {493 defer wg.Done()494 defer reqw.Close()495 var m jsonpb.Marshaler496 for i := 0; i < 1000; i++ {497 msg := sub.StringMessage{Value: proto.String(fmt.Sprintf("message %d", i))}498 buf, err := m.MarshalToString(&msg)499 if err != nil {500 t.Errorf("m.Marshal(%v) failed with %v; want success", &msg, err)501 return502 }503 if _, err := fmt.Fprintln(reqw, buf); err != nil {504 t.Errorf("fmt.Fprintln(reqw, %q) failed with %v; want success", buf, err)505 return506 }507 want = append(want, &msg)508 }509 }()510 url := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything/echo", port)511 req, err := http.NewRequest("POST", url, reqr)512 if err != nil {513 t.Errorf("http.NewRequest(%q, %q, reqr) failed with %v; want success", "POST", url, err)514 return515 }516 req.Header.Set("Content-Type", "application/json")517 req.Header.Set("Transfer-Encoding", "chunked")518 resp, err := http.DefaultClient.Do(req)519 if err != nil {520 t.Errorf("http.Post(%q, %q, req) failed with %v; want success", url, "application/json", err)521 return522 }523 defer resp.Body.Close()524 if got, want := resp.StatusCode, http.StatusOK; got != want {525 t.Errorf("resp.StatusCode = %d; want %d", got, want)526 }527 var got []*sub.StringMessage528 wg.Add(1)529 go func() {530 defer wg.Done()531 dec := json.NewDecoder(resp.Body)532 for i := 0; ; i++ {533 var item struct {534 Result json.RawMessage `json:"result"`535 Error map[string]interface{} `json:"error"`536 }537 err := dec.Decode(&item)538 if err == io.EOF {539 break540 }541 if err != nil {542 t.Errorf("dec.Decode(&item) failed with %v; want success; i = %d", err, i)543 }544 if len(item.Error) != 0 {545 t.Errorf("item.Error = %#v; want empty; i = %d", item.Error, i)546 continue547 }548 var msg sub.StringMessage549 if err := jsonpb.UnmarshalString(string(item.Result), &msg); err != nil {550 t.Errorf("jsonpb.UnmarshalString(%q, &msg) failed with %v; want success", item.Result, err)551 }552 got = append(got, &msg)553 }554 }()555 wg.Wait()556 if !reflect.DeepEqual(got, want) {557 t.Errorf("got = %v; want %v", got, want)558 }559}560func testABEBulkEchoZeroLength(t *testing.T, port int) {561 url := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything/echo", port)562 req, err := http.NewRequest("POST", url, bytes.NewReader(nil))563 if err != nil {564 t.Errorf("http.NewRequest(%q, %q, bytes.NewReader(nil)) failed with %v; want success", "POST", url, err)565 return566 }567 req.Header.Set("Content-Type", "application/json")568 req.Header.Set("Transfer-Encoding", "chunked")569 resp, err := http.DefaultClient.Do(req)570 if err != nil {571 t.Errorf("http.Post(%q, %q, req) failed with %v; want success", url, "application/json", err)572 return573 }574 defer resp.Body.Close()575 if got, want := resp.StatusCode, http.StatusOK; got != want {576 t.Errorf("resp.StatusCode = %d; want %d", got, want)577 }578 dec := json.NewDecoder(resp.Body)579 var item struct {580 Result json.RawMessage `json:"result"`581 Error map[string]interface{} `json:"error"`582 }583 if err := dec.Decode(&item); err == nil {584 t.Errorf("dec.Decode(&item) succeeded; want io.EOF; item = %#v", item)585 } else if err != io.EOF {586 t.Errorf("dec.Decode(&item) failed with %v; want success", err)587 return588 }589}590func testAdditionalBindings(t *testing.T, port int) {591 for i, f := range []func() *http.Response{592 func() *http.Response {593 url := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything/echo/hello", port)594 resp, err := http.Get(url)595 if err != nil {596 t.Errorf("http.Get(%q) failed with %v; want success", url, err)597 return nil598 }599 return resp600 },601 func() *http.Response {602 url := fmt.Sprintf("http://localhost:%d/v2/example/echo", port)603 resp, err := http.Post(url, "application/json", strings.NewReader(`"hello"`))604 if err != nil {605 t.Errorf("http.Post(%q, %q, %q) failed with %v; want success", url, "application/json", `"hello"`, err)606 return nil607 }608 return resp609 },610 func() *http.Response {611 url := fmt.Sprintf("http://localhost:%d/v2/example/echo?value=hello", port)612 resp, err := http.Get(url)613 if err != nil {614 t.Errorf("http.Get(%q) failed with %v; want success", url, err)615 return nil616 }617 return resp618 },619 } {620 resp := f()621 if resp == nil {622 continue623 }624 defer resp.Body.Close()625 buf, err := ioutil.ReadAll(resp.Body)626 if err != nil {627 t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success; i=%d", err, i)628 return629 }630 if got, want := resp.StatusCode, http.StatusOK; got != want {631 t.Errorf("resp.StatusCode = %d; want %d; i=%d", got, want, i)632 t.Logf("%s", buf)633 }634 var msg sub.StringMessage635 if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {636 t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success; %d", buf, err, i)637 return638 }639 if got, want := msg.GetValue(), "hello"; got != want {640 t.Errorf("msg.GetValue() = %q; want %q", got, want)641 }642 }643}644func TestTimeout(t *testing.T) {645 url := "http://localhost:8080/v2/example/timeout"646 req, err := http.NewRequest("GET", url, nil)647 if err != nil {648 t.Errorf(`http.NewRequest("GET", %q, nil) failed with %v; want success`, url, err)649 return650 }651 req.Header.Set("Grpc-Timeout", "10m")652 resp, err := http.DefaultClient.Do(req)653 if err != nil {654 t.Errorf("http.DefaultClient.Do(%#v) failed with %v; want success", req, err)655 return656 }657 defer resp.Body.Close()658 if got, want := resp.StatusCode, http.StatusGatewayTimeout; got != want {659 t.Errorf("resp.StatusCode = %d; want %d", got, want)660 }661}662func TestErrorWithDetails(t *testing.T) {663 url := "http://localhost:8080/v2/example/errorwithdetails"664 resp, err := http.Get(url)665 if err != nil {666 t.Errorf("http.Get(%q) failed with %v; want success", url, err)667 return668 }669 defer resp.Body.Close()670 buf, err := ioutil.ReadAll(resp.Body)671 if err != nil {672 t.Fatalf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)673 }674 if got, want := resp.StatusCode, http.StatusInternalServerError; got != want {675 t.Errorf("resp.StatusCode = %d; want %d", got, want)676 }677 var msg errorBody678 if err := json.Unmarshal(buf, &msg); err != nil {679 t.Fatalf("json.Unmarshal(%s, &msg) failed with %v; want success", buf, err)680 }681 if got, want := msg.Code, int(codes.Unknown); got != want {682 t.Errorf("msg.Code = %d; want %d", got, want)683 }684 if got, want := msg.Error, "with details"; got != want {685 t.Errorf("msg.Error = %s; want %s", got, want)686 }687 if got, want := len(msg.Details), 1; got != want {688 t.Fatalf("len(msg.Details) = %q; want %q", got, want)689 }690 details, ok := msg.Details[0].(map[string]interface{})691 if got, want := ok, true; got != want {692 t.Fatalf("msg.Details[0] got type: %T, want %T", msg.Details[0], map[string]interface{}{})693 }694 typ, ok := details["@type"].(string)695 if got, want := ok, true; got != want {696 t.Fatalf("msg.Details[0][\"@type\"] got type: %T, want %T", typ, "")697 }698 if got, want := details["@type"], "type.googleapis.com/google.rpc.DebugInfo"; got != want {699 t.Errorf("msg.Details[\"@type\"] = %q; want %q", got, want)700 }701 if got, want := details["detail"], "error debug details"; got != want {702 t.Errorf("msg.Details[\"detail\"] = %q; want %q", got, want)703 }704 entries, ok := details["stack_entries"].([]interface{})705 if got, want := ok, true; got != want {706 t.Fatalf("msg.Details[0][\"stack_entries\"] got type: %T, want %T", entries, []string{})707 }708 entry, ok := entries[0].(string)709 if got, want := ok, true; got != want {710 t.Fatalf("msg.Details[0][\"stack_entries\"][0] got type: %T, want %T", entry, "")711 }712 if got, want := entries[0], "foo:1"; got != want {713 t.Errorf("msg.Details[\"stack_entries\"][0] = %q; want %q", got, want)714 }715}716func TestPostWithEmptyBody(t *testing.T) {717 url := "http://localhost:8080/v2/example/postwithemptybody/name"718 rep, err := http.Post(url, "application/json", nil)719 if err != nil {720 t.Errorf("http.Post(%q) failed with %v; want success", url, err)721 return722 }723 if rep.StatusCode != http.StatusOK {724 t.Errorf("http.Post(%q) response code is %d; want %d", url,725 rep.StatusCode, http.StatusOK)726 return727 }728}729func TestUnknownPath(t *testing.T) {730 url := "http://localhost:8080"731 resp, err := http.Post(url, "application/json", strings.NewReader("{}"))732 if err != nil {733 t.Errorf("http.Post(%q) failed with %v; want success", url, err)734 return735 }736 defer resp.Body.Close()737 buf, err := ioutil.ReadAll(resp.Body)738 if err != nil {739 t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)740 return741 }742 if got, want := resp.StatusCode, http.StatusNotFound; got != want {743 t.Errorf("resp.StatusCode = %d; want %d", got, want)744 t.Logf("%s", buf)745 }746}747func TestMethodNotAllowed(t *testing.T) {748 url := "http://localhost:8080/v1/example/echo/myid"749 resp, err := http.Get(url)750 if err != nil {751 t.Errorf("http.Post(%q) failed with %v; want success", url, err)752 return753 }754 defer resp.Body.Close()755 buf, err := ioutil.ReadAll(resp.Body)756 if err != nil {757 t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)758 return759 }760 if got, want := resp.StatusCode, http.StatusMethodNotAllowed; got != want {761 t.Errorf("resp.StatusCode = %d; want %d", got, want)762 t.Logf("%s", buf)763 }764}765func TestInvalidArgument(t *testing.T) {766 url := "http://localhost:8080/v1/example/echo/myid/not_int64"767 resp, err := http.Get(url)768 if err != nil {769 t.Errorf("http.Get(%q) failed with %v; want success", url, err)770 return771 }772 defer resp.Body.Close()773 buf, err := ioutil.ReadAll(resp.Body)774 if err != nil {775 t.Errorf("iotuil.ReadAll(resp.Body) failed with %v; want success", err)776 return777 }778 if got, want := resp.StatusCode, http.StatusBadRequest; got != want {779 t.Errorf("resp.StatusCode = %d; want %d", got, want)780 t.Logf("%s", buf)781 }782}...

Full Screen

Full Screen

shift_test.go

Source:shift_test.go Github

copy

Full Screen

...248 return x >> n249}250func TestShiftOfZero(t *testing.T) {251 if got := ofz64l64(5); got != 0 {252 t.Errorf("0<<5 == %d, want 0", got)253 }254 if got := ofz64l32(5); got != 0 {255 t.Errorf("0<<5 == %d, want 0", got)256 }257 if got := ofz64l16(5); got != 0 {258 t.Errorf("0<<5 == %d, want 0", got)259 }260 if got := ofz64l8(5); got != 0 {261 t.Errorf("0<<5 == %d, want 0", got)262 }263 if got := ofz64r64(5); got != 0 {264 t.Errorf("0>>5 == %d, want 0", got)265 }266 if got := ofz64r32(5); got != 0 {267 t.Errorf("0>>5 == %d, want 0", got)268 }269 if got := ofz64r16(5); got != 0 {270 t.Errorf("0>>5 == %d, want 0", got)271 }272 if got := ofz64r8(5); got != 0 {273 t.Errorf("0>>5 == %d, want 0", got)274 }275 if got := ofz64ur64(5); got != 0 {276 t.Errorf("0>>>5 == %d, want 0", got)277 }278 if got := ofz64ur32(5); got != 0 {279 t.Errorf("0>>>5 == %d, want 0", got)280 }281 if got := ofz64ur16(5); got != 0 {282 t.Errorf("0>>>5 == %d, want 0", got)283 }284 if got := ofz64ur8(5); got != 0 {285 t.Errorf("0>>>5 == %d, want 0", got)286 }287 if got := ofz32l64(5); got != 0 {288 t.Errorf("0<<5 == %d, want 0", got)289 }290 if got := ofz32l32(5); got != 0 {291 t.Errorf("0<<5 == %d, want 0", got)292 }293 if got := ofz32l16(5); got != 0 {294 t.Errorf("0<<5 == %d, want 0", got)295 }296 if got := ofz32l8(5); got != 0 {297 t.Errorf("0<<5 == %d, want 0", got)298 }299 if got := ofz32r64(5); got != 0 {300 t.Errorf("0>>5 == %d, want 0", got)301 }302 if got := ofz32r32(5); got != 0 {303 t.Errorf("0>>5 == %d, want 0", got)304 }305 if got := ofz32r16(5); got != 0 {306 t.Errorf("0>>5 == %d, want 0", got)307 }308 if got := ofz32r8(5); got != 0 {309 t.Errorf("0>>5 == %d, want 0", got)310 }311 if got := ofz32ur64(5); got != 0 {312 t.Errorf("0>>>5 == %d, want 0", got)313 }314 if got := ofz32ur32(5); got != 0 {315 t.Errorf("0>>>5 == %d, want 0", got)316 }317 if got := ofz32ur16(5); got != 0 {318 t.Errorf("0>>>5 == %d, want 0", got)319 }320 if got := ofz32ur8(5); got != 0 {321 t.Errorf("0>>>5 == %d, want 0", got)322 }323 if got := ofz16l64(5); got != 0 {324 t.Errorf("0<<5 == %d, want 0", got)325 }326 if got := ofz16l32(5); got != 0 {327 t.Errorf("0<<5 == %d, want 0", got)328 }329 if got := ofz16l16(5); got != 0 {330 t.Errorf("0<<5 == %d, want 0", got)331 }332 if got := ofz16l8(5); got != 0 {333 t.Errorf("0<<5 == %d, want 0", got)334 }335 if got := ofz16r64(5); got != 0 {336 t.Errorf("0>>5 == %d, want 0", got)337 }338 if got := ofz16r32(5); got != 0 {339 t.Errorf("0>>5 == %d, want 0", got)340 }341 if got := ofz16r16(5); got != 0 {342 t.Errorf("0>>5 == %d, want 0", got)343 }344 if got := ofz16r8(5); got != 0 {345 t.Errorf("0>>5 == %d, want 0", got)346 }347 if got := ofz16ur64(5); got != 0 {348 t.Errorf("0>>>5 == %d, want 0", got)349 }350 if got := ofz16ur32(5); got != 0 {351 t.Errorf("0>>>5 == %d, want 0", got)352 }353 if got := ofz16ur16(5); got != 0 {354 t.Errorf("0>>>5 == %d, want 0", got)355 }356 if got := ofz16ur8(5); got != 0 {357 t.Errorf("0>>>5 == %d, want 0", got)358 }359 if got := ofz8l64(5); got != 0 {360 t.Errorf("0<<5 == %d, want 0", got)361 }362 if got := ofz8l32(5); got != 0 {363 t.Errorf("0<<5 == %d, want 0", got)364 }365 if got := ofz8l16(5); got != 0 {366 t.Errorf("0<<5 == %d, want 0", got)367 }368 if got := ofz8l8(5); got != 0 {369 t.Errorf("0<<5 == %d, want 0", got)370 }371 if got := ofz8r64(5); got != 0 {372 t.Errorf("0>>5 == %d, want 0", got)373 }374 if got := ofz8r32(5); got != 0 {375 t.Errorf("0>>5 == %d, want 0", got)376 }377 if got := ofz8r16(5); got != 0 {378 t.Errorf("0>>5 == %d, want 0", got)379 }380 if got := ofz8r8(5); got != 0 {381 t.Errorf("0>>5 == %d, want 0", got)382 }383 if got := ofz8ur64(5); got != 0 {384 t.Errorf("0>>>5 == %d, want 0", got)385 }386 if got := ofz8ur32(5); got != 0 {387 t.Errorf("0>>>5 == %d, want 0", got)388 }389 if got := ofz8ur16(5); got != 0 {390 t.Errorf("0>>>5 == %d, want 0", got)391 }392 if got := ofz8ur8(5); got != 0 {393 t.Errorf("0>>>5 == %d, want 0", got)394 }395}396//go:noinline397func byz64l(n int64) int64 {398 return n << 0399}400//go:noinline401func byz64r(n int64) int64 {402 return n >> 0403}404//go:noinline405func byz64ur(n uint64) uint64 {406 return n >> 0407}408//go:noinline409func byz32l(n int32) int32 {410 return n << 0411}412//go:noinline413func byz32r(n int32) int32 {414 return n >> 0415}416//go:noinline417func byz32ur(n uint32) uint32 {418 return n >> 0419}420//go:noinline421func byz16l(n int16) int16 {422 return n << 0423}424//go:noinline425func byz16r(n int16) int16 {426 return n >> 0427}428//go:noinline429func byz16ur(n uint16) uint16 {430 return n >> 0431}432//go:noinline433func byz8l(n int8) int8 {434 return n << 0435}436//go:noinline437func byz8r(n int8) int8 {438 return n >> 0439}440//go:noinline441func byz8ur(n uint8) uint8 {442 return n >> 0443}444func TestShiftByZero(t *testing.T) {445 {446 var n int64 = 0x5555555555555555447 if got := byz64l(n); got != n {448 t.Errorf("%x<<0 == %x, want %x", n, got, n)449 }450 if got := byz64r(n); got != n {451 t.Errorf("%x>>0 == %x, want %x", n, got, n)452 }453 }454 {455 var n uint64 = 0xaaaaaaaaaaaaaaaa456 if got := byz64ur(n); got != n {457 t.Errorf("%x>>>0 == %x, want %x", n, got, n)458 }459 }460 {461 var n int32 = 0x55555555462 if got := byz32l(n); got != n {463 t.Errorf("%x<<0 == %x, want %x", n, got, n)464 }465 if got := byz32r(n); got != n {466 t.Errorf("%x>>0 == %x, want %x", n, got, n)467 }468 }469 {470 var n uint32 = 0xaaaaaaaa471 if got := byz32ur(n); got != n {472 t.Errorf("%x>>>0 == %x, want %x", n, got, n)473 }474 }475 {476 var n int16 = 0x5555477 if got := byz16l(n); got != n {478 t.Errorf("%x<<0 == %x, want %x", n, got, n)479 }480 if got := byz16r(n); got != n {481 t.Errorf("%x>>0 == %x, want %x", n, got, n)482 }483 }484 {485 var n uint16 = 0xaaaa486 if got := byz16ur(n); got != n {487 t.Errorf("%x>>>0 == %x, want %x", n, got, n)488 }489 }490 {491 var n int8 = 0x55492 if got := byz8l(n); got != n {493 t.Errorf("%x<<0 == %x, want %x", n, got, n)494 }495 if got := byz8r(n); got != n {496 t.Errorf("%x>>0 == %x, want %x", n, got, n)497 }498 }499 {500 var n uint8 = 0x55501 if got := byz8ur(n); got != n {502 t.Errorf("%x>>>0 == %x, want %x", n, got, n)503 }504 }505}506//go:noinline507func two64l(x int64) int64 {508 return x << 1 << 1509}510//go:noinline511func two64r(x int64) int64 {512 return x >> 1 >> 1513}514//go:noinline515func two64ur(x uint64) uint64 {516 return x >> 1 >> 1517}518//go:noinline519func two32l(x int32) int32 {520 return x << 1 << 1521}522//go:noinline523func two32r(x int32) int32 {524 return x >> 1 >> 1525}526//go:noinline527func two32ur(x uint32) uint32 {528 return x >> 1 >> 1529}530//go:noinline531func two16l(x int16) int16 {532 return x << 1 << 1533}534//go:noinline535func two16r(x int16) int16 {536 return x >> 1 >> 1537}538//go:noinline539func two16ur(x uint16) uint16 {540 return x >> 1 >> 1541}542//go:noinline543func two8l(x int8) int8 {544 return x << 1 << 1545}546//go:noinline547func two8r(x int8) int8 {548 return x >> 1 >> 1549}550//go:noinline551func two8ur(x uint8) uint8 {552 return x >> 1 >> 1553}554func TestShiftCombine(t *testing.T) {555 if got, want := two64l(4), int64(16); want != got {556 t.Errorf("4<<1<<1 == %d, want %d", got, want)557 }558 if got, want := two64r(64), int64(16); want != got {559 t.Errorf("64>>1>>1 == %d, want %d", got, want)560 }561 if got, want := two64ur(64), uint64(16); want != got {562 t.Errorf("64>>1>>1 == %d, want %d", got, want)563 }564 if got, want := two32l(4), int32(16); want != got {565 t.Errorf("4<<1<<1 == %d, want %d", got, want)566 }567 if got, want := two32r(64), int32(16); want != got {568 t.Errorf("64>>1>>1 == %d, want %d", got, want)569 }570 if got, want := two32ur(64), uint32(16); want != got {571 t.Errorf("64>>1>>1 == %d, want %d", got, want)572 }573 if got, want := two16l(4), int16(16); want != got {574 t.Errorf("4<<1<<1 == %d, want %d", got, want)575 }576 if got, want := two16r(64), int16(16); want != got {577 t.Errorf("64>>1>>1 == %d, want %d", got, want)578 }579 if got, want := two16ur(64), uint16(16); want != got {580 t.Errorf("64>>1>>1 == %d, want %d", got, want)581 }582 if got, want := two8l(4), int8(16); want != got {583 t.Errorf("4<<1<<1 == %d, want %d", got, want)584 }585 if got, want := two8r(64), int8(16); want != got {586 t.Errorf("64>>1>>1 == %d, want %d", got, want)587 }588 if got, want := two8ur(64), uint8(16); want != got {589 t.Errorf("64>>1>>1 == %d, want %d", got, want)590 }591}592//go:noinline593func three64l(x int64) int64 {594 return x << 3 >> 1 << 2595}596//go:noinline597func three64ul(x uint64) uint64 {598 return x << 3 >> 1 << 2599}600//go:noinline601func three64r(x int64) int64 {602 return x >> 3 << 1 >> 2603}604//go:noinline605func three64ur(x uint64) uint64 {606 return x >> 3 << 1 >> 2607}608//go:noinline609func three32l(x int32) int32 {610 return x << 3 >> 1 << 2611}612//go:noinline613func three32ul(x uint32) uint32 {614 return x << 3 >> 1 << 2615}616//go:noinline617func three32r(x int32) int32 {618 return x >> 3 << 1 >> 2619}620//go:noinline621func three32ur(x uint32) uint32 {622 return x >> 3 << 1 >> 2623}624//go:noinline625func three16l(x int16) int16 {626 return x << 3 >> 1 << 2627}628//go:noinline629func three16ul(x uint16) uint16 {630 return x << 3 >> 1 << 2631}632//go:noinline633func three16r(x int16) int16 {634 return x >> 3 << 1 >> 2635}636//go:noinline637func three16ur(x uint16) uint16 {638 return x >> 3 << 1 >> 2639}640//go:noinline641func three8l(x int8) int8 {642 return x << 3 >> 1 << 2643}644//go:noinline645func three8ul(x uint8) uint8 {646 return x << 3 >> 1 << 2647}648//go:noinline649func three8r(x int8) int8 {650 return x >> 3 << 1 >> 2651}652//go:noinline653func three8ur(x uint8) uint8 {654 return x >> 3 << 1 >> 2655}656func TestShiftCombine3(t *testing.T) {657 if got, want := three64l(4), int64(64); want != got {658 t.Errorf("4<<1<<1 == %d, want %d", got, want)659 }660 if got, want := three64ul(4), uint64(64); want != got {661 t.Errorf("4<<1<<1 == %d, want %d", got, want)662 }663 if got, want := three64r(64), int64(4); want != got {664 t.Errorf("64>>1>>1 == %d, want %d", got, want)665 }666 if got, want := three64ur(64), uint64(4); want != got {667 t.Errorf("64>>1>>1 == %d, want %d", got, want)668 }669 if got, want := three32l(4), int32(64); want != got {670 t.Errorf("4<<1<<1 == %d, want %d", got, want)671 }672 if got, want := three32ul(4), uint32(64); want != got {673 t.Errorf("4<<1<<1 == %d, want %d", got, want)674 }675 if got, want := three32r(64), int32(4); want != got {676 t.Errorf("64>>1>>1 == %d, want %d", got, want)677 }678 if got, want := three32ur(64), uint32(4); want != got {679 t.Errorf("64>>1>>1 == %d, want %d", got, want)680 }681 if got, want := three16l(4), int16(64); want != got {682 t.Errorf("4<<1<<1 == %d, want %d", got, want)683 }684 if got, want := three16ul(4), uint16(64); want != got {685 t.Errorf("4<<1<<1 == %d, want %d", got, want)686 }687 if got, want := three16r(64), int16(4); want != got {688 t.Errorf("64>>1>>1 == %d, want %d", got, want)689 }690 if got, want := three16ur(64), uint16(4); want != got {691 t.Errorf("64>>1>>1 == %d, want %d", got, want)692 }693 if got, want := three8l(4), int8(64); want != got {694 t.Errorf("4<<1<<1 == %d, want %d", got, want)695 }696 if got, want := three8ul(4), uint8(64); want != got {697 t.Errorf("4<<1<<1 == %d, want %d", got, want)698 }699 if got, want := three8r(64), int8(4); want != got {700 t.Errorf("64>>1>>1 == %d, want %d", got, want)701 }702 if got, want := three8ur(64), uint8(4); want != got {703 t.Errorf("64>>1>>1 == %d, want %d", got, want)704 }705}706var (707 one64 int64 = 1708 one64u uint64 = 1709 one32 int32 = 1710 one32u uint32 = 1711 one16 int16 = 1712 one16u uint16 = 1713 one8 int8 = 1714 one8u uint8 = 1715)716func TestShiftLargeCombine(t *testing.T) {717 var N uint64 = 0x8000000000000000718 if one64<<N<<N == 1 {719 t.Errorf("shift overflow mishandled")720 }721 if one64>>N>>N == 1 {722 t.Errorf("shift overflow mishandled")723 }724 if one64u>>N>>N == 1 {725 t.Errorf("shift overflow mishandled")726 }727 if one32<<N<<N == 1 {728 t.Errorf("shift overflow mishandled")729 }730 if one32>>N>>N == 1 {731 t.Errorf("shift overflow mishandled")732 }733 if one32u>>N>>N == 1 {734 t.Errorf("shift overflow mishandled")735 }736 if one16<<N<<N == 1 {737 t.Errorf("shift overflow mishandled")738 }739 if one16>>N>>N == 1 {740 t.Errorf("shift overflow mishandled")741 }742 if one16u>>N>>N == 1 {743 t.Errorf("shift overflow mishandled")744 }745 if one8<<N<<N == 1 {746 t.Errorf("shift overflow mishandled")747 }748 if one8>>N>>N == 1 {749 t.Errorf("shift overflow mishandled")750 }751 if one8u>>N>>N == 1 {752 t.Errorf("shift overflow mishandled")753 }754}755func TestShiftLargeCombine3(t *testing.T) {756 var N uint64 = 0x8000000000000001757 if one64<<N>>2<<N == 1 {758 t.Errorf("shift overflow mishandled")759 }760 if one64u<<N>>2<<N == 1 {761 t.Errorf("shift overflow mishandled")762 }763 if one64>>N<<2>>N == 1 {764 t.Errorf("shift overflow mishandled")765 }766 if one64u>>N<<2>>N == 1 {767 t.Errorf("shift overflow mishandled")768 }769 if one32<<N>>2<<N == 1 {770 t.Errorf("shift overflow mishandled")771 }772 if one32u<<N>>2<<N == 1 {773 t.Errorf("shift overflow mishandled")774 }775 if one32>>N<<2>>N == 1 {776 t.Errorf("shift overflow mishandled")777 }778 if one32u>>N<<2>>N == 1 {779 t.Errorf("shift overflow mishandled")780 }781 if one16<<N>>2<<N == 1 {782 t.Errorf("shift overflow mishandled")783 }784 if one16u<<N>>2<<N == 1 {785 t.Errorf("shift overflow mishandled")786 }787 if one16>>N<<2>>N == 1 {788 t.Errorf("shift overflow mishandled")789 }790 if one16u>>N<<2>>N == 1 {791 t.Errorf("shift overflow mishandled")792 }793 if one8<<N>>2<<N == 1 {794 t.Errorf("shift overflow mishandled")795 }796 if one8u<<N>>2<<N == 1 {797 t.Errorf("shift overflow mishandled")798 }799 if one8>>N<<2>>N == 1 {800 t.Errorf("shift overflow mishandled")801 }802 if one8u>>N<<2>>N == 1 {803 t.Errorf("shift overflow mishandled")804 }805}806func TestShiftGeneric(t *testing.T) {807 for _, test := range [...]struct {808 valueWidth int809 signed bool810 shiftWidth int811 left bool812 f interface{}813 }{814 {64, true, 64, true, func(n int64, s uint64) int64 { return n << s }},815 {64, true, 64, false, func(n int64, s uint64) int64 { return n >> s }},816 {64, false, 64, false, func(n uint64, s uint64) uint64 { return n >> s }},817 {64, true, 32, true, func(n int64, s uint32) int64 { return n << s }},818 {64, true, 32, false, func(n int64, s uint32) int64 { return n >> s }},819 {64, false, 32, false, func(n uint64, s uint32) uint64 { return n >> s }},820 {64, true, 16, true, func(n int64, s uint16) int64 { return n << s }},821 {64, true, 16, false, func(n int64, s uint16) int64 { return n >> s }},822 {64, false, 16, false, func(n uint64, s uint16) uint64 { return n >> s }},823 {64, true, 8, true, func(n int64, s uint8) int64 { return n << s }},824 {64, true, 8, false, func(n int64, s uint8) int64 { return n >> s }},825 {64, false, 8, false, func(n uint64, s uint8) uint64 { return n >> s }},826 {32, true, 64, true, func(n int32, s uint64) int32 { return n << s }},827 {32, true, 64, false, func(n int32, s uint64) int32 { return n >> s }},828 {32, false, 64, false, func(n uint32, s uint64) uint32 { return n >> s }},829 {32, true, 32, true, func(n int32, s uint32) int32 { return n << s }},830 {32, true, 32, false, func(n int32, s uint32) int32 { return n >> s }},831 {32, false, 32, false, func(n uint32, s uint32) uint32 { return n >> s }},832 {32, true, 16, true, func(n int32, s uint16) int32 { return n << s }},833 {32, true, 16, false, func(n int32, s uint16) int32 { return n >> s }},834 {32, false, 16, false, func(n uint32, s uint16) uint32 { return n >> s }},835 {32, true, 8, true, func(n int32, s uint8) int32 { return n << s }},836 {32, true, 8, false, func(n int32, s uint8) int32 { return n >> s }},837 {32, false, 8, false, func(n uint32, s uint8) uint32 { return n >> s }},838 {16, true, 64, true, func(n int16, s uint64) int16 { return n << s }},839 {16, true, 64, false, func(n int16, s uint64) int16 { return n >> s }},840 {16, false, 64, false, func(n uint16, s uint64) uint16 { return n >> s }},841 {16, true, 32, true, func(n int16, s uint32) int16 { return n << s }},842 {16, true, 32, false, func(n int16, s uint32) int16 { return n >> s }},843 {16, false, 32, false, func(n uint16, s uint32) uint16 { return n >> s }},844 {16, true, 16, true, func(n int16, s uint16) int16 { return n << s }},845 {16, true, 16, false, func(n int16, s uint16) int16 { return n >> s }},846 {16, false, 16, false, func(n uint16, s uint16) uint16 { return n >> s }},847 {16, true, 8, true, func(n int16, s uint8) int16 { return n << s }},848 {16, true, 8, false, func(n int16, s uint8) int16 { return n >> s }},849 {16, false, 8, false, func(n uint16, s uint8) uint16 { return n >> s }},850 {8, true, 64, true, func(n int8, s uint64) int8 { return n << s }},851 {8, true, 64, false, func(n int8, s uint64) int8 { return n >> s }},852 {8, false, 64, false, func(n uint8, s uint64) uint8 { return n >> s }},853 {8, true, 32, true, func(n int8, s uint32) int8 { return n << s }},854 {8, true, 32, false, func(n int8, s uint32) int8 { return n >> s }},855 {8, false, 32, false, func(n uint8, s uint32) uint8 { return n >> s }},856 {8, true, 16, true, func(n int8, s uint16) int8 { return n << s }},857 {8, true, 16, false, func(n int8, s uint16) int8 { return n >> s }},858 {8, false, 16, false, func(n uint8, s uint16) uint8 { return n >> s }},859 {8, true, 8, true, func(n int8, s uint8) int8 { return n << s }},860 {8, true, 8, false, func(n int8, s uint8) int8 { return n >> s }},861 {8, false, 8, false, func(n uint8, s uint8) uint8 { return n >> s }},862 } {863 fv := reflect.ValueOf(test.f)864 var args [2]reflect.Value865 for i := 0; i < test.valueWidth; i++ {866 // Build value to be shifted.867 var n int64 = 1868 for j := 0; j < i; j++ {869 n <<= 1870 }871 args[0] = reflect.ValueOf(n).Convert(fv.Type().In(0))872 for s := 0; s <= test.shiftWidth; s++ {873 args[1] = reflect.ValueOf(s).Convert(fv.Type().In(1))874 // Compute desired result. We're testing variable shifts875 // assuming constant shifts are correct.876 r := n877 var op string878 switch {879 case test.left:880 op = "<<"881 for j := 0; j < s; j++ {882 r <<= 1883 }884 switch test.valueWidth {885 case 32:886 r = int64(int32(r))887 case 16:888 r = int64(int16(r))889 case 8:890 r = int64(int8(r))891 }892 case test.signed:893 op = ">>"894 switch test.valueWidth {895 case 32:896 r = int64(int32(r))897 case 16:898 r = int64(int16(r))899 case 8:900 r = int64(int8(r))901 }902 for j := 0; j < s; j++ {903 r >>= 1904 }905 default:906 op = ">>>"907 for j := 0; j < s; j++ {908 r = int64(uint64(r) >> 1)909 }910 }911 // Call function.912 res := fv.Call(args[:])[0].Convert(reflect.ValueOf(r).Type())913 if res.Int() != r {914 t.Errorf("%s%dx%d(%x,%x)=%x, want %x", op, test.valueWidth, test.shiftWidth, n, s, res.Int(), r)915 }916 }917 }918 }919}...

Full Screen

Full Screen

string_test.go

Source:string_test.go Github

copy

Full Screen

...5func TestParseStrInt64(t *testing.T) {6 value := "10"7 got, err := ParseStrInt64(value)8 if err != nil {9 t.Errorf("failed, errors:%+v", err)10 }11 if got != 10 {12 t.Errorf("failed, got=<%+v>, expect=<%+v>", got, 10)13 }14}15func TestParseStrFloat64(t *testing.T) {16 value := "10.10"17 got, err := ParseStrFloat64(value)18 if err != nil {19 t.Errorf("failed, errors:%+v", err)20 }21 if got != 10.10 {22 t.Errorf("failed, got=<%+v>, expect=<%+v>", got, 10.10)23 }24}25func TestParseStrInt(t *testing.T) {26 value := "10"27 got, err := ParseStrInt(value)28 if err != nil {29 t.Errorf("failed, errors:%+v", err)30 }31 if got != 10 {32 t.Errorf("failed, got=<%+v>, expect=<%+v>", got, 10)33 }34}35func TestParseStrIntSlice(t *testing.T) {36 value := []string{"10", "11", "12"}37 got, err := ParseStrIntSlice(value)38 if err != nil {39 t.Errorf("failed, errors:%+v", err)40 }41 if len(got) != len(value) {42 t.Errorf("failed, got=<%d>, expect=<%d>", len(got), len(value))43 return44 }45 if got[0] != 10 {46 t.Errorf("failed, got=<%+v>, expect=<%+v>", got[0], 10)47 return48 }49 if got[1] != 11 {50 t.Errorf("failed, got=<%+v>, expect=<%+v>", got[1], 11)51 return52 }53 if got[2] != 12 {54 t.Errorf("failed, got=<%+v>, expect=<%+v>", got[1], 11)55 return56 }57}58func TestParseStrInt64Slice(t *testing.T) {59 value := []string{"10", "11", "12"}60 got, err := ParseStrInt64Slice(value)61 if err != nil {62 t.Errorf("failed, errors:%+v", err)63 }64 if len(got) != len(value) {65 t.Errorf("failed, got=<%d>, expect=<%d>", len(got), len(value))66 return67 }68 if got[0] != 10 {69 t.Errorf("failed, got=<%+v>, expect=<%+v>", got[0], 10)70 return71 }72 if got[1] != 11 {73 t.Errorf("failed, got=<%+v>, expect=<%+v>", got[1], 11)74 return75 }76 if got[2] != 12 {77 t.Errorf("failed, got=<%+v>, expect=<%+v>", got[1], 11)78 return79 }80}81func TestParseStrUInt64Slice(t *testing.T) {82 value := []string{"10", "11", "12"}83 got, err := ParseStrUInt64Slice(value)84 if err != nil {85 t.Errorf("failed, errors:%+v", err)86 }87 if len(got) != len(value) {88 t.Errorf("failed, got=<%d>, expect=<%d>", len(got), len(value))89 return90 }91 if got[0] != 10 {92 t.Errorf("failed, got=<%+v>, expect=<%+v>", got[0], 10)93 return94 }95 if got[1] != 11 {96 t.Errorf("failed, got=<%+v>, expect=<%+v>", got[1], 11)97 return98 }99 if got[2] != 12 {100 t.Errorf("failed, got=<%+v>, expect=<%+v>", got[1], 11)101 return102 }103}...

Full Screen

Full Screen

Errorf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 _, err := os.Open("no-file.txt")4 if err != nil {5 fmt.Println("err happened", err)6 }7}8main.main()9fmt.Println("err happened", err)10fmt.Println("err happened", err.Error())11fmt.Printf("err happened %v", err)12log.Println("err happened", err)13log.Fatalln(err)14panic(err)

Full Screen

Full Screen

Errorf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err := errors.New("error message")4 fmt.Println(err)5}6import (7func main() {8 err := errors.New("error message")9 fmt.Println(err.Error())10}11import (12func main() {13 err := errors.New("error message")14 fmt.Println(err.Error())15 fmt.Println(err)16}17import (18func main() {19 err := errors.New("error message")20 fmt.Println(err.Error())21 fmt.Println(err)22 fmt.Println(err)23}24import (25func main() {26 err := errors.New("error message")27 fmt.Println(err.Error())28 fmt.Println(err)29 fmt.Println(err)30 fmt.Println(err)31}32import (33func main() {34 err := errors.New("error message")35 fmt.Println(err.Error())36 fmt.Println(err)37 fmt.Println(err)38 fmt.Println(err)39 fmt.Println(err)40}41import (42func main() {43 err := errors.New("error message")44 fmt.Println(err.Error())45 fmt.Println(err)46 fmt.Println(err)47 fmt.Println(err)48 fmt.Println(err)49 fmt.Println(err)50}51import (52func main() {53 err := errors.New("error message")54 fmt.Println(err.Error())55 fmt.Println(err)56 fmt.Println(err)57 fmt.Println(err)58 fmt.Println(err)59 fmt.Println(err)

Full Screen

Full Screen

Errorf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 _, err := fmt.Println("Hello World")4 if err != nil {5 log.Fatalf("Error in printing: %v", err)6 }7}82020/05/13 13:31:21 Error in printing: %!v(PANIC=String method: runtime error: invalid memory address or nil pointer dereference)9import (10func main() {11 _, err := fmt.Println("Hello World")12 if err != nil {13 log.Println(err)14 }15}16import (17func main() {18 _, err := fmt.Println("Hello World")19 if err != nil {20 log.Panicln(err)21 }22}23log.Panicln(0xc00003ff60, 0x1, 0x1)24main.main()

Full Screen

Full Screen

Errorf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 _, err := fmt.Println("Hello")4 if err != nil {5 log.Fatalf("Error: %v", err)6 }7}8import (9func main() {10 _, err := fmt.Println("Hello")11 if err != nil {12 log.Fatalf("Error: %v", err)13 }14}15import (16func main() {17 _, err := fmt.Println("Hello")18 if err != nil {19 log.Fatalf("Error: %v", err)20 }21}22import (23func main() {24 _, err := fmt.Println("Hello")25 if err != nil {26 log.Fatalf("Error: %v", err)27 }28}29import (30func main() {31 _, err := fmt.Println("Hello")32 if err != nil {33 log.Fatalf("Error: %v", err)34 }35}36import (37func main() {38 _, err := fmt.Println("Hello")39 if err != nil {40 log.Fatalf("Error: %v", err)41 }42}

Full Screen

Full Screen

Errorf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err := fmt.Errorf("This is an error")4 log.Printf("Error: %v", err)5}6Recommended Posts: Go | Error() method in Go7Go | Error() method in Go8Go | Panic() method in Go9Go | Recover() method in Go10Go | New() method in Go11Go | Println() method in Go12Go | Printf() method in Go13Go | Print() method in Go14Go | Fatal() method in Go15Go | Fatalf() method in Go16Go | Fataln() method in Go17Go | Error() method in Go18Go | Error() method in Go19Go | Panic() method in Go20Go | Recover() method in Go21Go | New() method in Go22Go | Println() method in Go23Go | Printf() method in Go24Go | Print() method in Go25Go | Fatal() method in Go26Go | Fatalf() method in Go27Go | Fataln() method in Go28Go | Error() method in Go29Go | Error() method in Go30Go | Panic() method in Go31Go | Recover() method in Go32Go | New() method in Go33Go | Println() method in Go34Go | Printf() method in Go35Go | Print() method in Go36Go | Fatal() method in Go37Go | Fatalf() method in Go38Go | Fataln() method in Go39Go | Error() method in Go40Go | Error() method in Go41Go | Panic() method in Go42Go | Recover() method in Go43Go | New() method in Go44Go | Println() method in Go45Go | Printf() method in Go46Go | Print() method in Go47Go | Fatal() method in Go48Go | Fatalf() method in Go49Go | Fataln() method in Go50Go | Error() method in Go51Go | Error() method in Go52Go | Panic() method in Go53Go | Recover() method in Go54Go | New() method in Go55Go | Println() method in Go

Full Screen

Full Screen

Errorf

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main(){3 err = fmt.Errorf("error")4 fmt.Println(err)5}6import "fmt"7func main(){8 err = fmt.Errorf("error: %s", "Error")9 fmt.Println(err)10}

Full Screen

Full Screen

Errorf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Errorf("Errorf method")4}5import (6func main() {7 fmt.Errorf("Errorf method")8}9import (10func main() {11 fmt.Errorf("Errorf method")12}13import (14func main() {15 fmt.Errorf("Errorf method")16}17import (18func main() {19 fmt.Errorf("Errorf method")20}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful