(t *testing.T)
| 207 | } |
| 208 | |
| 209 | func TestAttributesRelativeAttrConditional(t *testing.T) { |
| 210 | reg := newTestRegistry(t) |
| 211 | attrs := NewAttributeFactory(containers.DefaultContainer, reg, reg) |
| 212 | data := map[string]any{ |
| 213 | "a": map[int]any{ |
| 214 | -1: []int32{2, 42}, |
| 215 | }, |
| 216 | "b": []int{0, 1}, |
| 217 | "c": []any{1, 0}, |
| 218 | } |
| 219 | vars, _ := NewActivation(data) |
| 220 | |
| 221 | // The relative attribute under test is applied to a map literal: |
| 222 | // { |
| 223 | // a: {-1: [2, 42], b: 1} |
| 224 | // b: [0, 1], |
| 225 | // c: {1, 0}, |
| 226 | // } |
| 227 | // |
| 228 | // The expression being evaluated is: |
| 229 | // <map-literal>.a[-1][(false ? b : c)[0]] -> 42 |
| 230 | // |
| 231 | // Effectively the same as saying <map-literal>.a[-1][c[0]] |
| 232 | cond := NewConstValue(2, types.False) |
| 233 | condAttr := attrs.ConditionalAttribute(4, cond, |
| 234 | attrs.AbsoluteAttribute(5, "b"), |
| 235 | attrs.AbsoluteAttribute(6, "c")) |
| 236 | qual0 := makeQualifier(t, attrs, nil, 7, 0) |
| 237 | condAttr.AddQualifier(qual0) |
| 238 | |
| 239 | obj := NewConstValue(1, reg.NativeToValue(data)) |
| 240 | attr := attrs.RelativeAttribute(1, obj) |
| 241 | qualA := makeQualifier(t, attrs, nil, 2, "a") |
| 242 | qualNeg1 := makeQualifier(t, attrs, nil, 3, int64(-1)) |
| 243 | attr.AddQualifier(qualA) |
| 244 | attr.AddQualifier(qualNeg1) |
| 245 | attr.AddQualifier(condAttr) |
| 246 | out, err := attr.Resolve(vars) |
| 247 | if err != nil { |
| 248 | t.Fatal(err) |
| 249 | } |
| 250 | if out != types.Int(42) { |
| 251 | t.Errorf("Got %v (%T), wanted 42", out, out) |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | func TestAttributesRelativeAttrRelativeQualifier(t *testing.T) { |
| 256 | cont, err := containers.NewContainer(containers.Name("acme.ns")) |
nothing calls this directly
no test coverage detected