Last active
November 1, 2020 14:19
-
-
Save RicardoLinck/94203df0d1c708d81a649485c6ac1a64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ( | |
| "testing" | |
| "github.com/stretchr/testify/assert" | |
| ) | |
| func Test_getEndpoint(t *testing.T) { | |
| type args struct { | |
| version int | |
| } | |
| tests := []struct { | |
| name string | |
| args args | |
| want string | |
| wantErr error | |
| }{ | |
| { | |
| name: "Returns /api/v1/some-data when api version 1", | |
| args: args{version: 1}, | |
| want: "/api/v1/some-data", | |
| wantErr: nil, | |
| }, | |
| { | |
| name: "Returns /api/v2/data when api version 2", | |
| args: args{version: 2}, | |
| want: "/api/v2/data", | |
| wantErr: nil, | |
| }, | |
| { | |
| name: "Errors when invalid api version", | |
| args: args{version: 3}, | |
| want: "", | |
| wantErr: ErrInvalidAPIVersion, | |
| }, | |
| } | |
| for _, tt := range tests { | |
| t.Run(tt.name, func(t *testing.T) { | |
| got, err := getEndpoint(tt.args.version) | |
| assert.Equal(t, tt.want, got) | |
| if tt.wantErr != nil { | |
| assert.Error(t, tt.wantErr, err) | |
| } else { | |
| assert.NoError(t, err) | |
| } | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment