// Code generated by azure-service-operator-codegen. DO NOT EDIT.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package arm

import (
	"encoding/json"
	"github.com/google/go-cmp/cmp"
	"github.com/google/go-cmp/cmp/cmpopts"
	"github.com/kr/pretty"
	"github.com/kylelemons/godebug/diff"
	"github.com/leanovate/gopter"
	"github.com/leanovate/gopter/gen"
	"github.com/leanovate/gopter/prop"
	"os"
	"reflect"
	"testing"
)

func Test_PrometheusRule_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 100
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of PrometheusRule via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPrometheusRule, PrometheusRuleGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForPrometheusRule runs a test to see if a specific instance of PrometheusRule round trips to JSON and back losslessly
func RunJSONSerializationTestForPrometheusRule(subject PrometheusRule) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual PrometheusRule
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of PrometheusRule instances for property testing - lazily instantiated by PrometheusRuleGenerator()
var prometheusRuleGenerator gopter.Gen

// PrometheusRuleGenerator returns a generator of PrometheusRule instances for property testing.
// We first initialize prometheusRuleGenerator with a simplified generator based on the
// fields with primitive types then replacing it with a more complex one that also handles complex fields
// to ensure any cycles in the object graph properly terminate.
func PrometheusRuleGenerator() gopter.Gen {
	if prometheusRuleGenerator != nil {
		return prometheusRuleGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPrometheusRule(generators)
	prometheusRuleGenerator = gen.Struct(reflect.TypeOf(PrometheusRule{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPrometheusRule(generators)
	AddRelatedPropertyGeneratorsForPrometheusRule(generators)
	prometheusRuleGenerator = gen.Struct(reflect.TypeOf(PrometheusRule{}), generators)

	return prometheusRuleGenerator
}

// AddIndependentPropertyGeneratorsForPrometheusRule is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPrometheusRule(gens map[string]gopter.Gen) {
	gens["Alert"] = gen.PtrOf(gen.AlphaString())
	gens["Annotations"] = gen.MapOf(
		gen.AlphaString(),
		gen.AlphaString())
	gens["Enabled"] = gen.PtrOf(gen.Bool())
	gens["Expression"] = gen.PtrOf(gen.AlphaString())
	gens["For"] = gen.PtrOf(gen.AlphaString())
	gens["Labels"] = gen.MapOf(
		gen.AlphaString(),
		gen.AlphaString())
	gens["Record"] = gen.PtrOf(gen.AlphaString())
	gens["Severity"] = gen.PtrOf(gen.Int())
}

// AddRelatedPropertyGeneratorsForPrometheusRule is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForPrometheusRule(gens map[string]gopter.Gen) {
	gens["Actions"] = gen.SliceOf(PrometheusRuleGroupActionGenerator())
	gens["ResolveConfiguration"] = gen.PtrOf(PrometheusRuleResolveConfigurationGenerator())
}

func Test_PrometheusRuleGroupAction_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 100
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of PrometheusRuleGroupAction via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroupAction, PrometheusRuleGroupActionGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForPrometheusRuleGroupAction runs a test to see if a specific instance of PrometheusRuleGroupAction round trips to JSON and back losslessly
func RunJSONSerializationTestForPrometheusRuleGroupAction(subject PrometheusRuleGroupAction) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual PrometheusRuleGroupAction
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of PrometheusRuleGroupAction instances for property testing - lazily instantiated by
// PrometheusRuleGroupActionGenerator()
var prometheusRuleGroupActionGenerator gopter.Gen

// PrometheusRuleGroupActionGenerator returns a generator of PrometheusRuleGroupAction instances for property testing.
func PrometheusRuleGroupActionGenerator() gopter.Gen {
	if prometheusRuleGroupActionGenerator != nil {
		return prometheusRuleGroupActionGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction(generators)
	prometheusRuleGroupActionGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupAction{}), generators)

	return prometheusRuleGroupActionGenerator
}

// AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction(gens map[string]gopter.Gen) {
	gens["ActionGroupId"] = gen.PtrOf(gen.AlphaString())
	gens["ActionProperties"] = gen.MapOf(
		gen.AlphaString(),
		gen.AlphaString())
}

func Test_PrometheusRuleGroupProperties_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 100
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of PrometheusRuleGroupProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroupProperties, PrometheusRuleGroupPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForPrometheusRuleGroupProperties runs a test to see if a specific instance of PrometheusRuleGroupProperties round trips to JSON and back losslessly
func RunJSONSerializationTestForPrometheusRuleGroupProperties(subject PrometheusRuleGroupProperties) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual PrometheusRuleGroupProperties
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of PrometheusRuleGroupProperties instances for property testing - lazily instantiated by
// PrometheusRuleGroupPropertiesGenerator()
var prometheusRuleGroupPropertiesGenerator gopter.Gen

