-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gyuho Lee <[email protected]>
- Loading branch information
Showing
1 changed file
with
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package rootkeys | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestRootsFS(t *testing.T) { | ||
// Test that we can list the embedded files | ||
entries, err := RootsFS.ReadDir("keys") | ||
if err != nil { | ||
t.Fatalf("failed to read keys directory: %v", err) | ||
} | ||
|
||
// Verify we have exactly 2 files | ||
if len(entries) != 2 { | ||
t.Errorf("expected 2 files, got %d", len(entries)) | ||
} | ||
|
||
// Expected files | ||
expectedFiles := map[string]bool{ | ||
"gpud-root-1.pem": false, | ||
"gpud-root-2.pem": false, | ||
} | ||
|
||
// Verify each file exists and can be read | ||
for _, entry := range entries { | ||
name := entry.Name() | ||
if _, ok := expectedFiles[name]; !ok { | ||
t.Errorf("unexpected file: %s", name) | ||
continue | ||
} | ||
expectedFiles[name] = true | ||
|
||
// Try to read the file | ||
content, err := RootsFS.ReadFile("keys/" + name) | ||
if err != nil { | ||
t.Errorf("failed to read file %s: %v", name, err) | ||
continue | ||
} | ||
|
||
// Verify the file is not empty | ||
if len(content) == 0 { | ||
t.Errorf("file %s is empty", name) | ||
} | ||
} | ||
|
||
// Verify all expected files were found | ||
for name, found := range expectedFiles { | ||
if !found { | ||
t.Errorf("expected file %s was not found", name) | ||
} | ||
} | ||
} | ||
|
||
func TestRootsFSErrors(t *testing.T) { | ||
// Test reading non-existent directory | ||
_, err := RootsFS.ReadDir("nonexistent") | ||
if err == nil { | ||
t.Error("expected error when reading non-existent directory") | ||
} | ||
|
||
// Test reading non-existent file | ||
_, err = RootsFS.ReadFile("keys/nonexistent.pem") | ||
if err == nil { | ||
t.Error("expected error when reading non-existent file") | ||
} | ||
|
||
// Test reading a directory as a file | ||
_, err = RootsFS.ReadFile("keys") | ||
if err == nil { | ||
t.Error("expected error when reading directory as file") | ||
} | ||
} |