diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d51f5fc..6a6073f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,51 +8,55 @@ env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: + golangci: + strategy: + matrix: + go-version: [1.21.x] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + lint_and_test: + needs: [golangci] strategy: matrix: - go-version: [1.16.x] + go-version: [1.21.x] os: [ubuntu-latest] runs-on: ${{ matrix.os }} timeout-minutes: 80 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: go-version: ${{ matrix.go-version }} - name: Install Go dependencies run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.37.1 - go get -u github.com/kisielk/errcheck - go get -u golang.org/x/lint/golint - go get -u honnef.co/go/tools/cmd/staticcheck - go get -u github.com/axw/gocov/gocov - go get -u github.com/securego/gosec/cmd/gosec - go get -u github.com/ory/go-acc - go get -u github.com/client9/misspell/cmd/misspell - go get -u github.com/gordonklaus/ineffassign - go get github.com/fzipp/gocyclo - go get github.com/stretchr/testify/assert@v1.7.0 + go mod download + go get github.com/axw/gocov/gocov go get github.com/ory/go-acc + go install github.com/ory/go-acc + go install github.com/axw/gocov/gocov + go get github.com/savannahghi/serverutils@v0.0.7 - - name: Run lint and test + - name: Run tests run: | - staticcheck ./... - go fmt $(go list ./... | grep -v /vendor/) - go vet $(go list ./... | grep -v /vendor/) - golint -set_exit_status $(go list ./... | grep -v /vendor/) - errcheck -ignore 'os:.*,' $(go list ./... | grep -v /vendor/) - misspell -error . - gosec -exclude=G304,G101 ./... - go-acc -o coverage.txt --ignore generated,cmd ./... -- -timeout 60m - grep -v "generated.go" coverage.txt > coverage.out + go-acc -o coverage.txt --ignore generated,cmd,graph ./... -- -timeout 60m + grep -v "generated.go" coverage.txt | grep -v "_gen.go" | grep -v "_mock.go" | grep -v "*mock.go" | grep -v "mocks.go" | grep -v "*resolver*go" | grep -v "server.go" | grep -v "*.html" > coverage.out go tool cover -html=coverage.out -o coverage.html gocov convert coverage.out > coverage.json gocov report coverage.json > coverage_report.txt tail coverage_report.txt - + - name: Install goveralls env: GO111MODULE: off diff --git a/enums.go b/enums.go index 9e8f110..d040a48 100644 --- a/enums.go +++ b/enums.go @@ -55,6 +55,19 @@ func (e Gender) String() string { return string(e) } +// ToAdvantageGender converts the `male` and `female` genders to `MALE` and `FEMALE` respectively. +// This is used in support of advantage wrapper service and also ensure consistency of known gender types in go services. +func (e Gender) ToAdvantageGender() string { + switch e { + case GenderMale: + return "MALE" + case GenderFemale: + return "FEMALE" + default: + return "OTHER" + } +} + // UnmarshalGQL translates from the supplied value to a valid enum value func (e *Gender) UnmarshalGQL(v interface{}) error { str, ok := v.(string) diff --git a/enums_test.go b/enums_test.go index 82dcf43..ad8232a 100644 --- a/enums_test.go +++ b/enums_test.go @@ -1185,3 +1185,34 @@ func TestSenderID_String(t *testing.T) { }) } } + +func TestGender_ToAdvantageGender(t *testing.T) { + tests := []struct { + name string + e enumutils.Gender + want string + }{ + { + name: "Happy case: convert `male` to `MALE`", + e: enumutils.GenderMale, + want: "MALE", + }, + { + name: "Happy case: convert `female` to `FEMALE`", + e: enumutils.GenderFemale, + want: "FEMALE", + }, + { + name: "Happy case: return other genders", + e: enumutils.GenderOther, + want: "OTHER", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := tt.e.ToAdvantageGender(); got != tt.want { + t.Errorf("Gender.ToAdvantageGender() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/go.mod b/go.mod index 03987ad..b69e63d 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,11 @@ module github.com/savannahghi/enumutils -go 1.16 +go 1.22.1 require github.com/stretchr/testify v1.7.0 + +require ( + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect +)