Skip to content

Commit acf5e0b

Browse files
committed
Fix linter issues on the new tests
1 parent bb44a22 commit acf5e0b

4 files changed

Lines changed: 76 additions & 77 deletions

File tree

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ linters:
119119
- mnd
120120
- revive
121121
- staticcheck
122+
- dupl
122123
path: _test\.go
123124
- path: pkg/golinters/errcheck.go
124125
text: 'SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead'
@@ -144,6 +145,7 @@ linters:
144145
- third_party$
145146
- builtin$
146147
- examples$
148+
- console/node_modules
147149
formatters:
148150
enable:
149151
- gofmt
@@ -166,3 +168,4 @@ formatters:
166168
- third_party$
167169
- builtin$
168170
- examples$
171+
- console/node_modules

internal/controller/argo_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ var _ = Describe("SyncApplication", func() {
12451245
},
12461246
}
12471247
err := syncApplication(argocdclient, app, true)
1248-
Expect(err).To(BeNil())
1248+
Expect(err).ToNot(HaveOccurred())
12491249
})
12501250
})
12511251

@@ -1669,12 +1669,12 @@ var _ = Describe("GetSharedValueFiles", func() {
16691669
},
16701670
},
16711671
Status: api.PatternStatus{
1672-
ClusterPlatform: "AWS",
1673-
ClusterVersion: "4.12",
1674-
ClusterName: "barcluster",
1675-
AppClusterDomain: "apps.hub.example.com",
1676-
ClusterDomain: "hub.example.com",
1677-
LocalCheckoutPath: td,
1672+
ClusterPlatform: "AWS",
1673+
ClusterVersion: "4.12",
1674+
ClusterName: "barcluster",
1675+
AppClusterDomain: "apps.hub.example.com",
1676+
ClusterDomain: "hub.example.com",
1677+
LocalCheckoutPath: td,
16781678
},
16791679
}
16801680
})
@@ -1694,7 +1694,7 @@ var _ = Describe("GetSharedValueFiles", func() {
16941694
Context("when there are no sharedValueFiles in the values", func() {
16951695
It("should return nil", func() {
16961696
// Create empty values file
1697-
err := os.WriteFile(filepath.Join(td, "values-global.yaml"), []byte("key: value\n"), 0644)
1697+
err := os.WriteFile(filepath.Join(td, "values-global.yaml"), []byte("key: value\n"), 0600)
16981698
Expect(err).ToNot(HaveOccurred())
16991699

17001700
result, err := getSharedValueFiles(pattern, "")
@@ -1709,7 +1709,7 @@ var _ = Describe("GetSharedValueFiles", func() {
17091709
sharedValueFiles:
17101710
- /values-shared.yaml
17111711
`
1712-
err := os.WriteFile(filepath.Join(td, "values-global.yaml"), []byte(yamlContent), 0644)
1712+
err := os.WriteFile(filepath.Join(td, "values-global.yaml"), []byte(yamlContent), 0600)
17131713
Expect(err).ToNot(HaveOccurred())
17141714

17151715
result, err := getSharedValueFiles(pattern, "")
@@ -1739,12 +1739,12 @@ var _ = Describe("CountVPApplications", func() {
17391739
},
17401740
},
17411741
Status: api.PatternStatus{
1742-
ClusterPlatform: "AWS",
1743-
ClusterVersion: "4.12",
1744-
ClusterName: "barcluster",
1745-
AppClusterDomain: "apps.hub.example.com",
1746-
ClusterDomain: "hub.example.com",
1747-
LocalCheckoutPath: td,
1742+
ClusterPlatform: "AWS",
1743+
ClusterVersion: "4.12",
1744+
ClusterName: "barcluster",
1745+
AppClusterDomain: "apps.hub.example.com",
1746+
ClusterDomain: "hub.example.com",
1747+
LocalCheckoutPath: td,
17481748
},
17491749
}
17501750
})
@@ -1764,7 +1764,7 @@ var _ = Describe("CountVPApplications", func() {
17641764

17651765
Context("when there are no applications defined", func() {
17661766
It("should return 0, 0", func() {
1767-
err := os.WriteFile(filepath.Join(td, "values-global.yaml"), []byte("key: value\n"), 0644)
1767+
err := os.WriteFile(filepath.Join(td, "values-global.yaml"), []byte("key: value\n"), 0600)
17681768
Expect(err).ToNot(HaveOccurred())
17691769

17701770
apps, appsets, err := countVPApplications(pattern)
@@ -1786,7 +1786,7 @@ var _ = Describe("CountVPApplications", func() {
17861786
generators:
17871787
- generator1
17881788
`
1789-
err := os.WriteFile(filepath.Join(td, "values-global.yaml"), []byte(yamlContent), 0644)
1789+
err := os.WriteFile(filepath.Join(td, "values-global.yaml"), []byte(yamlContent), 0600)
17901790
Expect(err).ToNot(HaveOccurred())
17911791

17921792
apps, appsets, err := countVPApplications(pattern)

internal/controller/utils_test.go

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,16 @@ var _ = Describe("getHTTPSTransport", func() {
13341334
Namespace: "openshift-config-managed",
13351335
},
13361336
Data: map[string]string{
1337-
"ca.crt": "-----BEGIN CERTIFICATE-----\nMIIBhTCCASugAwIBAgIQIRi6zePL6mKjOipn+dNuaTAKBggqhkjOPQQDAjASMRAw\nDgYDVQQKEwdBY21lIENvMB4XDTE3MTAyMDE5NDMwNloXDTE4MTAyMDE5NDMwNlow\nEjEQMA4GA1UEChMHQWNtZSBDbzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABLU3\njSayahkJYT5/UqIqViZFMVh16yrQ1mOA8V/k3H8Pk/DL1tJ1yXYEptzhKELNJIjp\nzUv0jVJHPnLGVaikzlKjYzBhMA4GA1UdDwEB/wQEAwICpDATBgNVHSUEDDAKBggr\nBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdEQQiMCCCDmxvY2FsaG9zdDo1\nNDUzgg4xMjcuMC4wLjE6NTQ1MzAKBggqhkjOPQQDAgNIADBFAiEA2wpSek3WdNcr\njSuvziv6OERWSEZObKHVIJl/Cj9SWWECIGB/W0PCjZjKXBzgoW0OzXRiDP/WRxW6\nfrNHC7GJcIqs\n-----END CERTIFICATE-----\n",
1337+
"ca.crt": "-----BEGIN CERTIFICATE-----\n" +
1338+
"MIIBhTCCASugAwIBAgIQIRi6zePL6mKjOipn+dNuaTAKBggqhkjOPQQDAjASMRAw\n" +
1339+
"DgYDVQQKEwdBY21lIENvMB4XDTE3MTAyMDE5NDMwNloXDTE4MTAyMDE5NDMwNlow\n" +
1340+
"EjEQMA4GA1UEChMHQWNtZSBDbzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABLU3\n" +
1341+
"jSayahkJYT5/UqIqViZFMVh16yrQ1mOA8V/k3H8Pk/DL1tJ1yXYEptzhKELNJIjp\n" +
1342+
"zUv0jVJHPnLGVaikzlKjYzBhMA4GA1UdDwEB/wQEAwICpDATBgNVHSUEDDAKBggr\n" +
1343+
"BgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdEQQiMCCCDmxvY2FsaG9zdDo1\n" +
1344+
"NDUzgg4xMjcuMC4wLjE6NTQ1MzAKBggqhkjOPQQDAgNIADBFAiEA2wpSek3WdNcr\n" +
1345+
"jSuvziv6OERWSEZObKHVIJl/Cj9SWWECIGB/W0PCjZjKXBzgoW0OzXRiDP/WRxW6\n" +
1346+
"frNHC7GJcIqs\n-----END CERTIFICATE-----\n",
13381347
},
13391348
}
13401349
_, err := kubeClient.CoreV1().ConfigMaps("openshift-config-managed").Create(context.TODO(), cm, metav1.CreateOptions{})
@@ -1396,7 +1405,7 @@ var _ = Describe("GenerateRandomPassword", func() {
13961405
Expect(err).ToNot(HaveOccurred())
13971406
Expect(password).ToNot(BeEmpty())
13981407
// base64 encoded 15 bytes = 20 chars
1399-
Expect(len(password)).To(Equal(20))
1408+
Expect(password).To(HaveLen(20))
14001409
})
14011410
})
14021411

@@ -1477,7 +1486,7 @@ var _ = Describe("writeConfigMapKeyToFile", func() {
14771486
Expect(err).ToNot(HaveOccurred())
14781487

14791488
filePath := filepath.Join(td, "ca.crt")
1480-
err = os.WriteFile(filePath, []byte("existing-data\n"), 0644)
1489+
err = os.WriteFile(filePath, []byte("existing-data\n"), 0600)
14811490
Expect(err).ToNot(HaveOccurred())
14821491

14831492
err = writeConfigMapKeyToFile(kubeClient, "test-ns", "test-cm", "ca.crt", filePath, true)
@@ -1664,7 +1673,7 @@ var _ = Describe("getClusterWideArgoNamespace", func() {
16641673
})
16651674
})
16661675

1667-
var _ = Describe("getPatternConditionByStatus", func() {
1676+
var _ = Describe("Pattern condition search functions", func() {
16681677
var conditions []api.PatternCondition
16691678

16701679
BeforeEach(func() {
@@ -1680,70 +1689,57 @@ var _ = Describe("getPatternConditionByStatus", func() {
16801689
}
16811690
})
16821691

1683-
Context("when conditions is nil", func() {
1684-
It("should return -1 and nil", func() {
1685-
idx, cond := getPatternConditionByStatus(nil, corev1.ConditionTrue)
1686-
Expect(idx).To(Equal(-1))
1687-
Expect(cond).To(BeNil())
1692+
Describe("getPatternConditionByStatus", func() {
1693+
Context("when conditions is nil", func() {
1694+
It("should return -1 and nil", func() {
1695+
idx, cond := getPatternConditionByStatus(nil, corev1.ConditionTrue)
1696+
Expect(idx).To(Equal(-1))
1697+
Expect(cond).To(BeNil())
1698+
})
16881699
})
1689-
})
16901700

1691-
Context("when condition exists", func() {
1692-
It("should return the index and condition", func() {
1693-
idx, cond := getPatternConditionByStatus(conditions, corev1.ConditionTrue)
1694-
Expect(idx).To(Equal(0))
1695-
Expect(cond).ToNot(BeNil())
1696-
Expect(cond.Type).To(Equal(api.Synced))
1701+
Context("when condition exists", func() {
1702+
It("should return the index and condition", func() {
1703+
idx, cond := getPatternConditionByStatus(conditions, corev1.ConditionTrue)
1704+
Expect(idx).To(Equal(0))
1705+
Expect(cond).ToNot(BeNil())
1706+
Expect(cond.Type).To(Equal(api.Synced))
1707+
})
16971708
})
1698-
})
16991709

1700-
Context("when condition does not exist", func() {
1701-
It("should return -1 and nil", func() {
1702-
idx, cond := getPatternConditionByStatus(conditions, corev1.ConditionUnknown)
1703-
Expect(idx).To(Equal(-1))
1704-
Expect(cond).To(BeNil())
1710+
Context("when condition does not exist", func() {
1711+
It("should return -1 and nil", func() {
1712+
idx, cond := getPatternConditionByStatus(conditions, corev1.ConditionUnknown)
1713+
Expect(idx).To(Equal(-1))
1714+
Expect(cond).To(BeNil())
1715+
})
17051716
})
17061717
})
1707-
})
1708-
1709-
var _ = Describe("getPatternConditionByType", func() {
1710-
var conditions []api.PatternCondition
1711-
1712-
BeforeEach(func() {
1713-
conditions = []api.PatternCondition{
1714-
{
1715-
Type: api.Synced,
1716-
Status: corev1.ConditionTrue,
1717-
},
1718-
{
1719-
Type: api.Degraded,
1720-
Status: corev1.ConditionFalse,
1721-
},
1722-
}
1723-
})
17241718

1725-
Context("when conditions is nil", func() {
1726-
It("should return -1 and nil", func() {
1727-
idx, cond := getPatternConditionByType(nil, api.Synced)
1728-
Expect(idx).To(Equal(-1))
1729-
Expect(cond).To(BeNil())
1719+
Describe("getPatternConditionByType", func() {
1720+
Context("when conditions is nil", func() {
1721+
It("should return -1 and nil", func() {
1722+
idx, cond := getPatternConditionByType(nil, api.Synced)
1723+
Expect(idx).To(Equal(-1))
1724+
Expect(cond).To(BeNil())
1725+
})
17301726
})
1731-
})
17321727

1733-
Context("when condition type exists", func() {
1734-
It("should return the index and condition", func() {
1735-
idx, cond := getPatternConditionByType(conditions, api.Degraded)
1736-
Expect(idx).To(Equal(1))
1737-
Expect(cond).ToNot(BeNil())
1738-
Expect(cond.Status).To(Equal(corev1.ConditionFalse))
1728+
Context("when condition type exists", func() {
1729+
It("should return the index and condition", func() {
1730+
idx, cond := getPatternConditionByType(conditions, api.Degraded)
1731+
Expect(idx).To(Equal(1))
1732+
Expect(cond).ToNot(BeNil())
1733+
Expect(cond.Status).To(Equal(corev1.ConditionFalse))
1734+
})
17391735
})
1740-
})
17411736

1742-
Context("when condition type does not exist", func() {
1743-
It("should return -1 and nil", func() {
1744-
idx, cond := getPatternConditionByType(conditions, api.Unknown)
1745-
Expect(idx).To(Equal(-1))
1746-
Expect(cond).To(BeNil())
1737+
Context("when condition type does not exist", func() {
1738+
It("should return -1 and nil", func() {
1739+
idx, cond := getPatternConditionByType(conditions, api.Unknown)
1740+
Expect(idx).To(Equal(-1))
1741+
Expect(cond).To(BeNil())
1742+
})
17471743
})
17481744
})
17491745
})

internal/controller/values_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ var _ = Describe("MergeHelmValues", func() {
248248
It("should merge values from multiple files", func() {
249249
file1 := filepath.Join(td, "values1.yaml")
250250
file2 := filepath.Join(td, "values2.yaml")
251-
err := os.WriteFile(file1, []byte("key1: value1\nshared: from-file1\n"), 0644)
251+
err := os.WriteFile(file1, []byte("key1: value1\nshared: from-file1\n"), 0600)
252252
Expect(err).ToNot(HaveOccurred())
253-
err = os.WriteFile(file2, []byte("key2: value2\nshared: from-file2\n"), 0644)
253+
err = os.WriteFile(file2, []byte("key2: value2\nshared: from-file2\n"), 0600)
254254
Expect(err).ToNot(HaveOccurred())
255255

256256
result, err := mergeHelmValues(file1, file2)
@@ -265,7 +265,7 @@ var _ = Describe("MergeHelmValues", func() {
265265
Context("with invalid YAML file", func() {
266266
It("should return an error", func() {
267267
file := filepath.Join(td, "invalid.yaml")
268-
err := os.WriteFile(file, []byte("{{invalid yaml}}"), 0644)
268+
err := os.WriteFile(file, []byte("{{invalid yaml}}"), 0600)
269269
Expect(err).ToNot(HaveOccurred())
270270

271271
_, err = mergeHelmValues(file)

0 commit comments

Comments
 (0)