@@ -1747,3 +1747,123 @@ func TestNewRunnerJobPLZTestRun(t *testing.T) {
1747
1747
t .Errorf ("NewRunnerJob returned unexpected data, diff: %s" , diff )
1748
1748
}
1749
1749
}
1750
+
1751
+ func TestNewRunnerJobPriorityClassName (t * testing.T ) {
1752
+
1753
+ script := & types.Script {
1754
+ Name : "test" ,
1755
+ Filename : "thing.js" ,
1756
+ Type : "ConfigMap" ,
1757
+ }
1758
+
1759
+ var zero int64 = 0
1760
+ automountServiceAccountToken := true
1761
+
1762
+ expectedLabels := map [string ]string {
1763
+ "app" : "k6" ,
1764
+ "k6_cr" : "test" ,
1765
+ "runner" : "true" ,
1766
+ "label1" : "awesome" ,
1767
+ }
1768
+
1769
+ expectedOutcome := & batchv1.Job {
1770
+ ObjectMeta : metav1.ObjectMeta {
1771
+ Name : "test-1" ,
1772
+ Namespace : "test" ,
1773
+ Labels : expectedLabels ,
1774
+ Annotations : map [string ]string {
1775
+ "awesomeAnnotation" : "dope" ,
1776
+ },
1777
+ },
1778
+ Spec : batchv1.JobSpec {
1779
+ BackoffLimit : new (int32 ),
1780
+ Template : corev1.PodTemplateSpec {
1781
+ ObjectMeta : metav1.ObjectMeta {
1782
+ Labels : expectedLabels ,
1783
+ Annotations : map [string ]string {
1784
+ "awesomeAnnotation" : "dope" ,
1785
+ },
1786
+ },
1787
+ Spec : corev1.PodSpec {
1788
+ Hostname : "test-1" ,
1789
+ RestartPolicy : corev1 .RestartPolicyNever ,
1790
+ Affinity : nil ,
1791
+ NodeSelector : nil ,
1792
+ Tolerations : nil ,
1793
+ TopologySpreadConstraints : nil ,
1794
+ ServiceAccountName : "default" ,
1795
+ AutomountServiceAccountToken : & automountServiceAccountToken ,
1796
+ SecurityContext : & corev1.PodSecurityContext {},
1797
+ Containers : []corev1.Container {{
1798
+ Image : "grafana/k6:latest" ,
1799
+ ImagePullPolicy : "" ,
1800
+ Name : "k6" ,
1801
+ Command : []string {"k6" , "run" , "--quiet" , "/test/test.js" , "--address=0.0.0.0:6565" , "--paused" , "--tag" , "instance_id=1" , "--tag" , "job_name=test-1" },
1802
+ Env : []corev1.EnvVar {},
1803
+ Resources : corev1.ResourceRequirements {},
1804
+ VolumeMounts : script .VolumeMount (),
1805
+ Ports : []corev1.ContainerPort {{ContainerPort : 6565 }},
1806
+ LivenessProbe : & corev1.Probe {
1807
+ ProbeHandler : corev1.ProbeHandler {
1808
+ HTTPGet : & corev1.HTTPGetAction {
1809
+ Path : "/v1/status" ,
1810
+ Port : intstr.IntOrString {IntVal : 6565 },
1811
+ Scheme : "HTTP" ,
1812
+ },
1813
+ },
1814
+ },
1815
+ ReadinessProbe : & corev1.Probe {
1816
+ ProbeHandler : corev1.ProbeHandler {
1817
+ HTTPGet : & corev1.HTTPGetAction {
1818
+ Path : "/v1/status" ,
1819
+ Port : intstr.IntOrString {IntVal : 6565 },
1820
+ Scheme : "HTTP" ,
1821
+ },
1822
+ },
1823
+ },
1824
+ SecurityContext : & corev1.SecurityContext {},
1825
+ }},
1826
+ TerminationGracePeriodSeconds : & zero ,
1827
+ Volumes : script .Volume (),
1828
+ PriorityClassName : "high-priority" ,
1829
+ },
1830
+ },
1831
+ },
1832
+ }
1833
+
1834
+ k6 := & v1alpha1.TestRun {
1835
+ ObjectMeta : metav1.ObjectMeta {
1836
+ Name : "test" ,
1837
+ Namespace : "test" ,
1838
+ },
1839
+ Spec : v1alpha1.TestRunSpec {
1840
+
1841
+ Script : v1alpha1.K6Script {
1842
+ ConfigMap : v1alpha1.K6Configmap {
1843
+ Name : "test" ,
1844
+ File : "test.js" ,
1845
+ },
1846
+ },
1847
+ Runner : v1alpha1.Pod {
1848
+ Metadata : v1alpha1.PodMetadata {
1849
+ Labels : map [string ]string {
1850
+ "label1" : "awesome" ,
1851
+ },
1852
+ Annotations : map [string ]string {
1853
+ "awesomeAnnotation" : "dope" ,
1854
+ },
1855
+ },
1856
+ PriorityClassName : "high-priority" ,
1857
+ },
1858
+ },
1859
+ }
1860
+
1861
+ job , err := NewRunnerJob (k6 , 1 , cloud .NewTokenInfo ("" , "" ))
1862
+ if err != nil {
1863
+ t .Errorf ("NewRunnerJob errored, got: %v" , err )
1864
+ }
1865
+
1866
+ if diff := deep .Equal (job , expectedOutcome ); diff != nil {
1867
+ t .Errorf ("NewRunnerJob returned unexpected data, diff: %s" , diff )
1868
+ }
1869
+ }
0 commit comments