How to use Run method of test_helpers Package

Best Ginkgo code snippet using test_helpers.Run

cli_test.go

Source:cli_test.go Github

copy

Full Screen

...18var testPw = []byte("test")19func TestMain(m *testing.M) {20 test_helpers.ResetTmpDir(false)21 before := test_helpers.ListFds(0, "")22 r := m.Run()23 after := test_helpers.ListFds(0, "")24 if len(before) != len(after) {25 fmt.Printf("fd leak in test process? before, after:\n%v\n%v\n", before, after)26 os.Exit(1)27 }28 os.Exit(r)29}30// Test -init flag31func TestInit(t *testing.T) {32 dir := test_helpers.InitFS(t)33 _, c, err := configfile.LoadAndDecrypt(dir+"/"+configfile.ConfDefaultName, testPw)34 if err != nil {35 t.Fatal(err)36 }37 if c.IsFeatureFlagSet(configfile.FlagAESSIV) {38 t.Error("AESSIV flag should not be set")39 }40}41// Test that gocryptfs.conf and gocryptfs.diriv are there with the expected42// permissions after -init43func TestInitFilePerms(t *testing.T) {44 dir := test_helpers.InitFS(t)45 var st syscall.Stat_t46 syscall.Stat(dir+"/gocryptfs.conf", &st)47 perms := st.Mode & 077748 if perms != 0400 {49 t.Errorf("Wrong permissions for gocryptfs.conf: %#o", perms)50 }51 st = syscall.Stat_t{}52 syscall.Stat(dir+"/gocryptfs.diriv", &st)53 perms = st.Mode & 077754 // From v1.7.1, these are created with 0440 permissions, see55 // https://github.com/HorizonLiu/gocryptfs/issues/387 .56 // From v2.0, created with 0444 perms, see57 // https://github.com/HorizonLiu/gocryptfs/issues/539 .58 if perms != 0444 {59 t.Errorf("Wrong permissions for gocryptfs.diriv: %#o", perms)60 }61}62// Test -init with -devrandom flag63func TestInitDevRandom(t *testing.T) {64 test_helpers.InitFS(t, "-devrandom")65}66// Test -init with -aessiv67func TestInitAessiv(t *testing.T) {68 dir := test_helpers.InitFS(t, "-aessiv")69 _, c, err := configfile.LoadAndDecrypt(dir+"/"+configfile.ConfDefaultName, testPw)70 if err != nil {71 t.Fatal(err)72 }73 if !c.IsFeatureFlagSet(configfile.FlagAESSIV) {74 t.Error("AESSIV flag should be set but is not")75 }76}77// Test -init with -reverse78func TestInitReverse(t *testing.T) {79 dir := test_helpers.InitFS(t, "-reverse")80 _, c, err := configfile.LoadAndDecrypt(dir+"/"+configfile.ConfReverseName, testPw)81 if err != nil {82 t.Fatal(err)83 }84 if !c.IsFeatureFlagSet(configfile.FlagAESSIV) {85 t.Error("AESSIV flag should be set but is not")86 }87}88// testPasswd changes the password from "test" to "test" using89// the -extpass method, then from "test" to "newpasswd" using the90// stdin method.91func testPasswd(t *testing.T, dir string, extraArgs ...string) {92 // Change password using "-extpass"93 args := []string{"-q", "-passwd", "-extpass", "echo test"}94 args = append(args, extraArgs...)95 args = append(args, dir)96 cmd := exec.Command(test_helpers.GocryptfsBinary, args...)97 cmd.Stdout = os.Stdout98 cmd.Stderr = os.Stderr99 err := cmd.Run()100 if err != nil {101 t.Error(err)102 }103 // Change password using stdin104 args = []string{"-q", "-passwd"}105 args = append(args, extraArgs...)106 args = append(args, dir)107 cmd = exec.Command(test_helpers.GocryptfsBinary, args...)108 cmd.Stdout = os.Stdout109 cmd.Stderr = os.Stderr110 p, err := cmd.StdinPipe()111 if err != nil {112 t.Fatal(err)113 }114 err = cmd.Start()115 if err != nil {116 t.Error(err)117 }118 // Old password119 p.Write([]byte("test\n"))120 // New password121 p.Write([]byte("newpasswd\n"))122 p.Close()123 err = cmd.Wait()124 if err != nil {125 t.Error(err)126 }127}128// Test -passwd flag129func TestPasswd(t *testing.T) {130 // Create FS131 dir := test_helpers.InitFS(t)132 mnt := dir + ".mnt"133 // Add content134 test_helpers.MountOrFatal(t, dir, mnt, "-extpass", "echo test")135 file1 := mnt + "/file1"136 err := ioutil.WriteFile(file1, []byte("somecontent"), 0600)137 if err != nil {138 t.Fatal(err)139 }140 err = test_helpers.UnmountErr(mnt)141 if err != nil {142 t.Fatal(err)143 }144 // Change password to "newpasswd"145 testPasswd(t, dir)146 // Mount and verify147 test_helpers.MountOrFatal(t, dir, mnt, "-extpass", "echo newpasswd")148 content, err := ioutil.ReadFile(file1)149 if err != nil {150 t.Error(err)151 } else if string(content) != "somecontent" {152 t.Errorf("wrong content: %q", string(content))153 }154 err = test_helpers.UnmountErr(mnt)155 if err != nil {156 t.Fatal(err)157 }158}159// cp copies file at `src` to `dst`, overwriting160// `dst` if it already exists. Calls t.Fatal on failure.161func cp(t *testing.T, src string, dst string) {162 conf, err := ioutil.ReadFile(src)163 if err != nil {164 t.Fatal(err)165 }166 syscall.Unlink(dst)167 err = ioutil.WriteFile(dst, conf, 0600)168 if err != nil {169 t.Fatal(err)170 }171}172// Test -passwd with -masterkey173func TestPasswdMasterkey(t *testing.T) {174 // Create FS175 dir := test_helpers.InitFS(t)176 // Overwrite with config with known master key177 cp(t, "gocryptfs.conf.b9e5ba23", dir+"/gocryptfs.conf")178 // Add content179 mnt := dir + ".mnt"180 test_helpers.MountOrFatal(t, dir, mnt, "-extpass", "echo test")181 file1 := mnt + "/file1"182 err := ioutil.WriteFile(file1, []byte("somecontent"), 0600)183 if err != nil {184 t.Fatal(err)185 }186 test_helpers.UnmountPanic(mnt)187 // Change password using stdin188 args := []string{"-q", "-passwd", "-masterkey",189 "b9e5ba23-981a22b8-c8d790d8-627add29-f680513f-b7b7035f-d203fb83-21d82205"}190 args = append(args, dir)191 cmd := exec.Command(test_helpers.GocryptfsBinary, args...)192 cmd.Stdout = os.Stdout193 cmd.Stderr = os.Stderr194 p, err := cmd.StdinPipe()195 if err != nil {196 t.Fatal(err)197 }198 err = cmd.Start()199 if err != nil {200 t.Error(err)201 }202 // New password203 p.Write([]byte("newpasswd\n"))204 p.Close()205 err = cmd.Wait()206 if err != nil {207 t.Error(err)208 }209 // Mount and verify210 test_helpers.MountOrFatal(t, dir, mnt, "-extpass", "echo newpasswd")211 content, err := ioutil.ReadFile(file1)212 if err != nil {213 t.Error(err)214 } else if string(content) != "somecontent" {215 t.Errorf("wrong content: %q", string(content))216 }217 test_helpers.UnmountPanic(mnt)218}219// Test -passwd with -masterkey=stdin220func TestPasswdMasterkeyStdin(t *testing.T) {221 // Create FS222 dir := test_helpers.InitFS(t)223 // Overwrite with config with known master key224 cp(t, "gocryptfs.conf.b9e5ba23", dir+"/gocryptfs.conf")225 // Add content226 mnt := dir + ".mnt"227 test_helpers.MountOrFatal(t, dir, mnt, "-extpass", "echo test")228 file1 := mnt + "/file1"229 err := ioutil.WriteFile(file1, []byte("somecontent"), 0600)230 if err != nil {231 t.Fatal(err)232 }233 test_helpers.UnmountPanic(mnt)234 // Change password using stdin235 args := []string{"-q", "-passwd", "-masterkey=stdin"}236 args = append(args, dir)237 cmd := exec.Command(test_helpers.GocryptfsBinary, args...)238 cmd.Stdout = os.Stdout239 cmd.Stderr = os.Stderr240 p, err := cmd.StdinPipe()241 if err != nil {242 t.Fatal(err)243 }244 err = cmd.Start()245 if err != nil {246 t.Error(err)247 }248 // Masterkey249 p.Write([]byte("b9e5ba23-981a22b8-c8d790d8-627add29-f680513f-b7b7035f-d203fb83-21d82205\n"))250 // New password251 p.Write([]byte("newpasswd\n"))252 p.Close()253 err = cmd.Wait()254 if err != nil {255 t.Fatal(err)256 }257 // Mount and verify258 test_helpers.MountOrFatal(t, dir, mnt, "-extpass", "echo newpasswd")259 content, err := ioutil.ReadFile(file1)260 if err != nil {261 t.Fatal(err)262 } else if string(content) != "somecontent" {263 t.Errorf("wrong content: %q", string(content))264 }265 test_helpers.UnmountPanic(mnt)266}267// Test -passwd with -reverse268func TestPasswdReverse(t *testing.T) {269 // Create FS270 dir := test_helpers.InitFS(t, "-reverse")271 testPasswd(t, dir, "-reverse")272}273// Test -passwd with -scryptn274func TestPasswdScryptn(t *testing.T) {275 dir := test_helpers.InitFS(t)276 cf, err := configfile.Load(dir + "/gocryptfs.conf")277 if err != nil {278 t.Fatal(err)279 }280 testPasswd(t, dir, "-scryptn", strconv.Itoa(cf.ScryptObject.LogN()+1))281 cf2, err := configfile.Load(dir + "/gocryptfs.conf")282 if err != nil {283 t.Fatal(err)284 }285 if cf2.ScryptObject.LogN() != cf.ScryptObject.LogN()+1 {286 t.Errorf("wrong logN value %d", cf2.ScryptObject.LogN())287 }288}289// Test -init & -config flag290func TestInitConfig(t *testing.T) {291 config := test_helpers.TmpDir + "/TestInitConfig.conf"292 dir := test_helpers.InitFS(t, "-config="+config)293 _, err := os.Stat(config)294 if err != nil {295 t.Fatal(err)296 }297 // Test -passwd & -config298 cmd2 := exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", "-extpass", "echo test",299 "-config", config, dir)300 cmd2.Stdout = os.Stdout301 cmd2.Stderr = os.Stderr302 err = cmd2.Run()303 if err != nil {304 t.Error(err)305 }306}307// Test -ro308func TestRo(t *testing.T) {309 dir := test_helpers.InitFS(t)310 mnt := dir + ".mnt"311 test_helpers.MountOrFatal(t, dir, mnt, "-ro", "-extpass=echo test")312 defer test_helpers.UnmountPanic(mnt)313 file := mnt + "/file"314 err := os.Mkdir(file, 0777)315 if err == nil {316 t.Errorf("Mkdir should have failed")317 }318 _, err = os.Create(file)319 if err == nil {320 t.Errorf("Create should have failed")321 }322}323// Test "-nonempty"324func TestNonempty(t *testing.T) {325 dir := test_helpers.InitFS(t)326 mnt := dir + ".mnt"327 err := os.Mkdir(mnt, 0700)328 if err != nil {329 t.Fatal(err)330 }331 err = ioutil.WriteFile(mnt+"/somefile", []byte("xyz"), 0600)332 if err != nil {333 t.Fatal(err)334 }335 err = test_helpers.Mount(dir, mnt, false, "-extpass=echo test")336 if err == nil {337 t.Errorf("Mounting over a file should fail per default")338 }339 // Should work with "-nonempty"340 test_helpers.MountOrFatal(t, dir, mnt, "-nonempty", "-extpass=echo test")341 test_helpers.UnmountPanic(mnt)342}343// -nofail should be ignored and the mount should succeed344func TestNofail(t *testing.T) {345 dir := test_helpers.InitFS(t)346 mnt := dir + ".mnt"347 test_helpers.MountOrFatal(t, dir, mnt, "-nofail", "-extpass=echo test")348 defer test_helpers.UnmountPanic(mnt)349}350// Test "mountpoint shadows cipherdir" handling351func TestShadows(t *testing.T) {352 mnt := test_helpers.InitFS(t)353 cipher := mnt + ".cipher"354 err := os.Rename(mnt, cipher)355 if err != nil {356 t.Fatal(err)357 }358 // This should work359 // (note that MountOrFatal creates "mnt" again)360 test_helpers.MountOrFatal(t, cipher, mnt, "-extpass=echo test")361 test_helpers.UnmountPanic(mnt)362 cipher2 := mnt + "/cipher"363 err = os.Rename(cipher, cipher2)364 if err != nil {365 t.Fatal(err)366 }367 // This should fail368 err = test_helpers.Mount(cipher2, mnt, false, "-extpass=echo test")369 if err == nil {370 t.Errorf("Should have failed")371 }372}373// TestMountPasswordIncorrect makes sure the correct exit code is used when the password374// was incorrect while mounting375func TestMountPasswordIncorrect(t *testing.T) {376 cDir := test_helpers.InitFS(t) // Create filesystem with password "test"377 pDir := cDir + ".mnt"378 err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo WRONG", "-wpanic=false")379 exitCode := test_helpers.ExtractCmdExitCode(err)380 if exitCode != exitcodes.PasswordIncorrect {381 t.Errorf("want=%d, got=%d", exitcodes.PasswordIncorrect, exitCode)382 }383}384// TestPasswdPasswordIncorrect makes sure the correct exit code is used when the password385// was incorrect while changing the password386func TestPasswdPasswordIncorrect(t *testing.T) {387 cDir := test_helpers.InitFS(t) // Create filesystem with password "test"388 // Change password389 cmd := exec.Command(test_helpers.GocryptfsBinary, "-passwd", cDir)390 childStdin, err := cmd.StdinPipe()391 if err != nil {392 t.Fatal(err)393 }394 err = cmd.Start()395 if err != nil {396 t.Fatal(err)397 }398 _, err = childStdin.Write([]byte("WRONGPASSWORD\nNewPassword"))399 if err != nil {400 t.Fatal(err)401 }402 err = childStdin.Close()403 if err != nil {404 t.Fatal(err)405 }406 err = cmd.Wait()407 exitCode := test_helpers.ExtractCmdExitCode(err)408 if exitCode != exitcodes.PasswordIncorrect {409 t.Errorf("want=%d, got=%d", exitcodes.PasswordIncorrect, exitCode)410 }411}412// Check that we correctly background on mount and close stderr and stdout.413// Something like414// gocryptfs a b | cat415// must not hang ( https://github.com/HorizonLiu/gocryptfs/issues/130 ).416func TestMountBackground(t *testing.T) {417 dir := test_helpers.InitFS(t)418 mnt := dir + ".mnt"419 err := os.Mkdir(mnt, 0700)420 if err != nil {421 t.Fatal(err)422 }423 // Manually create a pipe pair and connect the child's stdout and stderr424 // to it. We cannot use StdoutPipe because that will close the pipe425 // when the child forks away.426 pr, pw, err := os.Pipe()427 if err != nil {428 t.Fatal(err)429 }430 args := []string{"-extpass", "echo test", dir, mnt}431 cmd := exec.Command(test_helpers.GocryptfsBinary, args...)432 cmd.Stdout = pw433 cmd.Stderr = pw434 err = cmd.Run()435 if err != nil {436 t.Error(err)437 }438 pw.Close()439 defer test_helpers.UnmountPanic(mnt)440 // Read until we get EOF.441 c1 := make(chan struct{}, 1)442 go func() {443 buf := make([]byte, 1000)444 for {445 _, err = pr.Read(buf)446 // We should get io.EOF when the child closes stdout447 // and stderr.448 if err != nil {449 pr.Close()450 c1 <- struct{}{}451 return452 }453 }454 }()455 select {456 case <-c1:457 return458 case <-time.After(time.Second * 5):459 t.Fatal("timeout")460 }461}462// Test that "gocryptfs -init -info CIPHERDIR" returns an error to the463// user. Only one operation flag is allowed.464func TestMultipleOperationFlags(t *testing.T) {465 // Test all combinations466 opFlags := []string{"-init", "-info", "-passwd", "-fsck"}467 for _, flag1 := range opFlags {468 var flag2 string469 for _, flag2 = range opFlags {470 if flag1 == flag2 {471 continue472 }473 args := []string{flag1, flag2, "/tmp"}474 //t.Logf("testing %v", args)475 cmd := exec.Command(test_helpers.GocryptfsBinary, args...)476 err := cmd.Run()477 exitCode := test_helpers.ExtractCmdExitCode(err)478 if exitCode != exitcodes.Usage {479 t.Fatalf("this should have failed with code %d, but returned %d",480 exitcodes.Usage, exitCode)481 }482 }483 }484}485func TestNoexec(t *testing.T) {486 dir := test_helpers.InitFS(t)487 mnt := dir + ".mnt"488 test_helpers.MountOrFatal(t, dir, mnt, "-extpass=echo test", "-noexec")489 defer test_helpers.UnmountPanic(mnt)490 sh := mnt + "/x.sh"491 content := `#!/bin/bash492echo hello493`494 err := ioutil.WriteFile(sh, []byte(content), 0755)495 if err != nil {496 t.Fatal(err)497 }498 err = exec.Command(sh).Run()499 exitCode := test_helpers.ExtractCmdExitCode(err)500 if exitCode != int(syscall.EACCES) {501 t.Errorf("got exitcode %d instead of EPERM (%d)", exitCode, syscall.EPERM)502 }503}504// Test that a missing argument to "-o" triggers exit code 1.505// See also cli_args_test.go for comprehensive tests of "-o" parsing.506func TestMissingOArg(t *testing.T) {507 cmd := exec.Command(test_helpers.GocryptfsBinary, "foo", "bar", "-o")508 err := cmd.Run()509 exitCode := test_helpers.ExtractCmdExitCode(err)510 if exitCode != exitcodes.Usage {511 t.Fatalf("this should have failed with code %d, but returned %d",512 exitcodes.Usage, exitCode)513 }514}515// -exclude must return an error in forward mode516func TestExcludeForward(t *testing.T) {517 dir := test_helpers.InitFS(t)518 mnt := dir + ".mnt"519 err := test_helpers.Mount(dir, mnt, false, "-extpass", "echo test", "-exclude", "foo")520 if err == nil {521 t.Errorf("-exclude in forward mode should fail")522 }523 t.Log(err)524}525// Check that the config file can be read from a named pipe.526// Make sure bug https://github.com/HorizonLiu/gocryptfs/issues/258 does not come527// back.528func TestConfigPipe(t *testing.T) {529 dir := test_helpers.InitFS(t)530 mnt := dir + ".mnt"531 err := os.Mkdir(mnt, 0700)532 if err != nil {533 t.Fatal(err)534 }535 bashLine := fmt.Sprintf("%s -q -extpass \"echo test\" -config <(cat %s/gocryptfs.conf) %s %s", test_helpers.GocryptfsBinary, dir, dir, mnt)536 cmd := exec.Command("bash", "-c", bashLine)537 cmd.Stdout = os.Stdout538 cmd.Stderr = os.Stdout539 err = cmd.Run()540 exitCode := test_helpers.ExtractCmdExitCode(err)541 if exitCode != 0 {542 t.Errorf("bash command\n%q\nresulted in exit code %d", bashLine, exitCode)543 return544 }545 test_helpers.UnmountPanic(mnt)546}547// Ciphertext dir and mountpoint contains a comma548// https://github.com/HorizonLiu/gocryptfs/issues/262549func TestComma(t *testing.T) {550 dir0 := test_helpers.InitFS(t)551 dir := dir0 + ",foo,bar"552 err := os.Rename(dir0, dir)553 if err != nil {554 t.Fatal(err)555 }556 mnt := dir + ".mnt"557 err = test_helpers.Mount(dir, mnt, false, "-extpass", "echo test", "-wpanic=0")558 if err != nil {559 t.Fatalf("Failed to mount %q on %q: %v", dir, mnt, err)560 }561 test_helpers.UnmountPanic(mnt)562}563// Mount with idle timeout 10ms and check that the process exits by itself564// within 5 seconds.565func TestIdle(t *testing.T) {566 dir := test_helpers.InitFS(t)567 mnt := dir + ".mnt"568 err := os.Mkdir(mnt, 0700)569 if err != nil {570 t.Fatal(err)571 }572 cmd := exec.Command(test_helpers.GocryptfsBinary,573 "-q", "-nosyslog", "-fg", "-extpass", "echo test", "-i", "10ms", dir, mnt)574 cmd.Stdout = os.Stdout575 cmd.Stderr = os.Stderr576 err = cmd.Start()577 if err != nil {578 t.Fatal(err)579 }580 timer := time.AfterFunc(5*time.Second, func() {581 t.Error("timeout waiting for umount")582 cmd.Process.Kill()583 })584 err = cmd.Wait()585 timer.Stop()586 if err != nil {587 t.Error(err)588 }589}590// Mount with idle timeout of 100ms read something every 10ms. The fs should591// NOT get unmounted. Regression test for https://github.com/HorizonLiu/gocryptfs/issues/421592func TestNotIdle(t *testing.T) {593 dir := test_helpers.InitFS(t)594 mnt := dir + ".mnt"595 err := test_helpers.Mount(dir, mnt, false, "-extpass", "echo test", "-i=100ms")596 if err != nil {597 t.Fatal(err)598 }599 err = ioutil.WriteFile(mnt+"/foo", []byte("foo"), 0600)600 if err != nil {601 t.Fatal(err)602 }603 // Read every 10 milliseconds for a total of 1 second604 for i := 1; i < 100; i++ {605 _, err = ioutil.ReadFile(mnt + "/foo")606 if err != nil {607 t.Fatalf("iteration %d failed: %v", i, err)608 }609 time.Sleep(10 * time.Millisecond)610 }611 // Keep a file handle open for 1 second612 fd, err := os.Open(mnt + "/foo")613 if err != nil {614 t.Fatal(err)615 }616 time.Sleep(1 * time.Second)617 buf := make([]byte, 100)618 _, err = fd.Read(buf)619 if err != nil {620 t.Fatal(err)621 }622 fd.Close()623 // All good.624 test_helpers.UnmountPanic(mnt)625}626// TestSymlinkedCipherdir checks that if CIPHERDIR itself is a symlink, it is627// followed.628// https://github.com/HorizonLiu/gocryptfs/issues/450629func TestSymlinkedCipherdir(t *testing.T) {630 dir := test_helpers.InitFS(t)631 dirSymlink := dir + ".symlink"632 err := os.Symlink(dir, dirSymlink)633 if err != nil {634 t.Fatal(err)635 }636 mnt := dir + ".mnt"637 test_helpers.MountOrFatal(t, dirSymlink, mnt, "-extpass=echo test")638 defer test_helpers.UnmountPanic(mnt)639 file := mnt + "/file"640 f, err := os.Create(file)641 if err != nil {642 t.Fatal(err)643 }644 f.Close()645 f, err = os.Open(mnt)646 if err != nil {647 t.Fatal(err)648 }649 defer f.Close()650 names, err := f.Readdirnames(0)651 if err != nil {652 t.Fatal(err)653 }654 if len(names) != 1 || names[0] != "file" {655 t.Errorf("wrong Readdirnames result: %v", names)656 }657}658// TestBadname tests the `-badname` option659func TestBadname(t *testing.T) {660 dir := test_helpers.InitFS(t)661 mnt := dir + ".mnt"662 validFileName := "file"663 invalidSuffix := ".invalid_file"664 // use static suffix for testing665 test_helpers.MountOrFatal(t, dir, mnt, "-badname=*", "-extpass=echo test")666 defer test_helpers.UnmountPanic(mnt)667 // write one valid filename (empty content)668 file := mnt + "/" + validFileName669 err := ioutil.WriteFile(file, nil, 0600)670 if err != nil {671 t.Fatal(err)672 }673 // read encrypted file name674 fread, err := os.Open(dir)675 if err != nil {676 t.Fatal(err)677 }678 defer fread.Close()679 encryptedfilename := ""680 ciphernames, err := fread.Readdirnames(0)681 if err != nil {682 t.Fatal(err)683 }684 for _, ciphername := range ciphernames {685 if ciphername != "gocryptfs.conf" && ciphername != "gocryptfs.diriv" {686 encryptedfilename = ciphername687 // found cipher name of "file"688 break689 }690 }691 // write invalid file which should be decodable692 err = ioutil.WriteFile(dir+"/"+encryptedfilename+invalidSuffix, nil, 0600)693 if err != nil {694 t.Fatal(err)695 }696 // write invalid file which is not decodable (cropping the encrpyted file name)697 err = ioutil.WriteFile(dir+"/"+encryptedfilename[:len(encryptedfilename)-2]+invalidSuffix, nil, 0600)698 if err != nil {699 t.Fatal(err)700 }701 // check for filenames702 f, err := os.Open(mnt)703 if err != nil {704 t.Fatal(err)705 }706 defer f.Close()707 names, err := f.Readdirnames(0)708 if err != nil {709 t.Fatal(err)710 }711 foundDecodable := false712 foundUndecodable := false713 for _, name := range names {714 if strings.Contains(name, validFileName+invalidSuffix+" GOCRYPTFS_BAD_NAME") {715 foundDecodable = true716 } else if strings.Contains(name, encryptedfilename[:len(encryptedfilename)-2]+invalidSuffix+" GOCRYPTFS_BAD_NAME") {717 foundUndecodable = true718 }719 }720 if !foundDecodable {721 t.Errorf("did not find invalid name %s in %v", validFileName+invalidSuffix+" GOCRYPTFS_BAD_NAME", names)722 }723 if !foundUndecodable {724 t.Errorf("did not find invalid name %s in %v", encryptedfilename[:len(encryptedfilename)-2]+invalidSuffix+" GOCRYPTFS_BAD_NAME", names)725 }726}727// TestPassfile tests the `-passfile` option728func TestPassfile(t *testing.T) {729 dir := test_helpers.InitFS(t)730 mnt := dir + ".mnt"731 passfile1 := mnt + ".1.txt"732 ioutil.WriteFile(passfile1, []byte("test"), 0600)733 test_helpers.MountOrFatal(t, dir, mnt, "-passfile="+passfile1)734 defer test_helpers.UnmountPanic(mnt)735}736// TestPassfileX2 tests that the `-passfile` option can be passed twice737func TestPassfileX2(t *testing.T) {738 dir := test_helpers.InitFS(t)739 mnt := dir + ".mnt"740 passfile1 := mnt + ".1.txt"741 passfile2 := mnt + ".2.txt"742 ioutil.WriteFile(passfile1, []byte("te"), 0600)743 ioutil.WriteFile(passfile2, []byte("st"), 0600)744 test_helpers.MountOrFatal(t, dir, mnt, "-passfile="+passfile1, "-passfile="+passfile2)745 defer test_helpers.UnmountPanic(mnt)746}747// TestInitNotEmpty checks that `gocryptfs -init` returns the right error code748// if CIPHERDIR is not empty. See https://github.com/HorizonLiu/gocryptfs/pull/503749func TestInitNotEmpty(t *testing.T) {750 dir := test_helpers.TmpDir + "/" + t.Name()751 if err := os.Mkdir(dir, 0700); err != nil {752 t.Fatal(err)753 }754 if err := ioutil.WriteFile(dir+"/foo", nil, 0700); err != nil {755 t.Fatal(err)756 }757 cmd := exec.Command(test_helpers.GocryptfsBinary, "-init", "-extpass", "echo test", dir)758 cmd.Stdout = os.Stdout759 cmd.Stderr = os.Stderr760 err := cmd.Run()761 exitCode := test_helpers.ExtractCmdExitCode(err)762 if exitCode != exitcodes.CipherDir {763 t.Fatalf("wrong exit code: have=%d, want=%d", exitCode, exitcodes.CipherDir)764 }765}766// TestSharedstorage checks that `-sharedstorage` hands out arbitrary inode767// numbers (no hard link tracking)768func TestSharedstorage(t *testing.T) {769 dir := test_helpers.InitFS(t)770 mnt := dir + ".mnt"771 test_helpers.MountOrFatal(t, dir, mnt, "-extpass=echo test", "-sharedstorage")772 defer test_helpers.UnmountPanic(mnt)773 foo1 := mnt + "/foo1"774 foo2 := mnt + "/foo2"...

