Skip to content

Commit 4ad345c

Browse files
author
Joshua Krstic
committed
Add test for the wellknownfilewriter
1 parent 3b12427 commit 4ad345c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

launcher/container_runner_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"io"
1111
"os"
12+
"path"
1213
"strconv"
1314
"testing"
1415
"time"
@@ -651,6 +652,26 @@ func TestPullImageWithRetries(t *testing.T) {
651652
}
652653
}
653654

655+
func TestWellKnownFileLocationWriter(t *testing.T) {
656+
if err := os.MkdirAll(launcherfile.HostTmpPath, 0755); err != nil {
657+
t.Fatalf("Error creating host token path directory: %v", err)
658+
}
659+
660+
fw := &wellKnownFileLocationWriter{}
661+
testData := []byte("testing")
662+
fw.Write(testData)
663+
664+
filepath := path.Join(launcherfile.HostTmpPath, launcherfile.AttestationVerifierTokenFilename)
665+
data, err := os.ReadFile(filepath)
666+
if err != nil {
667+
t.Fatalf("Failed to read from %s: %v", filepath, err)
668+
}
669+
670+
if !bytes.Equal(data, testData) {
671+
t.Errorf("Initial token written to file does not match expected token: got %v, want %v", data, expectedToken)
672+
}
673+
}
674+
654675
// This ensures fakeContainer implements containerd.Container interface.
655676
var _ containerd.Container = &fakeContainer{}
656677

0 commit comments

Comments
 (0)