// PrometheusRuleGroupPropertiesGenerator returns a generator of PrometheusRuleGroupProperties instances for property testing.
// We first initialize prometheusRuleGroupPropertiesGenerator with a simplified generator based on the
// fields with primitive types then replacing it with a more complex one that also handles complex fields
// to ensure any cycles in the object graph properly terminate.
func PrometheusRuleGroupPropertiesGenerator() gopter.Gen {
	if prometheusRuleGroupPropertiesGenerator != nil {
		return prometheusRuleGroupPropertiesGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties(generators)
	prometheusRuleGroupPropertiesGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupProperties{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties(generators)
	AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties(generators)
	prometheusRuleGroupPropertiesGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupProperties{}), generators)

	return prometheusRuleGroupPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties(gens map[string]gopter.Gen) {
	gens["ClusterName"] = gen.PtrOf(gen.AlphaString())
	gens["Description"] = gen.PtrOf(gen.AlphaString())
	gens["Enabled"] = gen.PtrOf(gen.Bool())
	gens["Interval"] = gen.PtrOf(gen.AlphaString())
	gens["Scopes"] = gen.SliceOf(gen.AlphaString())
}

// AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties(gens map[string]gopter.Gen) {
	gens["Rules"] = gen.SliceOf(PrometheusRuleGenerator())
}

func Test_PrometheusRuleGroup_Spec_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 80
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of PrometheusRuleGroup_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroup_Spec, PrometheusRuleGroup_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForPrometheusRuleGroup_Spec runs a test to see if a specific instance of PrometheusRuleGroup_Spec round trips to JSON and back losslessly
func RunJSONSerializationTestForPrometheusRuleGroup_Spec(subject PrometheusRuleGroup_Spec) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual PrometheusRuleGroup_Spec
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of PrometheusRuleGroup_Spec instances for property testing - lazily instantiated by
// PrometheusRuleGroup_SpecGenerator()
var prometheusRuleGroup_SpecGenerator gopter.Gen

// PrometheusRuleGroup_SpecGenerator returns a generator of PrometheusRuleGroup_Spec instances for property testing.
// We first initialize prometheusRuleGroup_SpecGenerator with a simplified generator based on the
// fields with primitive types then replacing it with a more complex one that also handles complex fields
// to ensure any cycles in the object graph properly terminate.
func PrometheusRuleGroup_SpecGenerator() gopter.Gen {
	if prometheusRuleGroup_SpecGenerator != nil {
		return prometheusRuleGroup_SpecGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPrometheusRuleGroup_Spec(generators)
	prometheusRuleGroup_SpecGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroup_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPrometheusRuleGroup_Spec(generators)
	AddRelatedPropertyGeneratorsForPrometheusRuleGroup_Spec(generators)
	prometheusRuleGroup_SpecGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroup_Spec{}), generators)

	return prometheusRuleGroup_SpecGenerator
}

// AddIndependentPropertyGeneratorsForPrometheusRuleGroup_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPrometheusRuleGroup_Spec(gens map[string]gopter.Gen) {
	gens["Location"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.AlphaString()
	gens["Tags"] = gen.MapOf(
		gen.AlphaString(),
		gen.AlphaString())
}

// AddRelatedPropertyGeneratorsForPrometheusRuleGroup_Spec is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForPrometheusRuleGroup_Spec(gens map[string]gopter.Gen) {
	gens["Properties"] = gen.PtrOf(PrometheusRuleGroupPropertiesGenerator())
}

func Test_PrometheusRuleResolveConfiguration_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 100
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of PrometheusRuleResolveConfiguration via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPrometheusRuleResolveConfiguration, PrometheusRuleResolveConfigurationGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForPrometheusRuleResolveConfiguration runs a test to see if a specific instance of PrometheusRuleResolveConfiguration round trips to JSON and back losslessly
func RunJSONSerializationTestForPrometheusRuleResolveConfiguration(subject PrometheusRuleResolveConfiguration) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual PrometheusRuleResolveConfiguration
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of PrometheusRuleResolveConfiguration instances for property testing - lazily instantiated by
// PrometheusRuleResolveConfigurationGenerator()
var prometheusRuleResolveConfigurationGenerator gopter.Gen

// PrometheusRuleResolveConfigurationGenerator returns a generator of PrometheusRuleResolveConfiguration instances for property testing.
func PrometheusRuleResolveConfigurationGenerator() gopter.Gen {
	if prometheusRuleResolveConfigurationGenerator != nil {
		return prometheusRuleResolveConfigurationGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration(generators)
	prometheusRuleResolveConfigurationGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleResolveConfiguration{}), generators)

	return prometheusRuleResolveConfigurationGenerator
}

// AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration(gens map[string]gopter.Gen) {
	gens["AutoResolved"] = gen.PtrOf(gen.Bool())
	gens["TimeToResolve"] = gen.PtrOf(gen.AlphaString())
}
