-
Notifications
You must be signed in to change notification settings - Fork 256
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 #390 from Microsoft/runhcs_cmd_context
Store the runhcs.exe path for faster invocation
- Loading branch information
Showing
3 changed files
with
100 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build runhcs_test | ||
|
||
package runhcs | ||
|
||
import ( | ||
_ "github.com/Microsoft/hcsshim/functional/manifest" | ||
) |
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 |
---|---|---|
@@ -1,7 +1,68 @@ | ||
// +build runhcs_test | ||
|
||
package runhcs | ||
|
||
import ( | ||
_ "github.com/Microsoft/hcsshim/functional/manifest" | ||
"os" | ||
"path/filepath" | ||
"sync/atomic" | ||
"testing" | ||
) | ||
|
||
func resetRunhcsPath() { | ||
runhcsPath = atomic.Value{} | ||
} | ||
|
||
func TestGetCommandPath_NoLookPath(t *testing.T) { | ||
resetRunhcsPath() | ||
|
||
path := getCommandPath() | ||
if path != "runhcs.exe" { | ||
t.Fatalf("expected path 'runhcs.exe' got '%s'", path) | ||
} | ||
pathi := runhcsPath.Load() | ||
if pathi == nil { | ||
t.Fatal("cache state should be set after first query") | ||
} | ||
if path != pathi.(string) { | ||
t.Fatalf("expected: '%s' in cache got '%s'", path, pathi.(string)) | ||
} | ||
} | ||
|
||
func TestGetCommandPath_WithLookPath(t *testing.T) { | ||
resetRunhcsPath() | ||
|
||
wd, err := os.Getwd() | ||
if err != nil { | ||
t.Fatalf("failed to get cwd with err: %v", err) | ||
} | ||
fakePath := filepath.Join(wd, "runhcs.exe") | ||
f, err := os.Create(fakePath) | ||
if err != nil { | ||
t.Fatalf("failed to create fake runhcs.exe in path with err: %v", err) | ||
} | ||
f.Close() | ||
defer os.Remove(fakePath) | ||
|
||
path := getCommandPath() | ||
if path != fakePath { | ||
t.Fatalf("expected fake path '%s' got '%s'", fakePath, path) | ||
} | ||
pathi := runhcsPath.Load() | ||
if pathi == nil { | ||
t.Fatal("cache state should be set after first query") | ||
} | ||
if path != pathi.(string) { | ||
t.Fatalf("expected: '%s' in cache got '%s'", fakePath, pathi.(string)) | ||
} | ||
} | ||
|
||
func TestGetCommandPath_WithCache(t *testing.T) { | ||
resetRunhcsPath() | ||
|
||
value := "this is a test" | ||
runhcsPath.Store(value) | ||
|
||
path := getCommandPath() | ||
if path != value { | ||
t.Fatalf("expected fake cached path: '%s' got '%s'", value, path) | ||
} | ||
} |