Skip to content

Instantly share code, notes, and snippets.

@yulintan
Last active November 16, 2023 10:10
Show Gist options
  • Save yulintan/8094b27742f6789267f147405734cb94 to your computer and use it in GitHub Desktop.
Save yulintan/8094b27742f6789267f147405734cb94 to your computer and use it in GitHub Desktop.
It provides a way for testing private function in Go
package service
var CalculateSum = calculateSum
package service
func calculateSum(a, b int) int {
return a + b
}
package service_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
service "github.com/yulintan/test-private-function"
)
var _ = Describe("myService", func() {
It("returns the sum", func() {
r := service.CalculateSum(1, 2)
Expect(r).To(Equal(3))
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment