|
| 1 | +package utils |
| 2 | + |
| 3 | +import ( |
| 4 | + . "github.com/onsi/ginkgo/v2" |
| 5 | + . "github.com/onsi/gomega" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +var _ = Describe("Utils", func() { |
| 10 | + Describe("ExtractTaskClassNameFromTaskName", func() { |
| 11 | + It("should extract the correct task class name", func() { |
| 12 | + result, err := ExtractTaskClassName("alio2-cr1-hv-gw01.cern.ch:/opt/git/ControlWorkflows/tasks/readout@12b11ac4bb652e1835e3e94806a688c951691d5f#2sP21PjpfCQ") |
| 13 | + Expect(err).ToNot(HaveOccurred()) |
| 14 | + Expect(result).To(Equal("readout")) |
| 15 | + }) |
| 16 | + |
| 17 | + It("should extract the correct JIT task class name", func() { |
| 18 | + result, err := ExtractTaskClassName("alio2-cr1-hv-gw01.cern.ch:/opt/git/ControlWorkflows/tasks/jit-ad6f2b64b7502198430d7d7f93f15bf94c088cab-qc-pp-TPC-CalibQC_long@12b11ac4bb652e1835e3e94806a688c951691d5f#2sP21PjpfCQ") |
| 19 | + Expect(err).ToNot(HaveOccurred()) |
| 20 | + Expect(result).To(Equal("jit-ad6f2b64b7502198430d7d7f93f15bf94c088cab-qc-pp-TPC-CalibQC_long")) |
| 21 | + }) |
| 22 | + |
| 23 | + It("should return an error for invalid input", func() { |
| 24 | + result, err := ExtractTaskClassName("invalid-string") |
| 25 | + Expect(err).To(HaveOccurred()) |
| 26 | + Expect(result).To(Equal("")) |
| 27 | + }) |
| 28 | + }) |
| 29 | + |
| 30 | + Describe("TrimJitPrefix", func() { |
| 31 | + It("should remove the JIT prefix correctly", func() { |
| 32 | + result := TrimJitPrefix("jit-ad6f2b64b7502198430d7d7f93f15bf94c088cab-qc-pp-TPC-CalibQC_long") |
| 33 | + Expect(result).To(Equal("qc-pp-TPC-CalibQC_long")) |
| 34 | + }) |
| 35 | + |
| 36 | + It("should return the original string if no JIT prefix is present", func() { |
| 37 | + result := TrimJitPrefix("qc-pp-TPC-CalibQC_long") |
| 38 | + Expect(result).To(Equal("qc-pp-TPC-CalibQC_long")) |
| 39 | + }) |
| 40 | + }) |
| 41 | +}) |
| 42 | + |
| 43 | +func TestUtils(t *testing.T) { |
| 44 | + RegisterFailHandler(Fail) |
| 45 | + RunSpecs(t, "Component Utils Test Suite") |
| 46 | +} |
0 commit comments