Skip to content

Commit dd83a0b

Browse files
fix: skipped and failed integration tests and wrong cleanup (#79)
Some of the integration tests happened to work or not because there was a cleanup error. Some tests were always ignored. --------- Signed-off-by: OliverTrautvetter <66372584+OliverTrautvetter@users.noreply.github.com>
1 parent 6049712 commit dd83a0b

File tree

8 files changed

+148
-80
lines changed

8 files changed

+148
-80
lines changed

.github/workflows/integration-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
with:
2121
go-version-file: 'go.mod'
2222

23+
- name: Build CLI
24+
run: make build-cli
25+
2326
- name: Run Integration Tests
2427
env:
2528
OMS_PORTAL_API_KEY: ${{ secrets.OMS_PORTAL_API_KEY }}

NOTICE

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@ Version: v3.5.1
99
License: MIT
1010
License URL: https://github.com/blang/semver/blob/v3.5.1/LICENSE
1111

12+
----------
13+
Module: github.com/clipperhouse/stringish
14+
Version: v0.1.1
15+
License: MIT
16+
License URL: https://github.com/clipperhouse/stringish/blob/v0.1.1/LICENSE
17+
1218
----------
1319
Module: github.com/clipperhouse/uax29/v2
14-
Version: v2.2.0
20+
Version: v2.3.0
1521
License: MIT
16-
License URL: https://github.com/clipperhouse/uax29/blob/v2.2.0/LICENSE
22+
License URL: https://github.com/clipperhouse/uax29/blob/v2.3.0/LICENSE
1723

1824
----------
1925
Module: github.com/codesphere-cloud/cs-go/pkg/io
20-
Version: v0.14.0
26+
Version: v0.14.1
2127
License: Apache-2.0
22-
License URL: https://github.com/codesphere-cloud/cs-go/blob/v0.14.0/LICENSE
28+
License URL: https://github.com/codesphere-cloud/cs-go/blob/v0.14.1/LICENSE
2329

2430
----------
2531
Module: github.com/codesphere-cloud/oms/internal/tmpl
@@ -71,9 +77,9 @@ License URL: https://github.com/inconshreveable/go-update/blob/8152e7eb6ccf/inte
7177

7278
----------
7379
Module: github.com/jedib0t/go-pretty/v6
74-
Version: v6.7.1
80+
Version: v6.7.3
7581
License: MIT
76-
License URL: https://github.com/jedib0t/go-pretty/blob/v6.7.1/LICENSE
82+
License URL: https://github.com/jedib0t/go-pretty/blob/v6.7.3/LICENSE
7783

7884
----------
7985
Module: github.com/mattn/go-runewidth
@@ -113,9 +119,9 @@ License URL: https://github.com/spf13/pflag/blob/v1.0.10/LICENSE
113119

114120
----------
115121
Module: github.com/stretchr/objx
116-
Version: v0.5.2
122+
Version: v0.5.3
117123
License: MIT
118-
License URL: https://github.com/stretchr/objx/blob/v0.5.2/LICENSE
124+
License URL: https://github.com/stretchr/objx/blob/v0.5.3/LICENSE
119125

120126
----------
121127
Module: github.com/stretchr/testify
@@ -137,21 +143,21 @@ License URL: https://github.com/ulikunitz/xz/blob/v0.5.15/LICENSE
137143

138144
----------
139145
Module: golang.org/x/crypto
140-
Version: v0.42.0
146+
Version: v0.45.0
141147
License: BSD-3-Clause
142-
License URL: https://cs.opensource.google/go/x/crypto/+/v0.42.0:LICENSE
148+
License URL: https://cs.opensource.google/go/x/crypto/+/v0.45.0:LICENSE
143149

144150
----------
145151
Module: golang.org/x/oauth2
146-
Version: v0.30.0
152+
Version: v0.33.0
147153
License: BSD-3-Clause
148-
License URL: https://cs.opensource.google/go/x/oauth2/+/v0.30.0:LICENSE
154+
License URL: https://cs.opensource.google/go/x/oauth2/+/v0.33.0:LICENSE
149155

150156
----------
151157
Module: golang.org/x/text
152-
Version: v0.29.0
158+
Version: v0.31.0
153159
License: BSD-3-Clause
154-
License URL: https://cs.opensource.google/go/x/text/+/v0.29.0:LICENSE
160+
License URL: https://cs.opensource.google/go/x/text/+/v0.31.0:LICENSE
155161

156162
----------
157163
Module: gopkg.in/yaml.v3

cli/cmd/api_key_integration_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ var _ = Describe("API Key Integration Tests", func() {
6464
},
6565
}
6666

67+
GinkgoWriter.Printf("Attempting to register API key for owner: %s at API: %s\n", registerCmd.Opts.Owner, os.Getenv("OMS_PORTAL_API"))
6768
newKey, err := registerCmd.Register(portalClient)
69+
if err != nil {
70+
GinkgoWriter.Printf("Registration failed: %v\n", err)
71+
}
6872
Expect(err).To(BeNil(), "API key registration should succeed")
6973
Expect(newKey).NotTo(BeNil(), "Register should return the created API key")
7074

@@ -102,7 +106,12 @@ var _ = Describe("API Key Integration Tests", func() {
102106
},
103107
}
104108

109+
GinkgoWriter.Printf("[DEBUG] Attempting to register API key for owner: %s, org: %s at API: %s\n",
110+
testOwner, testOrg, os.Getenv("OMS_PORTAL_API"))
105111
newKey, err := registerCmd.Register(portalClient)
112+
if err != nil {
113+
GinkgoWriter.Printf("[ERROR] Registration failed: %v\n", err)
114+
}
106115
Expect(err).To(BeNil(), "API key registration should succeed")
107116
Expect(newKey).NotTo(BeNil(), "Register should return the created API key")
108117

@@ -222,18 +231,9 @@ var _ = Describe("API Key Integration Tests", func() {
222231

223232
Describe("Old API Key Detection and Warning", func() {
224233
var (
225-
cliPath string
234+
cliPath = "../../oms-cli"
226235
)
227236

228-
BeforeEach(func() {
229-
cliPath = "./oms-cli"
230-
231-
_, err := os.Stat(cliPath)
232-
if err != nil {
233-
Skip("OMS CLI not found at " + cliPath + ", please build it first with 'make build-cli'")
234-
}
235-
})
236-
237237
Context("when using a 22-character old API key format", func() {
238238
It("should detect the old format and attempt to upgrade", func() {
239239
cmd := exec.Command(cliPath, "version")
@@ -242,8 +242,11 @@ var _ = Describe("API Key Integration Tests", func() {
242242
"OMS_PORTAL_API=http://localhost:3000/api",
243243
)
244244

245-
output, _ := cmd.CombinedOutput()
245+
output, err := cmd.CombinedOutput()
246246
outputStr := string(output)
247+
if err != nil {
248+
GinkgoWriter.Printf("Command error: %v, Output: %s\n", err, outputStr)
249+
}
247250

248251
Expect(outputStr).To(ContainSubstring("OMS CLI version"))
249252
})
@@ -257,8 +260,11 @@ var _ = Describe("API Key Integration Tests", func() {
257260
"OMS_PORTAL_API=http://localhost:3000/api",
258261
)
259262

260-
output, _ := cmd.CombinedOutput()
263+
output, err := cmd.CombinedOutput()
261264
outputStr := string(output)
265+
if err != nil {
266+
GinkgoWriter.Printf("Command error: %v, Output: %s\n", err, outputStr)
267+
}
262268

263269
Expect(outputStr).To(ContainSubstring("OMS CLI version"))
264270
Expect(outputStr).NotTo(ContainSubstring("old API key"))
@@ -304,18 +310,9 @@ var _ = Describe("API Key Integration Tests", func() {
304310

305311
Describe("PreRun Hook Execution", func() {
306312
var (
307-
cliPath string
313+
cliPath = "../../oms-cli"
308314
)
309315

310-
BeforeEach(func() {
311-
cliPath = "./oms-cli"
312-
313-
_, err := os.Stat(cliPath)
314-
if err != nil {
315-
Skip("OMS CLI not found at " + cliPath + ", please build it first with 'make build-cli'")
316-
}
317-
})
318-
319316
Context("when running any OMS command", func() {
320317
It("should execute the PreRun hook", func() {
321318
cmd := exec.Command(cliPath, "version")
@@ -324,8 +321,11 @@ var _ = Describe("API Key Integration Tests", func() {
324321
"OMS_PORTAL_API=http://localhost:3000/api",
325322
)
326323

327-
output, _ := cmd.CombinedOutput()
324+
output, err := cmd.CombinedOutput()
328325
outputStr := string(output)
326+
if err != nil {
327+
GinkgoWriter.Printf("Command error: %v, Output: %s\n", err, outputStr)
328+
}
329329

330330
Expect(outputStr).To(ContainSubstring("OMS CLI version"))
331331
})

cli/cmd/cmd_suite_test.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ var _ = Describe("RootCmd", func() {
3131
mockHttpClient *portal.MockHttpClient
3232
)
3333

34+
safeSetEnv := func(key, value string) {
35+
originalValue, exists := os.LookupEnv(key)
36+
Expect(os.Setenv(key, value)).To(Succeed())
37+
38+
DeferCleanup(func() {
39+
if exists {
40+
Expect(os.Setenv(key, originalValue)).To(Succeed())
41+
} else {
42+
Expect(os.Unsetenv(key)).To(Succeed())
43+
}
44+
})
45+
}
46+
3447
BeforeEach(func() {
3548
mockEnv = env.NewMockEnv(GinkgoT())
3649
mockHttpClient = portal.NewMockHttpClient(GinkgoT())
@@ -48,8 +61,8 @@ var _ = Describe("RootCmd", func() {
4861
keyId := "test-key-id-12345"
4962
expectedNewKey := keyId + oldKey
5063

51-
Expect(os.Setenv("OMS_PORTAL_API_KEY", oldKey)).NotTo(HaveOccurred())
52-
Expect(os.Setenv("OMS_PORTAL_API", "http://test-portal.com/api")).NotTo(HaveOccurred())
64+
safeSetEnv("OMS_PORTAL_API_KEY", oldKey)
65+
safeSetEnv("OMS_PORTAL_API", "http://test-portal.com/api")
5366

5467
mockEnv.EXPECT().GetOmsPortalApi().Return("http://test-portal.com/api")
5568

@@ -80,35 +93,26 @@ var _ = Describe("RootCmd", func() {
8093
// Concatenate on client side
8194
newApiKey := result + oldKey
8295
Expect(newApiKey).To(Equal(expectedNewKey))
83-
84-
Expect(os.Unsetenv("OMS_PORTAL_API_KEY")).NotTo(HaveOccurred())
85-
Expect(os.Unsetenv("OMS_PORTAL_API")).NotTo(HaveOccurred())
8696
})
8797
})
8898

8999
Context("when API key is not 22 characters (new format)", func() {
90100
It("does not attempt to upgrade the key", func() {
91101
newKey := "new-long-api-key-format-very-long-string"
92102

93-
Expect(os.Setenv("OMS_PORTAL_API_KEY", newKey)).NotTo(HaveOccurred())
94-
Expect(os.Setenv("OMS_PORTAL_API", "http://test-portal.com/api")).NotTo(HaveOccurred())
103+
safeSetEnv("OMS_PORTAL_API_KEY", newKey)
104+
safeSetEnv("OMS_PORTAL_API", "http://test-portal.com/api")
95105

96106
Expect(len(newKey)).NotTo(Equal(22))
97-
98-
Expect(os.Unsetenv("OMS_PORTAL_API_KEY")).NotTo(HaveOccurred())
99-
Expect(os.Unsetenv("OMS_PORTAL_API")).NotTo(HaveOccurred())
100107
})
101108
})
102109

103110
Context("when API key is empty", func() {
104111
It("does not attempt to upgrade", func() {
105-
Expect(os.Setenv("OMS_PORTAL_API_KEY", "")).NotTo(HaveOccurred())
106-
Expect(os.Setenv("OMS_PORTAL_API", "http://test-portal.com/api")).NotTo(HaveOccurred())
112+
safeSetEnv("OMS_PORTAL_API_KEY", "")
113+
safeSetEnv("OMS_PORTAL_API", "http://test-portal.com/api")
107114

108115
Expect(len(os.Getenv("OMS_PORTAL_API_KEY"))).To(Equal(0))
109-
110-
Expect(os.Unsetenv("OMS_PORTAL_API_KEY")).NotTo(HaveOccurred())
111-
Expect(os.Unsetenv("OMS_PORTAL_API")).NotTo(HaveOccurred())
112116
})
113117
})
114118
})

go.mod

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,46 @@ go 1.24.2
44

55
require (
66
github.com/blang/semver v3.5.1+incompatible
7-
github.com/codesphere-cloud/cs-go v0.14.0
8-
github.com/jedib0t/go-pretty/v6 v6.7.1
7+
github.com/codesphere-cloud/cs-go v0.14.1
8+
github.com/jedib0t/go-pretty/v6 v6.7.3
99
github.com/onsi/ginkgo/v2 v2.27.2
1010
github.com/onsi/gomega v1.38.2
1111
github.com/rhysd/go-github-selfupdate v1.2.3
1212
github.com/spf13/cobra v1.10.1
1313
github.com/stretchr/testify v1.11.1
14-
golang.org/x/crypto v0.42.0
14+
golang.org/x/crypto v0.45.0
1515
gopkg.in/yaml.v3 v3.0.1
1616
)
1717

1818
require (
1919
github.com/Masterminds/semver/v3 v3.4.0 // indirect
20-
github.com/clipperhouse/uax29/v2 v2.2.0 // indirect
20+
github.com/clipperhouse/stringish v0.1.1 // indirect
21+
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
2122
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
2223
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2324
github.com/go-logr/logr v1.4.3 // indirect
2425
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
2526
github.com/google/go-cmp v0.7.0 // indirect
2627
github.com/google/go-github/v30 v30.1.0 // indirect
2728
github.com/google/go-querystring v1.1.0 // indirect
28-
github.com/google/pprof v0.0.0-20250923004556-9e5a51aed1e8 // indirect
29+
github.com/google/pprof v0.0.0-20251114195745-4902fdda35c8 // indirect
2930
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
3031
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3132
github.com/mattn/go-runewidth v0.0.19 // indirect
3233
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
3334
github.com/rogpeppe/go-internal v1.14.1 // indirect
3435
github.com/russross/blackfriday/v2 v2.1.0 // indirect
3536
github.com/spf13/pflag v1.0.10 // indirect
36-
github.com/stretchr/objx v0.5.2 // indirect
37+
github.com/stretchr/objx v0.5.3 // indirect
3738
github.com/tcnksm/go-gitconfig v0.1.2 // indirect
3839
github.com/ulikunitz/xz v0.5.15 // indirect
3940
go.yaml.in/yaml/v3 v3.0.4 // indirect
40-
golang.org/x/mod v0.28.0 // indirect
41-
golang.org/x/net v0.44.0 // indirect
42-
golang.org/x/oauth2 v0.30.0 // indirect
43-
golang.org/x/sync v0.17.0 // indirect
44-
golang.org/x/sys v0.36.0 // indirect
45-
golang.org/x/text v0.29.0 // indirect
46-
golang.org/x/tools v0.37.0 // indirect
41+
golang.org/x/mod v0.30.0 // indirect
42+
golang.org/x/net v0.47.0 // indirect
43+
golang.org/x/oauth2 v0.33.0 // indirect
44+
golang.org/x/sync v0.18.0 // indirect
45+
golang.org/x/sys v0.38.0 // indirect
46+
golang.org/x/text v0.31.0 // indirect
47+
golang.org/x/tools v0.39.0 // indirect
4748
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
4849
)

0 commit comments

Comments
 (0)