github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/agent/bundle_test.go (about) 1 package agent 2 3 import ( 4 "os" 5 "path/filepath" 6 "runtime" 7 "testing" 8 ) 9 10 // TestExecutableForInvalidOS tests that ExecutableForPlatform fails for an 11 // invalid OS specification. 12 func TestExecutableForInvalidOS(t *testing.T) { 13 if _, err := ExecutableForPlatform("fakeos", runtime.GOARCH, ""); err == nil { 14 t.Fatal("extracting agent executable succeeded for invalid OS") 15 } 16 } 17 18 // TestExecutableForInvalidArchitecture tests that ExecutableForPlatform fails 19 // for an invalid architecture specification. 20 func TestExecutableForInvalidArchitecture(t *testing.T) { 21 if _, err := ExecutableForPlatform(runtime.GOOS, "fakearch", ""); err == nil { 22 t.Fatal("extracting agent executable succeeded for invalid architecture") 23 } 24 } 25 26 // TestExecutableForInvalidPair tests that ExecutableForPlatform fails for an 27 // invalid OS/architecture specification. 28 func TestExecutableForInvalidPair(t *testing.T) { 29 if _, err := ExecutableForPlatform("fakeos", "fakearch", ""); err == nil { 30 t.Fatal("extracting agent executable succeeded for invalid architecture") 31 } 32 } 33 34 // TestExecutableForPlatform tests that ExecutableForPlatform succeeds for the 35 // current OS/architecture. 36 func TestExecutableForPlatform(t *testing.T) { 37 if executable, err := ExecutableForPlatform(runtime.GOOS, runtime.GOARCH, ""); err != nil { 38 t.Fatal("unable to extract agent bundle for current platform:", err) 39 } else if err = os.Remove(executable); err != nil { 40 t.Error("unable to remove agent executable:", err) 41 } 42 } 43 44 // TestExecutableForPlatformWithOutputPath tests that ExecutableForPlatform 45 // functions correctly when an output path is specified. 46 func TestExecutableForPlatformWithOutputPath(t *testing.T) { 47 // Compute the output path. 48 outputPath := filepath.Join(t.TempDir(), "agent_output") 49 50 // Perform executable extraction. 51 executable, err := ExecutableForPlatform(runtime.GOOS, runtime.GOARCH, outputPath) 52 if err != nil { 53 t.Fatal("unable to extract agent bundle for current platform:", err) 54 } 55 56 // Verify the output path. 57 if executable != outputPath { 58 t.Error("executable output path does not match expected:", executable, "!=", outputPath) 59 } 60 61 // Remove the file. 62 if err = os.Remove(executable); err != nil { 63 t.Error("unable to remove agent executable:", err) 64 } 65 }