<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:35:04 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[GODRIVER-834] Please convert Client, Database, Collection and others structs to interfaces to allow develop Mocks</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-834</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;Dear All,&lt;/p&gt;

&lt;p&gt;Please look at this cool library:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/DATA-DOG/go-sqlmock&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/DATA-DOG/go-sqlmock&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is very very useful library to &quot;mock&quot; any SQL database for tests.&lt;/p&gt;

&lt;p&gt;I am ready to develop the same library for MongoDB. But the problem is Client, Database, Collection and others are structs. Could you please refactor them to Go interfaces (like in&quot;sql&quot; Go build-in package). It allows me to &quot;mock&quot; them.&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;</description>
                <environment></environment>
        <key id="699317">GODRIVER-834</key>
            <summary>Please convert Client, Database, Collection and others structs to interfaces to allow develop Mocks</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="2">Won&apos;t Fix</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="amsokol">Aleksandr Sokolovskii</reporter>
                        <labels>
                    </labels>
                <created>Sun, 17 Feb 2019 06:35:41 +0000</created>
                <updated>Wed, 1 Dec 2021 20:20:18 +0000</updated>
                            <resolved>Mon, 4 Mar 2019 21:21:09 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="4114328" author="JIRAUSER1262777" created="Sat, 9 Oct 2021 04:43:19 +0000"  >&lt;p&gt;In case if anyone still needs the interfaces, I implemented a simple wrapper to provide the interfaces for all main classes: &lt;a href=&quot;https://github.com/sv-tools/mongoifc&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/sv-tools/mongoifc&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;it has the interfaces for such object as:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Client: &lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Client&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Client&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;Database: &lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Database&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Database&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;Session: &lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Session&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Session&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;ChangeStream: &lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#ChangeStream&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#ChangeStream&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;Cursor: &lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Cursor&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Cursor&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;Collection: &lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;SingleResult: &lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#SingleResult&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#SingleResult&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;IndexView: &lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#IndexView&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#IndexView&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;the main problem that it requires to use the wrapper instead of direct object.&lt;/p&gt;</comment>
                            <comment id="2225636" author="amsokol" created="Fri, 26 Apr 2019 08:05:41 +0000"  >&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;@Sam Ward, thank you for support.&lt;/p&gt;

&lt;p&gt;@Ian Whalen, there is Go official tool for mocking:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/golang/mock&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/golang/mock&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://godoc.org/github.com/golang/mock/gomock&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://godoc.org/github.com/golang/mock/gomock&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It would be great to make driver API compatible with it.&#160;&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;</comment>
                            <comment id="2220016" author="sbward" created="Sun, 21 Apr 2019 02:25:58 +0000"  >&lt;p&gt;Hey there, I believe the reason Aleksandr wants interfaces is that the best practice for testing in Go is through interfaces.&#160; For an example, look at how Amazon Web Service Go SDK provides interface (&quot;iface&quot;) packages for every driver:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/sdk-for-go/api/service/sqs/sqsiface/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.aws.amazon.com/sdk-for-go/api/service/sqs/sqsiface/&lt;/a&gt;,&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/ec2iface/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/ec2iface/&lt;/a&gt;, etc.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;There is a very good reason for this: in Go tests we want to run our code and &quot;mock&quot; things like backends and other loosely coupled code, then make assertions with the mock.&#160; Here&apos;s a typical Go mocking library that one might use in their project &#8211; notice that it relies on interface types to work:&#160;&lt;a href=&quot;https://github.com/matryer/moq&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/matryer/moq&lt;/a&gt; &#8211; it generates mock implementations with hooks for tests.&lt;/p&gt;

&lt;p&gt;In summary, providing interfaces for the full API is expected by the community and absolutely required for any serious project that uses Mongo&apos;s Go driver.&lt;/p&gt;

&lt;p&gt;Please consider reopening this ticket and adding the interfaces to your library &#8211; the whole community would love it!&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="2170046" author="ian@10gen.com" created="Mon, 4 Mar 2019 21:21:09 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=amsokol&quot; class=&quot;user-hover&quot; rel=&quot;amsokol&quot;&gt;amsokol&lt;/a&gt;, closing this as Won&apos;t Fix since the equivalent types in database/sql are structs not interfaces.  In the future we&apos;re planning to add functionality that will allow mocking at a lower level.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="901138">GODRIVER-1241</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1940812">GODRIVER-2249</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hudkxz:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>