Last active
March 28, 2023 22:22
-
-
Save brurucy/10669fb29259e6b8edaefdc69c2903e7 to your computer and use it in GitHub Desktop.
memoir
This file contains 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
func TestGetSchema(t *testing.T) { | |
ctrl := gomock.NewController(t) | |
schemataRepositoryMock := NewMockSchemataRepository(ctrl) | |
gitRepositoryMock := NewMockGitRepository(ctrl) | |
somePath := "some-api.json" | |
actualSchema := []byte(`{...}`) | |
gitRepositoryMock.EXPECT().Clone(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(s storage.Storer, worktree billy.Filesystem, o *git.CloneOptions) (*git.Repository, error) {...}) | |
someSchemaName := "some-api" | |
someGithubRepository := "github.com/pipedrive/some-api" | |
actualSchemata := entity.Schemata{ | |
{ | |
Name: someSchemaName, | |
Repository: someGithubRepository, | |
Path: somePath, | |
}, | |
} | |
schemataRepositoryMock.EXPECT().Load().Return(actualSchemata, nil).AnyTimes() | |
var request echotest.Request | |
pdtesting.Run(t, Module(), fx.Populate(&request), | |
fx.Decorate(func() repository.SchemataRepository { | |
return schemataRepositoryMock | |
}), | |
fx.Decorate(func() repository.GitRepository { | |
return gitRepositoryMock | |
}) | |
) | |
res := request(t, echotest.WithMethod(http.MethodGet), echotest.WithPath("/api/v1/schemata/some-api.json")) | |
assert.Equal(t, http.StatusOK, res.StatusCode) | |
assert.Equal(t, string(actualSchema), res.String()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment