-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from ipfs/fix/stuff
roundup of cleanup fixes
- Loading branch information
Showing
13 changed files
with
165 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ipfs/go-ipfs-cmds" | ||
) | ||
|
||
var root = &cmds.Command{ | ||
Subcommands: map[string]*cmds.Command{ | ||
"test": &cmds.Command{ | ||
Run: func(req *cmds.Request, re cmds.ResponseEmitter, e cmds.Environment) error { | ||
err := cmds.EmitOnce(re, 42) | ||
|
||
time.Sleep(2 * time.Second) | ||
|
||
e.(env).ch <- struct{}{} | ||
return err | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
type env struct { | ||
ch chan struct{} | ||
} | ||
|
||
func (e env) Context() context.Context { | ||
return context.Background() | ||
} | ||
|
||
func TestRunWaits(t *testing.T) { | ||
flag := make(chan struct{}, 1) | ||
|
||
devnull, err := os.OpenFile(os.DevNull, os.O_RDWR, 0600) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer devnull.Close() | ||
|
||
err = Run( | ||
context.Background(), | ||
root, | ||
[]string{"test", "test"}, | ||
devnull, devnull, devnull, | ||
func(ctx context.Context, req *cmds.Request) (cmds.Environment, error) { | ||
return env{flag}, nil | ||
}, | ||
func(req *cmds.Request, env interface{}) (cmds.Executor, error) { | ||
return cmds.NewExecutor(req.Root), nil | ||
}, | ||
) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
select { | ||
case <-flag: | ||
default: | ||
t.Fatal("expected flag to be raised") | ||
} | ||
} |
Oops, something went wrong.