| | |
| | |
| | |
| |
|
| | package embedtest_test |
| |
|
| | import ( |
| | "embed" |
| | "os" |
| | "testing" |
| | ) |
| |
|
| | var ( |
| | global2 = global |
| | concurrency2 = concurrency |
| | glass2 = glass |
| | sbig2 = sbig |
| | bbig2 = bbig |
| | ) |
| |
|
| | |
| | var global embed.FS |
| |
|
| | |
| | var concurrency string |
| |
|
| | |
| | var glass []byte |
| |
|
| | |
| | var sbig string |
| |
|
| | |
| | var bbig []byte |
| |
|
| | func testFiles(t *testing.T, f embed.FS, name, data string) { |
| | t.Helper() |
| | d, err := f.ReadFile(name) |
| | if err != nil { |
| | t.Error(err) |
| | return |
| | } |
| | if string(d) != data { |
| | t.Errorf("read %v = %q, want %q", name, d, data) |
| | } |
| | } |
| |
|
| | func testString(t *testing.T, s, name, data string) { |
| | t.Helper() |
| | if s != data { |
| | t.Errorf("%v = %q, want %q", name, s, data) |
| | } |
| | } |
| |
|
| | func TestXGlobal(t *testing.T) { |
| | testFiles(t, global, "testdata/hello.txt", "hello, world\n") |
| | testString(t, concurrency, "concurrency", "Concurrency is not parallelism.\n") |
| | testString(t, string(glass), "glass", "I can eat glass and it doesn't hurt me.\n") |
| | testString(t, concurrency2, "concurrency2", "Concurrency is not parallelism.\n") |
| | testString(t, string(glass2), "glass2", "I can eat glass and it doesn't hurt me.\n") |
| |
|
| | big, err := os.ReadFile("testdata/ascii.txt") |
| | if err != nil { |
| | t.Fatal(err) |
| | } |
| | testString(t, sbig, "sbig", string(big)) |
| | testString(t, sbig2, "sbig2", string(big)) |
| | testString(t, string(bbig), "bbig", string(big)) |
| | testString(t, string(bbig2), "bbig", string(big)) |
| |
|
| | if t.Failed() { |
| | return |
| | } |
| |
|
| | |
| | |
| | old := glass[0] |
| | glass[0]++ |
| | if glass2[0] != glass[0] { |
| | t.Fatalf("glass and glass2 do not share storage") |
| | } |
| | glass[0] = old |
| |
|
| | |
| | |
| | old = bbig[0] |
| | bbig[0]++ |
| | if bbig2[0] != bbig[0] { |
| | t.Fatalf("bbig and bbig2 do not share storage") |
| | } |
| | bbig[0] = old |
| | } |
| |
|