@@ -20,6 +20,9 @@ const (
2020 testSSHPubkeyName = "ssh-pubkey"
2121)
2222
23+ func ptrString (s string ) * string { return & s }
24+ func ptrInt64 (i int64 ) * int64 { return & i }
25+
2326func TestBuildPod_BasicConfig (t * testing.T ) {
2427 notebook := & marimov1alpha1.MarimoNotebook {
2528 ObjectMeta : metav1.ObjectMeta {
@@ -1069,13 +1072,67 @@ func TestBuildPod_EnvVarsEmpty(t *testing.T) {
10691072 }
10701073}
10711074
1075+ func TestBuildPod_RunAsUser (t * testing.T ) {
1076+ var runAsUser int64 = 1234
1077+ notebook := & marimov1alpha1.MarimoNotebook {
1078+ ObjectMeta : metav1.ObjectMeta {
1079+ Name : testNotebookName ,
1080+ Namespace : testNamespace ,
1081+ },
1082+ Spec : marimov1alpha1.MarimoNotebookSpec {
1083+ Image : "ghcr.io/marimo-team/marimo:latest" ,
1084+ Port : 2718 ,
1085+ Source : "https://github.com/marimo-team/marimo.git" ,
1086+ RunAsUser : & runAsUser ,
1087+ },
1088+ }
1089+
1090+ pod := BuildPod (notebook )
1091+
1092+ // Check marimo main container has RunAsUser set
1093+ var marimoContainer * corev1.Container
1094+ for i := range pod .Spec .Containers {
1095+ if pod .Spec .Containers [i ].Name == testMarimoContainer {
1096+ marimoContainer = & pod .Spec .Containers [i ]
1097+ break
1098+ }
1099+ }
1100+ if marimoContainer == nil {
1101+ t .Fatal ("marimo container not found" )
1102+ }
1103+ if marimoContainer .SecurityContext == nil || marimoContainer .SecurityContext .RunAsUser == nil {
1104+ t .Fatal ("marimo container SecurityContext.RunAsUser not set" )
1105+ }
1106+ if * marimoContainer .SecurityContext .RunAsUser != runAsUser {
1107+ t .Errorf ("marimo container RunAsUser: expected %d, got %d" , runAsUser , * marimoContainer .SecurityContext .RunAsUser )
1108+ }
1109+
1110+ // Check git-clone init container has RunAsUser set
1111+ var gitCloneContainer * corev1.Container
1112+ for i := range pod .Spec .InitContainers {
1113+ if pod .Spec .InitContainers [i ].Name == "git-clone" {
1114+ gitCloneContainer = & pod .Spec .InitContainers [i ]
1115+ break
1116+ }
1117+ }
1118+ if gitCloneContainer == nil {
1119+ t .Fatal ("git-clone init container not found" )
1120+ }
1121+ if gitCloneContainer .SecurityContext == nil || gitCloneContainer .SecurityContext .RunAsUser == nil {
1122+ t .Fatal ("git-clone container SecurityContext.RunAsUser not set" )
1123+ }
1124+ if * gitCloneContainer .SecurityContext .RunAsUser != runAsUser {
1125+ t .Errorf ("git-clone container RunAsUser: expected %d, got %d" , runAsUser , * gitCloneContainer .SecurityContext .RunAsUser )
1126+ }
1127+ }
1128+
10721129func TestExpandMounts_SSHFSIgnored (t * testing.T ) {
10731130 // sshfs:// mounts are handled by the plugin, not the operator
10741131 mounts := []string {
10751132 "sshfs:///home/marimo/notebooks" ,
10761133 }
10771134
1078- sidecars := expandMounts (mounts )
1135+ sidecars := expandMounts (mounts , nil )
10791136
10801137 // sshfs:// should be ignored (plugin handles it)
10811138 if len (sidecars ) != 0 {
@@ -1089,7 +1146,7 @@ func TestExpandMounts_UnsupportedScheme(t *testing.T) {
10891146 "nfs://server/path" , // Not supported yet
10901147 }
10911148
1092- sidecars := expandMounts (mounts )
1149+ sidecars := expandMounts (mounts , nil )
10931150
10941151 // Should return empty - unsupported schemes are ignored
10951152 if len (sidecars ) != 0 {
@@ -1103,7 +1160,7 @@ func TestExpandMounts_RsyncIgnored(t *testing.T) {
11031160 "rsync://./local/data" ,
11041161 }
11051162
1106- sidecars := expandMounts (mounts )
1163+ sidecars := expandMounts (mounts , nil )
11071164
11081165 // rsync:// should be ignored (plugin handles it)
11091166 if len (sidecars ) != 0 {
@@ -1119,7 +1176,7 @@ func TestExpandMounts_MixedSchemes(t *testing.T) {
11191176 "cw://bucket/path3" ,
11201177 }
11211178
1122- sidecars := expandMounts (mounts )
1179+ sidecars := expandMounts (mounts , nil )
11231180
11241181 // Only cw:// should produce sidecar
11251182 if len (sidecars ) != 1 {
@@ -1203,7 +1260,7 @@ func TestParseCWMountURI(t *testing.T) {
12031260func TestExpandMounts_CW (t * testing.T ) {
12041261 mounts := []string {"cw://mybucket/data" }
12051262
1206- sidecars := expandMounts (mounts )
1263+ sidecars := expandMounts (mounts , nil )
12071264
12081265 if len (sidecars ) != 1 {
12091266 t .Fatalf ("expected 1 sidecar, got %d" , len (sidecars ))
@@ -1236,7 +1293,7 @@ func TestExpandMounts_CW(t *testing.T) {
12361293func TestExpandMounts_CWCustomMountPoint (t * testing.T ) {
12371294 mounts := []string {"cw://mybucket/data:/mnt/s3" }
12381295
1239- sidecars := expandMounts (mounts )
1296+ sidecars := expandMounts (mounts , nil )
12401297
12411298 if len (sidecars ) != 1 {
12421299 t .Fatalf ("expected 1 sidecar, got %d" , len (sidecars ))
@@ -1255,7 +1312,7 @@ func TestExpandMounts_CWCustomMountPoint(t *testing.T) {
12551312func TestExpandMounts_CWBucketOnly (t * testing.T ) {
12561313 mounts := []string {"cw://mybucket" }
12571314
1258- sidecars := expandMounts (mounts )
1315+ sidecars := expandMounts (mounts , nil )
12591316
12601317 if len (sidecars ) != 1 {
12611318 t .Fatalf ("expected 1 sidecar, got %d" , len (sidecars ))
@@ -1275,7 +1332,7 @@ func TestExpandMounts_CWBucketOnly(t *testing.T) {
12751332func TestExpandMounts_CWSecretReference (t * testing.T ) {
12761333 mounts := []string {"cw://mybucket/data" }
12771334
1278- sidecars := expandMounts (mounts )
1335+ sidecars := expandMounts (mounts , nil )
12791336
12801337 if len (sidecars ) != 1 {
12811338 t .Fatalf ("expected 1 sidecar, got %d" , len (sidecars ))
0 commit comments