import ( "os" "testing" "github.com.cloudfoundry.bosh-agent.platform.fakes" ) func TestFileSystem(t *testing.T) { fakePlatform := fakes.NewFakePlatform() err := fakePlatform.WriteFile("/tmp/test.txt", []byte("hello world"), os.FileMode(0644)) if err != nil { t.Errorf("Error writing file: %s", err) } contents, err := fakePlatform.ReadFile("/tmp/test.txt") if err != nil { t.Errorf("Error reading file: %s", err) } if string(contents) != "hello world" { t.Errorf("Unexpected file contents: %s", contents) } }
import ( "os" "testing" "github.com.cloudfoundry.bosh-agent.platform.fakes" ) func TestEnvironmentVariables(t *testing.T) { fakePlatform := fakes.NewFakePlatform() fakePlatform.SetEnv("TEST_VARIABLE", "test value") if os.Getenv("TEST_VARIABLE") != "test value" { t.Errorf("Unexpected environment variable value") } }In both of these examples, we import the "github.com.cloudfoundry.bosh-agent.platform.fakes" package in order to create a "FakePlatform". This allows us to bypass the real file system or environment variables and test our code in isolation.