-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 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,47 @@ | ||
package examples | ||
|
||
import ( | ||
"io" | ||
"path" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/koron/nvgd/internal/embedresource" | ||
"github.com/koron/nvgd/internal/protocoltest" | ||
) | ||
|
||
func TestRegistered(t *testing.T) { | ||
protocoltest.GetRegistered[*embedresource.EmbedResource](t, "examples") | ||
} | ||
|
||
func loadAsset(t *testing.T, name string) string { | ||
t.Helper() | ||
f, err := assetFS.Open(name) | ||
if err != nil { | ||
t.Fatalf("asset not found: %s", err) | ||
} | ||
defer f.Close() | ||
b, err := io.ReadAll(f) | ||
if err != nil { | ||
t.Fatalf("failed to load the asset %s: %s", name, err) | ||
} | ||
return string(b) | ||
} | ||
|
||
func testAsset(t *testing.T, requrl, assetpath string) { | ||
t.Helper() | ||
want := loadAsset(t, path.Join("assets", assetpath)) | ||
rsrc := protocoltest.Open(t, requrl) | ||
got := protocoltest.ReadAllString(t, rsrc) | ||
if d := cmp.Diff(want, got); d != "" { | ||
t.Errorf("content mismatch: -want +got\n%s", d) | ||
} | ||
} | ||
|
||
func TestContents(t *testing.T) { | ||
testAsset(t, "examples:///line.csv", "line.csv") | ||
testAsset(t, "examples:///pie.csv", "pie.csv") | ||
testAsset(t, "examples:///test.csv", "test.csv") | ||
// Currently index.html is not available. | ||
//testAsset(t, "examples:///", "index.html") | ||
} |