factory

package
v0.0.0-...-87ef7df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MySQLBackupInstanceFactory = def.NewFactory(crv1.MySQLBackupInstance{}, "",
	def.DynamicField("Spec.Schedule", func(model interface{}) (interface{}, error) {
		return fmt.Sprintf("backup-%s", randomdata.RandStringRunes(16)), nil
	}),
	def.Field("Status.Phase", crv1.MySQLBackupScheduled),
	def.Field("ObjectMeta.Namespace", "default"),
	def.AfterBuild(func(model interface{}) error {
		instance, ok := model.(*crv1.MySQLBackupInstance)
		if !ok {
			return fmt.Errorf("invalid type of model in ObjectMeta.Name function")
		}

		minute := randomdata.Number(0, 59)
		hour := randomdata.Number(0, 23)
		day := randomdata.Number(1, 31)
		month := randomdata.Number(1, 12)
		year := randomdata.Number(1900, 3000)
		date := fmt.Sprintf("%d-%02d-%02d-%02d-%02d", year, month, day, hour, minute)

		instance.Name = fmt.Sprintf("%s-%s", instance.Spec.Schedule, date)
		return nil
	}),
)

MySQLBackupInstanceFactory generates a Backup instance schedule with random data for testing.

View Source
var MySQLBackupScheduleFactory = def.NewFactory(crv1.MySQLBackupSchedule{}, "",
	def.DynamicField("ObjectMeta.Name", func(model interface{}) (interface{}, error) {
		return fmt.Sprintf("backup-%s", randomdata.RandStringRunes(16)), nil
	}),
	def.Field("ObjectMeta.Namespace", "default"),
	def.DynamicField("Spec.Time", func(model interface{}) (interface{}, error) {
		minute := randomAny(randomdata.Number(0, 59))
		hour := randomAny(randomdata.Number(0, 23))
		day := randomAny(randomdata.Number(1, 31))
		month := randomAny(randomdata.Number(1, 12))
		weekday := randomAny(randomdata.Number(1, 7))
		year := randomAny(randomdata.Number(1900, 3000))
		return fmt.Sprintf("%s %s %s %s %s %s", minute, hour, day, month, weekday, year), nil
	}),
	def.Trait("ChangeDefaults",
		def.Field("Spec.Storage", resource.MustParse("1Gi")),
	),
)

MySQLBackupScheduleFactory generates a backupschedule schedule with random data for testing.

View Source
var MySQLClusterFactory = def.NewFactory(crv1.MySQLCluster{}, "",
	def.DynamicField("ObjectMeta.Name", func(model interface{}) (interface{}, error) {
		return fmt.Sprintf("cluster-%s", randomdata.RandStringRunes(16)), nil
	}),
	def.Field("ObjectMeta.Namespace", "default"),
	def.DynamicField("Spec.Secret", func(model interface{}) (interface{}, error) {
		cluster, ok := model.(*crv1.MySQLCluster)
		if !ok {
			return nil, fmt.Errorf("invalid type of model in Spec.Secret function")
		}
		return fmt.Sprintf("%s-secret", cluster.Name), nil
	}),
	def.Field("Spec.Storage", resource.MustParse("1Gi")),
	def.Trait("ChangeDefaults",
		def.DynamicField("Spec.Replicas", func(model interface{}) (interface{}, error) {
			return int32(randomdata.Number(3, 1<<8)), nil
		}),
		def.DynamicField("Spec.Port", func(model interface{}) (interface{}, error) {
			return int32(randomdata.Number(1<<12, 1<<16)), nil
		}),
		def.DynamicField("Spec.Image", func(model interface{}) (interface{}, error) {
			major := randomdata.Number(1, 10)
			minor := randomdata.Number(1, 10)
			return fmt.Sprintf("mysql:v%d.%d", major, minor), nil
		}),
	),
)

MySQLClusterFactory generates cluster with random data for testing.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL