(t *testing.T)
| 86 | } |
| 87 | |
| 88 | func TestRemappedGID(t *testing.T) { |
| 89 | tests := []struct { |
| 90 | spec oci.Spec |
| 91 | gid uint32 |
| 92 | }{{ |
| 93 | // empty spec |
| 94 | spec: oci.Spec{}, |
| 95 | gid: 0, |
| 96 | }, { |
| 97 | // empty Linux section |
| 98 | spec: oci.Spec{ |
| 99 | Linux: &specs.Linux{}, |
| 100 | }, |
| 101 | gid: 0, |
| 102 | }, { |
| 103 | // empty ID mappings |
| 104 | spec: oci.Spec{ |
| 105 | Linux: &specs.Linux{ |
| 106 | GIDMappings: make([]specs.LinuxIDMapping, 0), |
| 107 | }, |
| 108 | }, |
| 109 | gid: 0, |
| 110 | }, { |
| 111 | // valid ID mapping |
| 112 | spec: oci.Spec{ |
| 113 | Linux: &specs.Linux{ |
| 114 | GIDMappings: []specs.LinuxIDMapping{{ |
| 115 | ContainerID: 0, |
| 116 | HostID: 1000, |
| 117 | }}, |
| 118 | }, |
| 119 | }, |
| 120 | gid: 1000, |
| 121 | }, { |
| 122 | // missing ID mapping |
| 123 | spec: oci.Spec{ |
| 124 | Linux: &specs.Linux{ |
| 125 | GIDMappings: []specs.LinuxIDMapping{{ |
| 126 | ContainerID: 100, |
| 127 | HostID: 1000, |
| 128 | }}, |
| 129 | }, |
| 130 | }, |
| 131 | gid: 0, |
| 132 | }} |
| 133 | |
| 134 | for i, tc := range tests { |
| 135 | t.Run(strconv.Itoa(i), func(t *testing.T) { |
| 136 | s, err := json.Marshal(tc.spec) |
| 137 | require.NoError(t, err, "failed to marshal spec") |
| 138 | gid, err := remappedGID(s) |
| 139 | assert.NoError(t, err, "should unmarshal successfully") |
| 140 | assert.Equal(t, tc.gid, gid, "expected GID to match") |
| 141 | }) |
| 142 | } |
| 143 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…