@@ -740,3 +740,124 @@ func TestMakePodTemplateConfig(t *testing.T) {
740740
741741 assert .Equal (t , & mounter.PodTemplateConfig {}, makePodTemplateConfig (& oss.Options {}))
742742}
743+
744+ func TestGetDirectAssignedValue (t * testing.T ) {
745+ tests := []struct {
746+ name string
747+ runtimeClass string
748+ expected bool
749+ }{
750+ {
751+ name : "Test with rund runtime class" ,
752+ runtimeClass : "rund" ,
753+ expected : true ,
754+ },
755+ {
756+ name : "Test with runc runtime class" ,
757+ runtimeClass : "runc" ,
758+ expected : false ,
759+ },
760+ {
761+ name : "Test with empty runtime class" ,
762+ runtimeClass : "" ,
763+ expected : false ,
764+ },
765+ {
766+ name : "Test with invalid runtime class" ,
767+ runtimeClass : "invalid" ,
768+ expected : false ,
769+ },
770+ {
771+ name : "Test with RUNd runtime class (case insensitive)" ,
772+ runtimeClass : "RUNd" ,
773+ expected : true ,
774+ },
775+ {
776+ name : "Test with RUNc runtime class (case insensitive)" ,
777+ runtimeClass : "RUNc" ,
778+ expected : false ,
779+ },
780+ }
781+
782+ for _ , tt := range tests {
783+ t .Run (tt .name , func (t * testing.T ) {
784+ t .Setenv ("DEFAULT_RUNTIME_CLASS" , tt .runtimeClass )
785+ result := getDirectAssignedValue ()
786+ assert .Equal (t , tt .expected , result )
787+ })
788+ }
789+ }
790+
791+ func TestParseOptions_DirectAssigned (t * testing.T ) {
792+ tests := []struct {
793+ name string
794+ default_runtime_class string
795+ volOptions map [string ]string
796+ wantDirectAssigned bool
797+ }{
798+ {
799+ name : "empty runtime, empty volOptions" ,
800+ default_runtime_class : "" ,
801+ volOptions : map [string ]string {},
802+ wantDirectAssigned : false ,
803+ },
804+ {
805+ name : "invalid runtime, empty volOptions" ,
806+ default_runtime_class : "invalid" ,
807+ volOptions : map [string ]string {},
808+ wantDirectAssigned : false ,
809+ },
810+ {
811+ name : "default rund, empty volOptions" ,
812+ default_runtime_class : "rund" ,
813+ volOptions : map [string ]string {},
814+ wantDirectAssigned : true ,
815+ },
816+ {
817+ name : "default runc, empty volOptions" ,
818+ default_runtime_class : "runc" ,
819+ volOptions : map [string ]string {},
820+ wantDirectAssigned : false ,
821+ },
822+ {
823+ name : "empty runtime, vol true" ,
824+ default_runtime_class : "" ,
825+ volOptions : map [string ]string {
826+ optDirectAssigned : "true" ,
827+ },
828+ wantDirectAssigned : true ,
829+ },
830+ {
831+ name : "invalid runtime, vol false" ,
832+ default_runtime_class : "invalid" ,
833+ volOptions : map [string ]string {
834+ optDirectAssigned : "false" ,
835+ },
836+ wantDirectAssigned : false ,
837+ },
838+ {
839+ name : "default rund, invalid volOptions" ,
840+ default_runtime_class : "rund" ,
841+ volOptions : map [string ]string {
842+ optDirectAssigned : "invalid" ,
843+ },
844+ wantDirectAssigned : true ,
845+ },
846+ {
847+ name : "default runc, vol true" ,
848+ default_runtime_class : "runc" ,
849+ volOptions : map [string ]string {
850+ optDirectAssigned : "true" ,
851+ },
852+ wantDirectAssigned : true ,
853+ },
854+ }
855+ for _ , tt := range tests {
856+ t .Run (tt .name , func (t * testing.T ) {
857+ fakeMeta := metadata .NewMetadata ()
858+ t .Setenv ("DEFAULT_RUNTIME_CLASS" , tt .default_runtime_class )
859+ opt := parseOptions (tt .volOptions , nil , nil , false , "" , false , fakeMeta )
860+ assert .Equal (t , tt .wantDirectAssigned , opt .DirectAssigned )
861+ })
862+ }
863+ }
0 commit comments