How to use Parallel method of got Package

Best Got code snippet using got.Parallel

crash_cgo_test.go

Source:crash_cgo_test.go Github

copy

Full Screen

...14 "testing"15 "time"16)17func TestCgoCrashHandler(t *testing.T) {18 t.Parallel()19 testCrashHandler(t, true)20}21func TestCgoSignalDeadlock(t *testing.T) {22 // Don't call t.Parallel, since too much work going on at the23 // same time can cause the testprogcgo code to overrun its24 // timeouts (issue #18598).25 if testing.Short() && runtime.GOOS == "windows" {26 t.Skip("Skipping in short mode") // takes up to 64 seconds27 }28 got := runTestProg(t, "testprogcgo", "CgoSignalDeadlock")29 want := "OK\n"30 if got != want {31 t.Fatalf("expected %q, but got:\n%s", want, got)32 }33}34func TestCgoTraceback(t *testing.T) {35 t.Parallel()36 got := runTestProg(t, "testprogcgo", "CgoTraceback")37 want := "OK\n"38 if got != want {39 t.Fatalf("expected %q, but got:\n%s", want, got)40 }41}42func TestCgoCallbackGC(t *testing.T) {43 t.Parallel()44 switch runtime.GOOS {45 case "plan9", "windows":46 t.Skipf("no pthreads on %s", runtime.GOOS)47 }48 if testing.Short() {49 switch {50 case runtime.GOOS == "dragonfly":51 t.Skip("see golang.org/issue/11990")52 case runtime.GOOS == "linux" && runtime.GOARCH == "arm":53 t.Skip("too slow for arm builders")54 case runtime.GOOS == "linux" && (runtime.GOARCH == "mips64" || runtime.GOARCH == "mips64le"):55 t.Skip("too slow for mips64x builders")56 }57 }58 if testenv.Builder() == "darwin-amd64-10_14" {59 // TODO(#23011): When the 10.14 builders are gone, remove this skip.60 t.Skip("skipping due to platform bug on macOS 10.14; see https://golang.org/issue/43926")61 }62 got := runTestProg(t, "testprogcgo", "CgoCallbackGC")63 want := "OK\n"64 if got != want {65 t.Fatalf("expected %q, but got:\n%s", want, got)66 }67}68func TestCgoExternalThreadPanic(t *testing.T) {69 t.Parallel()70 if runtime.GOOS == "plan9" {71 t.Skipf("no pthreads on %s", runtime.GOOS)72 }73 got := runTestProg(t, "testprogcgo", "CgoExternalThreadPanic")74 want := "panic: BOOM"75 if !strings.Contains(got, want) {76 t.Fatalf("want failure containing %q. output:\n%s\n", want, got)77 }78}79func TestCgoExternalThreadSIGPROF(t *testing.T) {80 t.Parallel()81 // issue 9456.82 switch runtime.GOOS {83 case "plan9", "windows":84 t.Skipf("no pthreads on %s", runtime.GOOS)85 }86 got := runTestProg(t, "testprogcgo", "CgoExternalThreadSIGPROF", "GO_START_SIGPROF_THREAD=1")87 if want := "OK\n"; got != want {88 t.Fatalf("expected %q, but got:\n%s", want, got)89 }90}91func TestCgoExternalThreadSignal(t *testing.T) {92 t.Parallel()93 // issue 1013994 switch runtime.GOOS {95 case "plan9", "windows":96 t.Skipf("no pthreads on %s", runtime.GOOS)97 }98 got := runTestProg(t, "testprogcgo", "CgoExternalThreadSignal")99 if want := "OK\n"; got != want {100 t.Fatalf("expected %q, but got:\n%s", want, got)101 }102}103func TestCgoDLLImports(t *testing.T) {104 // test issue 9356105 if runtime.GOOS != "windows" {106 t.Skip("skipping windows specific test")107 }108 got := runTestProg(t, "testprogcgo", "CgoDLLImportsMain")109 want := "OK\n"110 if got != want {111 t.Fatalf("expected %q, but got %v", want, got)112 }113}114func TestCgoExecSignalMask(t *testing.T) {115 t.Parallel()116 // Test issue 13164.117 switch runtime.GOOS {118 case "windows", "plan9":119 t.Skipf("skipping signal mask test on %s", runtime.GOOS)120 }121 got := runTestProg(t, "testprogcgo", "CgoExecSignalMask", "GOTRACEBACK=system")122 want := "OK\n"123 if got != want {124 t.Errorf("expected %q, got %v", want, got)125 }126}127func TestEnsureDropM(t *testing.T) {128 t.Parallel()129 // Test for issue 13881.130 switch runtime.GOOS {131 case "windows", "plan9":132 t.Skipf("skipping dropm test on %s", runtime.GOOS)133 }134 got := runTestProg(t, "testprogcgo", "EnsureDropM")135 want := "OK\n"136 if got != want {137 t.Errorf("expected %q, got %v", want, got)138 }139}140// Test for issue 14387.141// Test that the program that doesn't need any cgo pointer checking142// takes about the same amount of time with it as without it.143func TestCgoCheckBytes(t *testing.T) {144 t.Parallel()145 // Make sure we don't count the build time as part of the run time.146 testenv.MustHaveGoBuild(t)147 exe, err := buildTestProg(t, "testprogcgo")148 if err != nil {149 t.Fatal(err)150 }151 // Try it 10 times to avoid flakiness.152 const tries = 10153 var tot1, tot2 time.Duration154 for i := 0; i < tries; i++ {155 cmd := testenv.CleanCmdEnv(exec.Command(exe, "CgoCheckBytes"))156 cmd.Env = append(cmd.Env, "GODEBUG=cgocheck=0", fmt.Sprintf("GO_CGOCHECKBYTES_TRY=%d", i))157 start := time.Now()158 cmd.Run()159 d1 := time.Since(start)160 cmd = testenv.CleanCmdEnv(exec.Command(exe, "CgoCheckBytes"))161 cmd.Env = append(cmd.Env, fmt.Sprintf("GO_CGOCHECKBYTES_TRY=%d", i))162 start = time.Now()163 cmd.Run()164 d2 := time.Since(start)165 if d1*20 > d2 {166 // The slow version (d2) was less than 20 times167 // slower than the fast version (d1), so OK.168 return169 }170 tot1 += d1171 tot2 += d2172 }173 t.Errorf("cgo check too slow: got %v, expected at most %v", tot2/tries, (tot1/tries)*20)174}175func TestCgoPanicDeadlock(t *testing.T) {176 t.Parallel()177 // test issue 14432178 got := runTestProg(t, "testprogcgo", "CgoPanicDeadlock")179 want := "panic: cgo error\n\n"180 if !strings.HasPrefix(got, want) {181 t.Fatalf("output does not start with %q:\n%s", want, got)182 }183}184func TestCgoCCodeSIGPROF(t *testing.T) {185 t.Parallel()186 got := runTestProg(t, "testprogcgo", "CgoCCodeSIGPROF")187 want := "OK\n"188 if got != want {189 t.Errorf("expected %q got %v", want, got)190 }191}192func TestCgoPprofCallback(t *testing.T) {193 t.Parallel()194 switch runtime.GOOS {195 case "windows", "plan9":196 t.Skipf("skipping cgo pprof callback test on %s", runtime.GOOS)197 }198 got := runTestProg(t, "testprogcgo", "CgoPprofCallback")199 want := "OK\n"200 if got != want {201 t.Errorf("expected %q got %v", want, got)202 }203}204func TestCgoCrashTraceback(t *testing.T) {205 t.Parallel()206 switch platform := runtime.GOOS + "/" + runtime.GOARCH; platform {207 case "darwin/amd64":208 case "linux/amd64":209 case "linux/ppc64le":210 default:211 t.Skipf("not yet supported on %s", platform)212 }213 got := runTestProg(t, "testprogcgo", "CrashTraceback")214 for i := 1; i <= 3; i++ {215 if !strings.Contains(got, fmt.Sprintf("cgo symbolizer:%d", i)) {216 t.Errorf("missing cgo symbolizer:%d", i)217 }218 }219}220func TestCgoCrashTracebackGo(t *testing.T) {221 t.Parallel()222 switch platform := runtime.GOOS + "/" + runtime.GOARCH; platform {223 case "darwin/amd64":224 case "linux/amd64":225 case "linux/ppc64le":226 default:227 t.Skipf("not yet supported on %s", platform)228 }229 got := runTestProg(t, "testprogcgo", "CrashTracebackGo")230 for i := 1; i <= 3; i++ {231 want := fmt.Sprintf("main.h%d", i)232 if !strings.Contains(got, want) {233 t.Errorf("missing %s", want)234 }235 }236}237func TestCgoTracebackContext(t *testing.T) {238 t.Parallel()239 got := runTestProg(t, "testprogcgo", "TracebackContext")240 want := "OK\n"241 if got != want {242 t.Errorf("expected %q got %v", want, got)243 }244}245func TestCgoTracebackContextPreemption(t *testing.T) {246 t.Parallel()247 got := runTestProg(t, "testprogcgo", "TracebackContextPreemption")248 want := "OK\n"249 if got != want {250 t.Errorf("expected %q got %v", want, got)251 }252}253func testCgoPprof(t *testing.T, buildArg, runArg, top, bottom string) {254 t.Parallel()255 if runtime.GOOS != "linux" || (runtime.GOARCH != "amd64" && runtime.GOARCH != "ppc64le") {256 t.Skipf("not yet supported on %s/%s", runtime.GOOS, runtime.GOARCH)257 }258 testenv.MustHaveGoRun(t)259 exe, err := buildTestProg(t, "testprogcgo", buildArg)260 if err != nil {261 t.Fatal(err)262 }263 cmd := testenv.CleanCmdEnv(exec.Command(exe, runArg))264 got, err := cmd.CombinedOutput()265 if err != nil {266 if testenv.Builder() == "linux-amd64-alpine" {267 // See Issue 18243 and Issue 19938.268 t.Skipf("Skipping failing test on Alpine (golang.org/issue/18243). Ignoring error: %v", err)269 }270 t.Fatalf("%s\n\n%v", got, err)271 }272 fn := strings.TrimSpace(string(got))273 defer os.Remove(fn)274 for try := 0; try < 2; try++ {275 cmd := testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), "tool", "pprof", "-tagignore=ignore", "-traces"))276 // Check that pprof works both with and without explicit executable on command line.277 if try == 0 {278 cmd.Args = append(cmd.Args, exe, fn)279 } else {280 cmd.Args = append(cmd.Args, fn)281 }282 found := false283 for i, e := range cmd.Env {284 if strings.HasPrefix(e, "PPROF_TMPDIR=") {285 cmd.Env[i] = "PPROF_TMPDIR=" + os.TempDir()286 found = true287 break288 }289 }290 if !found {291 cmd.Env = append(cmd.Env, "PPROF_TMPDIR="+os.TempDir())292 }293 out, err := cmd.CombinedOutput()294 t.Logf("%s:\n%s", cmd.Args, out)295 if err != nil {296 t.Error(err)297 continue298 }299 trace := findTrace(string(out), top)300 if len(trace) == 0 {301 t.Errorf("%s traceback missing.", top)302 continue303 }304 if trace[len(trace)-1] != bottom {305 t.Errorf("invalid traceback origin: got=%v; want=[%s ... %s]", trace, top, bottom)306 }307 }308}309func TestCgoPprof(t *testing.T) {310 testCgoPprof(t, "", "CgoPprof", "cpuHog", "runtime.main")311}312func TestCgoPprofPIE(t *testing.T) {313 testCgoPprof(t, "-buildmode=pie", "CgoPprof", "cpuHog", "runtime.main")314}315func TestCgoPprofThread(t *testing.T) {316 testCgoPprof(t, "", "CgoPprofThread", "cpuHogThread", "cpuHogThread2")317}318func TestCgoPprofThreadNoTraceback(t *testing.T) {319 testCgoPprof(t, "", "CgoPprofThreadNoTraceback", "cpuHogThread", "runtime._ExternalCode")320}321func TestRaceProf(t *testing.T) {322 if (runtime.GOOS != "linux" && runtime.GOOS != "freebsd") || runtime.GOARCH != "amd64" {323 t.Skipf("not yet supported on %s/%s", runtime.GOOS, runtime.GOARCH)324 }325 testenv.MustHaveGoRun(t)326 // This test requires building various packages with -race, so327 // it's somewhat slow.328 if testing.Short() {329 t.Skip("skipping test in -short mode")330 }331 exe, err := buildTestProg(t, "testprogcgo", "-race")332 if err != nil {333 t.Fatal(err)334 }335 got, err := testenv.CleanCmdEnv(exec.Command(exe, "CgoRaceprof")).CombinedOutput()336 if err != nil {337 t.Fatal(err)338 }339 want := "OK\n"340 if string(got) != want {341 t.Errorf("expected %q got %s", want, got)342 }343}344func TestRaceSignal(t *testing.T) {345 t.Parallel()346 if (runtime.GOOS != "linux" && runtime.GOOS != "freebsd") || runtime.GOARCH != "amd64" {347 t.Skipf("not yet supported on %s/%s", runtime.GOOS, runtime.GOARCH)348 }349 testenv.MustHaveGoRun(t)350 // This test requires building various packages with -race, so351 // it's somewhat slow.352 if testing.Short() {353 t.Skip("skipping test in -short mode")354 }355 exe, err := buildTestProg(t, "testprogcgo", "-race")356 if err != nil {357 t.Fatal(err)358 }359 got, err := testenv.CleanCmdEnv(exec.Command(exe, "CgoRaceSignal")).CombinedOutput()360 if err != nil {361 t.Logf("%s\n", got)362 t.Fatal(err)363 }364 want := "OK\n"365 if string(got) != want {366 t.Errorf("expected %q got %s", want, got)367 }368}369func TestCgoNumGoroutine(t *testing.T) {370 switch runtime.GOOS {371 case "windows", "plan9":372 t.Skipf("skipping numgoroutine test on %s", runtime.GOOS)373 }374 t.Parallel()375 got := runTestProg(t, "testprogcgo", "NumGoroutine")376 want := "OK\n"377 if got != want {378 t.Errorf("expected %q got %v", want, got)379 }380}381func TestCatchPanic(t *testing.T) {382 t.Parallel()383 switch runtime.GOOS {384 case "plan9", "windows":385 t.Skipf("no signals on %s", runtime.GOOS)386 case "darwin":387 if runtime.GOARCH == "amd64" {388 t.Skipf("crash() on darwin/amd64 doesn't raise SIGABRT")389 }390 }391 testenv.MustHaveGoRun(t)392 exe, err := buildTestProg(t, "testprogcgo")393 if err != nil {394 t.Fatal(err)395 }396 for _, early := range []bool{true, false} {397 cmd := testenv.CleanCmdEnv(exec.Command(exe, "CgoCatchPanic"))398 // Make sure a panic results in a crash.399 cmd.Env = append(cmd.Env, "GOTRACEBACK=crash")400 if early {401 // Tell testprogcgo to install an early signal handler for SIGABRT402 cmd.Env = append(cmd.Env, "CGOCATCHPANIC_EARLY_HANDLER=1")403 }404 if out, err := cmd.CombinedOutput(); err != nil {405 t.Errorf("testprogcgo CgoCatchPanic failed: %v\n%s", err, out)406 }407 }408}409func TestCgoLockOSThreadExit(t *testing.T) {410 switch runtime.GOOS {411 case "plan9", "windows":412 t.Skipf("no pthreads on %s", runtime.GOOS)413 }414 t.Parallel()415 testLockOSThreadExit(t, "testprogcgo")416}417func TestWindowsStackMemoryCgo(t *testing.T) {418 if runtime.GOOS != "windows" {419 t.Skip("skipping windows specific test")420 }421 testenv.SkipFlaky(t, 22575)422 o := runTestProg(t, "testprogcgo", "StackMemory")423 stackUsage, err := strconv.Atoi(o)424 if err != nil {425 t.Fatalf("Failed to read stack usage: %v", err)426 }427 if expected, got := 100<<10, stackUsage; got > expected {428 t.Fatalf("expected < %d bytes of memory per thread, got %d", expected, got)429 }430}431func TestSigStackSwapping(t *testing.T) {432 switch runtime.GOOS {433 case "plan9", "windows":434 t.Skipf("no sigaltstack on %s", runtime.GOOS)435 }436 t.Parallel()437 got := runTestProg(t, "testprogcgo", "SigStack")438 want := "OK\n"439 if got != want {440 t.Errorf("expected %q got %v", want, got)441 }442}443func TestCgoTracebackSigpanic(t *testing.T) {444 // Test unwinding over a sigpanic in C code without a C445 // symbolizer. See issue #23576.446 if runtime.GOOS == "windows" {447 // On Windows if we get an exception in C code, we let448 // the Windows exception handler unwind it, rather449 // than injecting a sigpanic.450 t.Skip("no sigpanic in C on windows")451 }452 t.Parallel()453 got := runTestProg(t, "testprogcgo", "TracebackSigpanic")454 t.Log(got)455 want := "runtime.sigpanic"456 if !strings.Contains(got, want) {457 t.Errorf("did not see %q in output", want)458 }459 // No runtime errors like "runtime: unexpected return pc".460 nowant := "runtime: "461 if strings.Contains(got, nowant) {462 t.Errorf("unexpectedly saw %q in output", nowant)463 }464}465func TestCgoPanicCallback(t *testing.T) {466 t.Parallel()467 got := runTestProg(t, "testprogcgo", "PanicCallback")468 t.Log(got)469 want := "panic: runtime error: invalid memory address or nil pointer dereference"470 if !strings.Contains(got, want) {471 t.Errorf("did not see %q in output", want)472 }473 want = "panic_callback"474 if !strings.Contains(got, want) {475 t.Errorf("did not see %q in output", want)476 }477 want = "PanicCallback"478 if !strings.Contains(got, want) {479 t.Errorf("did not see %q in output", want)480 }481 // No runtime errors like "runtime: unexpected return pc".482 nowant := "runtime: "483 if strings.Contains(got, nowant) {484 t.Errorf("did not see %q in output", want)485 }486}487// Test that C code called via cgo can use large Windows thread stacks488// and call back in to Go without crashing. See issue #20975.489//490// See also TestBigStackCallbackSyscall.491func TestBigStackCallbackCgo(t *testing.T) {492 if runtime.GOOS != "windows" {493 t.Skip("skipping windows specific test")494 }495 t.Parallel()496 got := runTestProg(t, "testprogcgo", "BigStack")497 want := "OK\n"498 if got != want {499 t.Errorf("expected %q got %v", want, got)500 }501}502func nextTrace(lines []string) ([]string, []string) {503 var trace []string504 for n, line := range lines {505 if strings.HasPrefix(line, "---") {506 return trace, lines[n+1:]507 }508 fields := strings.Fields(strings.TrimSpace(line))509 if len(fields) == 0 {510 continue511 }512 // Last field contains the function name.513 trace = append(trace, fields[len(fields)-1])514 }515 return nil, nil516}517func findTrace(text, top string) []string {518 lines := strings.Split(text, "\n")519 _, lines = nextTrace(lines) // Skip the header.520 for len(lines) > 0 {521 var t []string522 t, lines = nextTrace(lines)523 if len(t) == 0 {524 continue525 }526 if t[0] == top {527 return t528 }529 }530 return nil531}532func TestSegv(t *testing.T) {533 switch runtime.GOOS {534 case "plan9", "windows":535 t.Skipf("no signals on %s", runtime.GOOS)536 }537 for _, test := range []string{"Segv", "SegvInCgo"} {538 test := test539 t.Run(test, func(t *testing.T) {540 t.Parallel()541 got := runTestProg(t, "testprogcgo", test)542 t.Log(got)543 want := "SIGSEGV"544 if !strings.Contains(got, want) {545 if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" && strings.Contains(got, "fatal: morestack on g0") {546 testenv.SkipFlaky(t, 39457)547 }548 t.Errorf("did not see %q in output", want)549 }550 // No runtime errors like "runtime: unknown pc".551 switch runtime.GOOS {552 case "darwin", "illumos", "solaris":553 // Runtime sometimes throws when generating the traceback.554 testenv.SkipFlaky(t, 49182)555 case "linux":556 if runtime.GOARCH == "386" {557 // Runtime throws when generating a traceback from558 // a VDSO call via asmcgocall.559 testenv.SkipFlaky(t, 50504)560 }561 }562 if test == "SegvInCgo" && strings.Contains(got, "runtime: unknown pc") {563 testenv.SkipFlaky(t, 50979)564 }565 nowant := "runtime: "566 if strings.Contains(got, nowant) {567 t.Errorf("unexpectedly saw %q in output", nowant)568 }569 })570 }571}572func TestAbortInCgo(t *testing.T) {573 switch runtime.GOOS {574 case "plan9", "windows":575 // N.B. On Windows, C abort() causes the program to exit576 // without going through the runtime at all.577 t.Skipf("no signals on %s", runtime.GOOS)578 }579 t.Parallel()580 got := runTestProg(t, "testprogcgo", "Abort")581 t.Log(got)582 want := "SIGABRT"583 if !strings.Contains(got, want) {584 t.Errorf("did not see %q in output", want)585 }586 // No runtime errors like "runtime: unknown pc".587 nowant := "runtime: "588 if strings.Contains(got, nowant) {589 t.Errorf("did not see %q in output", want)590 }591}592// TestEINTR tests that we handle EINTR correctly.593// See issue #20400 and friends.594func TestEINTR(t *testing.T) {595 switch runtime.GOOS {596 case "plan9", "windows":597 t.Skipf("no EINTR on %s", runtime.GOOS)598 case "linux":599 if runtime.GOARCH == "386" {600 // On linux-386 the Go signal handler sets601 // a restorer function that is not preserved602 // by the C sigaction call in the test,603 // causing the signal handler to crash when604 // returning the normal code. The test is not605 // architecture-specific, so just skip on 386606 // rather than doing a complicated workaround.607 t.Skip("skipping on linux-386; C sigaction does not preserve Go restorer")608 }609 }610 t.Parallel()611 output := runTestProg(t, "testprogcgo", "EINTR")612 want := "OK\n"613 if output != want {614 t.Fatalf("want %s, got %s\n", want, output)615 }616}617// Issue #42207.618func TestNeedmDeadlock(t *testing.T) {619 switch runtime.GOOS {620 case "plan9", "windows":621 t.Skipf("no signals on %s", runtime.GOOS)622 }623 output := runTestProg(t, "testprogcgo", "NeedmDeadlock")624 want := "OK\n"...

Full Screen

Full Screen

value_test.go

Source:value_test.go Github

copy

Full Screen

...8 "github.com/google/uuid"9 "github.com/stretchr/testify/assert"10)11func TestBool(t *testing.T) {12 t.Parallel()13 tests := []struct {14 desc string15 i interface{}16 err bool17 want Bool18 }{19 {20 desc: "value is non-nil and non-bool",21 i: 23,22 err: true,23 },24 {25 desc: "value is nil",26 i: nil,27 want: Bool{},28 },29 {30 desc: "value is false",31 i: false,32 want: Bool{Valid: true},33 },34 {35 desc: "value is true",36 i: true,37 want: Bool{Value: true, Valid: true},38 },39 }40 for _, test := range tests {41 test := test // capture42 t.Run(test.desc, func(t *testing.T) {43 t.Parallel()44 got := Bool{}45 err := got.Unmarshal(test.i)46 if test.err {47 assert.Error(t, err)48 return49 }50 assert.NoError(t, err)51 assert.Equal(t, test.want, got)52 })53 }54}55func TestDateTime(t *testing.T) {56 t.Parallel()57 tests := []struct {58 desc string59 i interface{}60 err bool61 want DateTime62 }{63 {64 desc: "value is non-nil and non-string",65 i: 23,66 err: true,67 },68 {69 desc: "value is non-RFC3339Nano",70 i: "Mon, 02 Jan 2006 15:04:05 -0700",71 err: true,72 },73 {74 desc: "value is nil",75 i: nil,76 want: DateTime{},77 },78 {79 desc: "value is RFC3339Nano",80 i: "2019-08-27T04:14:55.302919Z",81 want: DateTime{82 Value: timeMustParse(time.RFC3339Nano, "2019-08-27T04:14:55.302919Z"),83 Valid: true,84 },85 },86 }87 for _, test := range tests {88 test := test // capture89 t.Run(test.desc, func(t *testing.T) {90 t.Parallel()91 got := DateTime{}92 err := got.Unmarshal(test.i)93 if test.err {94 assert.Error(t, err)95 return96 }97 assert.NoError(t, err)98 assert.Equal(t, test.want, got)99 })100 }101}102func TestDynamic(t *testing.T) {103 t.Parallel()104 tests := []struct {105 desc string106 i interface{}107 err bool108 want Dynamic109 }{110 {111 desc: "value is nil",112 i: nil,113 want: Dynamic{},114 },115 {116 desc: "value is string",117 i: `{"Visualization":null}`,118 want: Dynamic{119 Value: []byte(`{"Visualization":null}`),120 Valid: true,121 },122 },123 {124 desc: "value is []byte",125 i: []byte(`{"Visualization":null}`),126 want: Dynamic{127 Value: []byte(`{"Visualization":null}`),128 Valid: true,129 },130 },131 {132 desc: "value is map[string]interface{}",133 i: map[string]interface{}{"Visualization": nil},134 want: Dynamic{135 Value: []byte(`{"Visualization":null}`),136 Valid: true,137 },138 },139 {140 desc: "value is a []interface{}",141 i: []interface{}{1, "hello", 2.3},142 want: Dynamic{143 Value: []byte(`[1,"hello",2.3]`),144 Valid: true,145 },146 },147 }148 for _, test := range tests {149 test := test // capture150 t.Run(test.desc, func(t *testing.T) {151 t.Parallel()152 got := Dynamic{}153 err := got.Unmarshal(test.i)154 if test.err {155 assert.Error(t, err)156 return157 }158 assert.NoError(t, err)159 assert.EqualValues(t, test.want, got)160 })161 }162}163func TestGUID(t *testing.T) {164 t.Parallel()165 goodUUID := uuid.New()166 tests := []struct {167 desc string168 i interface{}169 err bool170 want GUID171 }{172 {173 desc: "value is non-nil and non-string",174 i: 23,175 err: true,176 },177 {178 desc: "value is a string, but not a UUID",179 i: "hello world",180 err: true,181 },182 {183 desc: "value is nil",184 i: nil,185 want: GUID{},186 },187 {188 desc: "value is a UUID",189 i: goodUUID.String(),190 want: GUID{Value: goodUUID, Valid: true},191 },192 }193 for _, test := range tests {194 test := test // capture195 t.Run(test.desc, func(t *testing.T) {196 t.Parallel()197 got := GUID{}198 err := got.Unmarshal(test.i)199 if test.err {200 assert.Error(t, err)201 return202 }203 assert.NoError(t, err)204 assert.EqualValues(t, test.want, got)205 })206 }207}208func TestInt(t *testing.T) {209 t.Parallel()210 tests := []struct {211 desc string212 i interface{}213 err bool214 want Int215 }{216 {217 desc: "value is non-nil and non-int",218 i: "hello",219 err: true,220 },221 {222 desc: "value is json.Number that is a float",223 i: json.Number("3.2"),224 err: true,225 },226 {227 desc: "value is greater than int32",228 i: math.MaxInt32 + 1,229 err: true,230 },231 {232 desc: "value is nil",233 i: nil,234 want: Int{},235 },236 {237 desc: "value is int",238 i: 2,239 want: Int{Value: 2, Valid: true},240 },241 {242 desc: "value is json.Number",243 i: json.Number("23"),244 want: Int{Value: 23, Valid: true},245 },246 }247 for _, test := range tests {248 test := test // capture249 t.Run(test.desc, func(t *testing.T) {250 t.Parallel()251 got := Int{}252 err := got.Unmarshal(test.i)253 if test.err {254 assert.Error(t, err)255 return256 }257 assert.NoError(t, err)258 assert.EqualValues(t, test.want, got)259 })260 }261}262func TestLong(t *testing.T) {263 t.Parallel()264 tests := []struct {265 desc string266 i interface{}267 err bool268 want Long269 }{270 {271 desc: "value is non-nil and non-int",272 i: "hello",273 err: true,274 },275 {276 desc: "value is json.Number that is a float",277 i: json.Number("3.2"),278 err: true,279 },280 {281 desc: "value is nil",282 i: nil,283 want: Long{},284 },285 {286 desc: "value is int",287 i: 2,288 want: Long{Value: 2, Valid: true},289 },290 {291 desc: "value is json.Number",292 i: json.Number("23"),293 want: Long{Value: 23, Valid: true},294 },295 }296 for _, test := range tests {297 test := test // capture298 t.Run(test.desc, func(t *testing.T) {299 t.Parallel()300 got := Long{}301 err := got.Unmarshal(test.i)302 if test.err {303 assert.Error(t, err)304 return305 }306 assert.NoError(t, err)307 assert.EqualValues(t, test.want, got)308 })309 }310}311func TestReal(t *testing.T) {312 t.Parallel()313 tests := []struct {314 desc string315 i interface{}316 err bool317 want Real318 }{319 {320 desc: "value is non-nil and non-float64",321 i: "hello",322 err: true,323 },324 {325 desc: "value is json.Number that is an int, which will convert to a float64",326 i: json.Number("3"),327 want: Real{Value: 3.0, Valid: true},328 },329 {330 desc: "value is nil",331 i: nil,332 want: Real{},333 },334 {335 desc: "value is float64",336 i: 2.3,337 want: Real{Value: 2.3, Valid: true},338 },339 {340 desc: "value is json.Number",341 i: json.Number("23.2"),342 want: Real{Value: 23.2, Valid: true},343 },344 }345 for _, test := range tests {346 test := test // capture347 t.Run(test.desc, func(t *testing.T) {348 t.Parallel()349 got := Real{}350 err := got.Unmarshal(test.i)351 if test.err {352 assert.Error(t, err)353 return354 }355 assert.NoError(t, err)356 assert.EqualValues(t, test.want, got)357 })358 }359}360func TestString(t *testing.T) {361 t.Parallel()362 tests := []struct {363 desc string364 i interface{}365 err bool366 want String367 }{368 {369 desc: "value is non-nil and non-string",370 i: 23,371 err: true,372 },373 {374 desc: "value is nil",375 i: nil,376 want: String{},377 },378 {379 desc: "value is string",380 i: "hello world",381 want: String{Value: "hello world", Valid: true},382 },383 }384 for _, test := range tests {385 test := test // capture386 t.Run(test.desc, func(t *testing.T) {387 t.Parallel()388 got := String{}389 err := got.Unmarshal(test.i)390 if test.err {391 assert.Error(t, err)392 return393 }394 assert.NoError(t, err)395 assert.EqualValues(t, test.want, got)396 })397 }398}399func TestTimespan(t *testing.T) {400 t.Parallel()401 tests := []struct {402 desc string403 i interface{}404 err bool405 want Timespan406 }{407 {408 desc: "value is non-nil and non-string",409 i: 23,410 err: true,411 },412 {413 desc: "value is nil",414 i: nil,415 want: Timespan{},416 },417 {418 desc: "value is string, but doesn't represent a time",419 i: "hello world",420 err: true,421 },422 {423 desc: "value is string, but doesn't split right",424 i: "00:00",425 err: true,426 },427 {i: "00:00:00", want: Timespan{Valid: true}},428 {i: "00:00:03", want: Timespan{Value: 3 * time.Second, Valid: true}},429 {i: "00:04:03", want: Timespan{Value: 4*time.Minute + 3*time.Second, Valid: true}},430 {i: "02:04:03", want: Timespan{Value: 2*time.Hour + 4*time.Minute + 3*time.Second, Valid: true}},431 {i: "00:00:00.099", want: Timespan{Value: 99 * time.Millisecond, Valid: true}},432 {i: "02:04:03.0123", want: Timespan{Value: 2*time.Hour + 4*time.Minute + 3*time.Second + 12300*time.Microsecond, Valid: true}},433 {i: "01.00:00:00", want: Timespan{Value: 24 * time.Hour, Valid: true}},434 {i: "02.04:05:07", want: Timespan{Value: 2*24*time.Hour + 4*time.Hour + 5*time.Minute + 7*time.Second, Valid: true}},435 {i: "-01.00:00:00", want: Timespan{Value: -24 * time.Hour, Valid: true}},436 {i: "-02.04:05:07", want: Timespan{Value: time.Duration(-1) * (2*24*time.Hour + 4*time.Hour + 5*time.Minute + 7*time.Second), Valid: true}},437 {i: "00.00:00.00:00.000", want: Timespan{Valid: true}},438 {i: "02.04:05:07.789", want: Timespan{Value: 2*24*time.Hour + 4*time.Hour + 5*time.Minute + 7*time.Second + 789*time.Millisecond, Valid: true}},439 {i: "03.00:00:00.111", want: Timespan{Value: 3*24*time.Hour + 111*time.Millisecond, Valid: true}},440 {i: "03.00:00:00.111", want: Timespan{Value: 3*24*time.Hour + 111*time.Millisecond, Valid: true}},441 {i: "364.23:59:59.9999999", want: Timespan{Value: 364*day + 23*time.Hour + 59*time.Minute + 59*time.Second + 9999999*100*time.Nanosecond, Valid: true}},442 }443 for _, test := range tests {444 test := test // capture445 t.Run(test.desc, func(t *testing.T) {446 t.Parallel()447 got := Timespan{}448 err := got.Unmarshal(test.i)449 if test.err {450 assert.Error(t, err)451 return452 }453 assert.NoError(t, err)454 assert.EqualValues(t, test.want, got)455 strGot := got.Marshal()456 if test.i == nil || !got.Valid {457 assert.Equal(t, "00:00:00", strGot)458 return459 }460 assert.EqualValues(t, removeLeadingZeros(test.i.(string)), removeLeadingZeros(strGot))461 })462 }463}464func removeLeadingZeros(s string) string {465 if len(s) == 0 {466 return s467 }468 if string(s[0]) == "-" {469 return string(s[0]) + strings.Trim(s[1:], "0:.")470 }471 return strings.Trim(s, "0:.")472}473func TestDecimal(t *testing.T) {474 t.Parallel()475 tests := []struct {476 desc string477 i interface{}478 err bool479 want Decimal480 }{481 {482 desc: "cannot be a non string",483 i: 3.0,484 err: true,485 },486 {desc: "Conversion of '1',", i: "1", want: Decimal{Value: "1", Valid: true}},487 {desc: "Conversion of '.1',", i: ".1", want: Decimal{Value: ".1", Valid: true}},488 {desc: "Conversion of '1.',", i: "1.", want: Decimal{Value: "1.", Valid: true}},489 {desc: "Conversion of '0.1',", i: "0.1", want: Decimal{Value: "0.1", Valid: true}},490 {desc: "Conversion of '3.07',", i: "3.07", want: Decimal{Value: "3.07", Valid: true}},491 }492 for _, test := range tests {493 test := test // capture494 t.Run(test.desc, func(t *testing.T) {495 t.Parallel()496 got := Decimal{}497 err := got.Unmarshal(test.i)498 if test.err {499 assert.Error(t, err)500 return501 }502 assert.NoError(t, err)503 assert.EqualValues(t, test.want, got)504 })505 }506}507func timeMustParse(layout string, p string) time.Time {508 t, err := time.Parse(layout, p)509 if err != nil {...

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 runtime.GOMAXPROCS(4)4 wg.Add(2)5 fmt.Println("Start Goroutines")6 go func() {7 defer wg.Done()8 for count := 0; count < 3; count++ {9 for char := 'a'; char < 'a'+26; char++ {10 fmt.Printf("%c ", char)11 }12 }13 }()14 go func() {15 defer wg.Done()16 for count := 0; count < 3; count++ {17 for char := 'A'; char < 'A'+26; char++ {18 fmt.Printf("%c ", char)19 }20 }21 }()22 fmt.Println("Waiting To Finish")23 wg.Wait()24 fmt.Println("\nTerminating Program")25}26Parallel() Method27The Parallel() method of the GOMAXPROCS() function is used to implement parallelism in Go. It is used to implement the parallelism in the code. It is used to

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 wg.Add(2)4 go func() {5 fmt.Println("Hello")6 wg.Done()7 }()8 go func() {9 fmt.Println("World")10 wg.Done()11 }()12 fmt.Println("Number of Goroutines:", runtime.NumGoroutine())13 wg.Wait()14}15import (16func main() {17 wg.Add(2)18 wg.Parallel(2, func() {19 fmt.Println("Hello")20 })21 wg.Parallel(2, func() {22 fmt.Println("World")23 })24 fmt.Println("Number of Goroutines:", runtime.NumGoroutine())25 wg.Wait()26}

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 wg.Add(2)4 go func() {5 defer wg.Done()6 for count := 0; count < 3; count++ {7 for r := 'a'; r < 'a'+26; r++ {8 fmt.Printf("%c ", r)9 }10 fmt.Println()11 }12 }()13 go func() {14 defer wg.Done()15 for count := 0; count < 3; count++ {16 for r := 'A'; r < 'A'+26; r++ {17 fmt.Printf("%c ", r)18 }19 fmt.Println()20 }21 }()22 fmt.Println("Number of CPUs:", runtime.NumCPU())23 fmt.Println("Number of Goroutines:", runtime.NumGoroutine())24 wg.Wait()25 fmt.Println("Terminating Program")26 fmt.Println("Number of CPUs:", runtime.NumCPU())27 fmt.Println("Number of Goroutines:", runtime.NumGoroutine())28}

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 runtime.GOMAXPROCS(runtime.NumCPU())4 waitGrp.Add(2)5 go func() {6 defer waitGrp.Done()7 for count := 0; count < 3; count++ {8 for r := 'a'; r <= 'z'; r++ {9 fmt.Printf("%c ", r)10 }11 }12 }()13 go func() {14 defer waitGrp.Done()15 for count := 0; count < 3; count++ {16 for r := 'A'; r <= 'Z'; r++ {17 fmt.Printf("%c ", r)18 }19 }20 }()21 waitGrp.Wait()22 fmt.Println("23}24import (25func main() {26 runtime.GOMAXPROCS(runtime.NumCPU())27 waitGrp.Add(2)28 go func() {29 defer waitGrp.Done()30 for count := 0; count < 3; count++ {31 for r := 'a'; r <= 'z'; r++ {32 fmt.Printf("%c ", r)33 }34 }35 }()36 go func() {37 defer waitGrp.Done()38 for count := 0; count <

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func TestParallel(t *testing.T) {3 t.Parallel()4 fmt.Println("This is parallel test")5}6func TestParallel1(t *testing.T) {7 t.Parallel()8 fmt.Println("This is parallel test1")9}10func TestParallel2(t *testing.T) {11 t.Parallel()12 fmt.Println("This is parallel test2")13}14func TestParallel3(t *testing.T) {15 t.Parallel()16 fmt.Println("This is parallel test3")17}18func TestParallel4(t *testing.T) {19 t.Parallel()20 fmt.Println("This is parallel test4")21}22func TestParallel5(t *testing.T) {23 t.Parallel()24 fmt.Println("This is parallel test5")25}26func TestParallel6(t *testing.T) {27 t.Parallel()28 fmt.Println("This is parallel test6")29}30func TestParallel7(t *testing.T) {31 t.Parallel()32 fmt.Println("This is parallel test7")33}34func TestParallel8(t *testing.T) {35 t.Parallel()36 fmt.Println("This is parallel test8")37}38func TestParallel9(t *testing.T) {39 t.Parallel()40 fmt.Println("This is parallel test9")41}42func TestParallel10(t *testing.T) {43 t.Parallel()44 fmt.Println("This is parallel test10")45}46func TestParallel11(t *testing.T) {47 t.Parallel()48 fmt.Println("This is parallel test11")49}50func TestParallel12(t *testing.T) {51 t.Parallel()52 fmt.Println("This is parallel test12")53}54func TestParallel13(t *testing.T) {55 t.Parallel()56 fmt.Println("This is parallel test13")57}58func TestParallel14(t *testing.T) {59 t.Parallel()60 fmt.Println("This is parallel test14")61}62func TestParallel15(t *testing.T) {63 t.Parallel()64 fmt.Println("This is parallel test15")65}66func TestParallel16(t *testing.T) {67 t.Parallel()68 fmt.Println("This is parallel test16")69}70func TestParallel17(t *testing.T) {71 t.Parallel()72 fmt.Println("This is parallel test17")73}74func TestParallel18(t *testing.T) {75 t.Parallel()76 fmt.Println("This is parallel test18")77}78func TestParallel19(t *testing.T) {

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func TestParallel(t *testing.T) {3 t.Parallel()4 fmt.Println("This is Parallel Test 1")5}6func TestParallel2(t *testing.T) {7 t.Parallel()8 fmt.Println("This is Parallel Test 2")9}10func TestNonParallel(t *testing.T) {11 fmt.Println("This is Non Parallel Test")12}13func TestParallel3(t *testing.T) {14 t.Parallel()15 fmt.Println("This is Parallel Test 3")16}17import (18func TestParallel(t *testing.T) {19 t.Run("Parallel Test 1", func(t *testing.T) {20 fmt.Println("This is Parallel Test 1")21 })22 t.Run("Parallel Test 2", func(t *testing.T) {23 fmt.Println("This is Parallel Test 2")24 })25}26func TestNonParallel(t *testing.T) {27 fmt.Println("This is Non Parallel Test")28}29func TestParallel2(t *testing.T) {30 t.Run("Parallel Test 3", func(t *testing.T) {31 fmt.Println("This is Parallel Test 3")32 })33}34import (35func TestParallel(t *testing.T) {36 t.Run("Parallel Test 1", func(t *testing.T) {37 time.Sleep(2 * time.Second)38 fmt.Println("This is Parallel Test 1")39 })40 t.Run("Parallel Test 2", func(t *testing.T) {41 fmt.Println("This is Parallel Test 2")42 })43}44func TestNonParallel(t *testing.T) {45 fmt.Println("This is Non Parallel Test")46}47func TestParallel2(t *testing.T) {48 t.Run("Parallel Test 3", func

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 runtime.GOMAXPROCS(1)4 wg.Add(2)5 fmt.Println("Start Goroutines")6 go func() {7 defer wg.Done()8 for count := 0; count < 3; count++ {9 for char := 'a'; char < 'a'+26; char++ {10 fmt.Printf("%c ", char)11 }12 }13 }()14 go func() {15 defer wg.Done()16 fmt.Println("17 for i := 1; i < 77; i++ {18 fmt.Printf("%d ", i)19 }20 }()21 fmt.Println("Waiting To Finish")22 wg.Wait()23 fmt.Println("24}

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 go func() {4 fmt.Println("Hello")5 }()6 time.Sleep(1 * time.Second)7}8go func()9import (10func main() {11 go func() {12 fmt.Println("Hello")13 }()14 time.Sleep(1 * time.Second)15}

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