public void IngressClassDeleted()
    {
        // Arrange
        var ingressClass = KubeResourceGenerator.CreateIngressClass("yarp", "microsoft.com/ingress-yarp", true);
        var ingress      = KubeResourceGenerator.CreateIngress("ingress-with-class", "ns-test", "yarp");

        _cacheUnderTest.Update(WatchEventType.Added, ingressClass);

        // Act
        _cacheUnderTest.Update(WatchEventType.Deleted, ingressClass);
        _cacheUnderTest.Update(WatchEventType.Added, ingress);

        // Assert
        var ingresses = _cacheUnderTest.GetIngresses().ToArray();

        Assert.Empty(ingresses);
    }
    public void IngressClassModifiedToAddDefault()
    {
        // Arrange
        var ingressClass = KubeResourceGenerator.CreateIngressClass("yarp", "microsoft.com/ingress-yarp", false);
        var ingress      = KubeResourceGenerator.CreateIngress("ingress-with-class", "ns-test", "yarp");

        _cacheUnderTest.Update(WatchEventType.Added, ingressClass);

        // Act
        ingressClass.Metadata.Annotations.Add("ingressclass.kubernetes.io/is-default-class", "true");

        _cacheUnderTest.Update(WatchEventType.Modified, ingressClass);
        _cacheUnderTest.Update(WatchEventType.Added, ingress);

        // Assert
        var ingresses = _cacheUnderTest.GetIngresses().ToArray();

        Assert.Single(ingresses);
    }
    public void IngressModifiedToRemoveClass()
    {
        // Arrange
        var ingressClass = KubeResourceGenerator.CreateIngressClass("yarp", "microsoft.com/ingress-yarp", false);

        _cacheUnderTest.Update(WatchEventType.Added, ingressClass);

        var ingress = KubeResourceGenerator.CreateIngress("ingress-with-class", "ns-test", "yarp");

        _cacheUnderTest.Update(WatchEventType.Added, ingress);

        // Act
        ingress.Spec.IngressClassName = null;
        _cacheUnderTest.Update(WatchEventType.Modified, ingress);

        // Assert
        var ingresses = _cacheUnderTest.GetIngresses().ToArray();

        Assert.Empty(ingresses);
    }
    public void IngressWithoutClassAnnotationTests(string ingressClassName, string controllerName, bool?isDefault, int expectedIngressCount)
    {
        // Arrange
        if (controllerName is not null)
        {
            var ingressClass = KubeResourceGenerator.CreateIngressClass(ingressClassName, controllerName, isDefault);
            _cacheUnderTest.Update(WatchEventType.Added, ingressClass);
        }

        var ingress = KubeResourceGenerator.CreateIngress("ingress-without-class", "ns-test", null);

        // Act
        var change = _cacheUnderTest.Update(WatchEventType.Added, ingress);

        // Assert
        var ingresses = _cacheUnderTest.GetIngresses().ToArray();

        Assert.Equal(expectedIngressCount != 0, change);
        Assert.Equal(expectedIngressCount, ingresses.Length);
    }
    public async Task ParsingTests(string name)
    {
        var ingressClass = KubeResourceGenerator.CreateIngressClass("yarp", "microsoft.com/ingress-yarp", true);
        var cache        = await GetKubernetesInfo(name, ingressClass).ConfigureAwait(false);

        var configContext = new YarpConfigContext();
        var ingresses     = cache.GetIngresses().ToArray();

        foreach (var ingress in ingresses)
        {
            if (cache.TryGetReconcileData(new NamespacedName(ingress.Metadata.NamespaceProperty, ingress.Metadata.Name), out var data))
            {
                var ingressContext = new YarpIngressContext(ingress, data.ServiceList, data.EndpointsList);
                YarpParser.ConvertFromKubernetesIngress(ingressContext, configContext);
            }
        }
        var options = new JsonSerializerOptions {
            Converters = { new JsonStringEnumConverter() }
        };

        VerifyClusters(JsonSerializer.Serialize(configContext.BuildClusterConfig(), options), name);
        VerifyRoutes(JsonSerializer.Serialize(configContext.Routes, options), name);
    }