Full Screen

Full Screen

stages_test.go

Source:stages_test.go Github

copy

Full Screen

...104 failWithMockerOutput(t, m)105 }106}107func runCLIStage(slug string, path string) (exitCode int) {108 return RunCLI(map[string]string{109 "CODECRAFTERS_CURRENT_STAGE_SLUG": slug,110 "CODECRAFTERS_SUBMISSION_DIR": path,111 "CODECRAFTERS_COURSE_PAGE_URL": "dummy",112 })113}114func failWithMockerOutput(t *testing.T, m *IOMocker) {115 m.End()116 t.Error(fmt.Sprintf("stdout: \n%s\n\nstderr: \n%s", m.ReadStdout(), m.ReadStderr()))117 t.FailNow()118}...

Full Screen

Full Screen

main_test.go

Source:main_test.go Github

copy

Full Screen

...8 "testing"9 "time"10)11func TestMainFunc(t *testing.T) {12 Running = true13 var git = NewGoGit()14 repos := test_helpers.SetupRepos()15 defer test_helpers.CleanupRepos(repos)16 configDir, err := ioutil.TempDir("", "git-notes-config-dir")17 assert.NoError(t, err)18 test_helpers.WriteFile(t, configDir, "git-notes.json", fmt.Sprintf(`{ "repos": [ "%s" ] }`, repos.Local))19 oldArgs := os.Args20 os.Args = []string{"app", fmt.Sprintf("%s/%s", configDir, "git-notes.json")}21 defer func() { os.Args = oldArgs }()22 test_helpers.WriteFile(t, repos.Local, "test.md", "TestContent")23 test_helpers.PerformCmd(t, repos.Local, "git", "add", "--all")24 test_helpers.PerformCmd(t, repos.Local, "git", "commit", "-m", "First commit")25 state, err := git.GetState(repos.Local)26 assert.NoError(t, err)27 assert.Equal(t, Ahead, state)28 go main()29 assert.Eventually(t, func() bool {30 state, err := git.GetState(repos.Local)31 assert.NoError(t, err)32 return state == Sync33 }, 15 * time.Second, 1 * time.Second)34 test_helpers.WriteFile(t, repos.Local, "test.md", "TestContent2")35 state, err = git.GetState(repos.Local)36 assert.NoError(t, err)37 assert.Equal(t, Dirty, state)38 assert.Eventually(t, func() bool {39 state, err := git.GetState(repos.Local)40 assert.NoError(t, err)41 return state == Sync42 }, 15 * time.Second, 1 * time.Second)43 Running = false44}45func TestRun(t *testing.T) {46 var git = MockGit{}47 var watcher = MockWatcher{}48 var configReader = MockConfigReader{}49 var monitor = MockMonitor{}50 oldArgs := os.Args51 os.Args = []string{"app", "some-git-notes.json"}52 defer func() { os.Args = oldArgs }()53 Run(&git, &watcher, &configReader, &monitor)54 assert.Equal(t, "some-git-notes.json", configReader.readPath)55 assert.Equal(t, []string{"some-path", "some-path-2"}, monitor.startMonitorPaths)56}57type MockConfigReader struct {58 readPath string59}60func (m *MockConfigReader) Read(path string) (*Config, error) {61 m.readPath = path62 var config = &Config{63 Repos: []string{"some-path", "some-path-2"},64 }65 return config, nil66}67type MockMonitor struct {...

Full Screen

Full Screen

Run

Using AI Code Generation

copy

Full Screen

1func TestMain(m *testing.M) {2 test_helpers.Run(m)3}4func TestMain(m *testing.M) {5 test_helpers.Run(m)6}7import (8func Run(m *testing.M) {9 fmt.Println("Running tests...")10 code := m.Run()11 fmt.Println("Tests completed.")12 os.Exit(code)13}14func RunTests() {15 fmt.Println("Running tests...")16 cmd := exec.Command("go", "test", "-v")17 cmd.Run()18 fmt.Println("Tests completed.")19}20func RunTestsWithCoverage() {21 fmt.Println("Running tests with coverage...")22 cmd := exec.Command("go", "test", "-coverprofile=cover.out", "-v")23 cmd.Run()24 fmt.Println("Tests completed.")25}26func RunTestsAndOpenCoverage() {27 fmt.Println("Running tests with coverage...")28 cmd := exec.Command("go", "test", "-coverprofile=cover.out", "-v")29 cmd.Run()30 fmt.Println("Tests completed.")31 fmt.Println("Opening coverage...")32 cmd = exec.Command("go", "tool", "cover", "-html=cover.out")33 cmd.Run()34 fmt.Println("Coverage opened.")35}36func RunTestsAndOpenCoverageWithCoveralls() {37 fmt.Println("Running tests with coverage...")38 cmd := exec.Command("go", "test", "-coverprofile=cover.out", "-v")39 cmd.Run()40 fmt.Println("Tests completed.")41 fmt.Println("Opening coverage...")42 cmd = exec.Command("go", "tool", "cover", "-html=cover.out")43 cmd.Run()44 fmt.Println("Coverage opened.")45 fmt.Println("Sending coverage to coveralls...")46 cmd = exec.Command("goveralls", "-coverprofile=cover.out

Full Screen

Full Screen

Run

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 test_helpers.Run()5}6import (7func Run() {8 fmt.Println("Hello World")9}10import (11func main() {12 fmt.Println("Hello World")13 test_helpers.Run()14}15import (16func Run() {17 fmt.Println("Hello World")18}

Full Screen

Full Screen

Run

Using AI Code Generation

copy

Full Screen

1import (2func TestMain(t *testing.T) {3 test_helpers.Run(t, func(t *testing.T) {4 })5}6import (7func Run(t *testing.T, f func(t *testing.T)) {8 f(t)9}10import (11func TestMain(t *testing.T) {12 test_helpers.Run(t, func(t *testing.T) {13 })14}15import (16func Run(t *testing.T, f func(t *testing.T)) {17 f(t)18}19--- PASS: TestMain (0.00s)20--- PASS: TestMain (0.00s)21Your name to display (optional):22Your name to display (optional):

Full Screen

Full Screen

Run

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 test_helpers.Run()5}6import (7func Run() {8 fmt.Println("Hello, test_helpers")9}10You are not importing test_helpers in 1.go . You need to add:11import "test_helpers"

Full Screen

Full Screen

Run

Using AI Code Generation

copy

Full Screen

1func TestRun(t *testing.T) {2 test_helpers.Run(t, "TestRun", func(t *testing.T) {3 t.Log("Hello World")4 })5}6func Run(t *testing.T, testName string, f func(t *testing.T)) {7 t.Run(testName, f)8}

Full Screen

Full Screen

Run

Using AI Code Generation

copy

Full Screen

1import (2func TestApp(t *testing.T) {3 revel.TestSuites(t, new(test_helpers.Test))4}5import (6type Test struct {7}8func (t *Test) Before() {9 println("Set up")10}11func (t *Test) TestThatIndexPageWorks() {12 t.Get("/")13 t.AssertOk()14 t.AssertContentType("text/html; charset=utf-8")15}16func (t *Test) After() {17 println("Tear down")18}

Full Screen

Full Screen

Run

Using AI Code Generation

copy

Full Screen

1func TestRun(t *testing.T) {2 test_helpers.Run(t, "TestRun", func(t *testing.T) {3 })4}5func Run(t *testing.T, name string, f func(t *testing.T)) {6 t.Run(name, f)7}

Full Screen

Full Screen

Run

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 test_helpers.Run()4 fmt.Println("test cases executed")5}6import (7func main() {8 fmt.Println(test_helpers.Reverse("hello"))9 fmt.Println("test cases executed")10}11import (12func main() {13 fmt.Println(test_helpers.Reverse("hello"))14 fmt.Println("test cases executed")15}16import (17func main() {18 fmt.Println(test_helpers.Reverse("hello"))19 fmt.Println("test cases executed")20}21import (22func main() {23 fmt.Println(test_helpers.Reverse("hello"))24 fmt.Println("test cases executed")25}26import (27func main() {28 fmt.Println(test_helpers.Reverse("hello"))29 fmt.Println("test cases executed")30}31import (32func main() {33 fmt.Println(test_helpers.Reverse("hello"))34 fmt.Println("test cases executed")35}36import (37func main() {38 fmt.Println(test_helpers.Reverse("hello"))39 fmt.Println("test cases executed")40}41import (42func main() {43 fmt.Println(test_helpers.Reverse("hello"))44 fmt.Println("test cases executed")45}

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