mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 09:26:43 -06:00
dde650905d
I removed some code, and commented out other one. See, $ gometalinter --vendor --disable-all --disable=gotype --enable=megacheck --deadline 6m ./... | grep unused pkg/api/avatar/avatar.go💯26⚠️ func (*CacheServer).mustInt is unused (U1000) (megacheck) pkg/api/folder_test.go:136:6⚠️ func callGetFolderByUID is unused (U1000) (megacheck) pkg/api/folder_test.go:141:6⚠️ func callDeleteFolder is unused (U1000) (megacheck) pkg/api/live/hub.go:40:15⚠️ func (*hub).removeConnection is unused (U1000) (megacheck) pkg/components/imguploader/azureblobuploader.go:130:5⚠️ var client is unused (U1000) (megacheck) pkg/middleware/middleware_test.go:438:28⚠️ func (*scenarioContext).withInvalidApiKey is unused (U1000) (megacheck) pkg/services/alerting/ticker.go:40:18⚠️ func (*Ticker).updateOffset is unused (U1000) (megacheck) pkg/services/notifications/notifications_test.go:12:6⚠️ type testTriggeredAlert is unused (U1000) (megacheck) pkg/services/sqlstore/dashboard_service_integration_test.go:935:6⚠️ type scenarioContext is unused (U1000) (megacheck) pkg/services/sqlstore/dashboard_service_integration_test.go:939:6⚠️ type scenarioFunc is unused (U1000) (megacheck) pkg/services/sqlstore/dashboard_service_integration_test.go:941:6⚠️ func dashboardGuardianScenario is unused (U1000) (megacheck) pkg/services/sqlstore/transactions_test.go:13:6⚠️ type testQuery is unused (U1000) (megacheck)
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package sqlstore
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
var ProvokedError = errors.New("testing error.")
|
|
|
|
func TestTransaction(t *testing.T) {
|
|
ss := InitTestDB(t)
|
|
|
|
Convey("InTransaction asdf asdf", t, func() {
|
|
cmd := &models.AddApiKeyCommand{Key: "secret-key", Name: "key", OrgId: 1}
|
|
|
|
err := AddApiKey(cmd)
|
|
So(err, ShouldBeNil)
|
|
|
|
deleteApiKeyCmd := &models.DeleteApiKeyCommand{Id: cmd.Result.Id, OrgId: 1}
|
|
|
|
Convey("can update key", func() {
|
|
err := ss.InTransaction(context.Background(), func(ctx context.Context) error {
|
|
return DeleteApiKeyCtx(ctx, deleteApiKeyCmd)
|
|
})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
query := &models.GetApiKeyByIdQuery{ApiKeyId: cmd.Result.Id}
|
|
err = GetApiKeyById(query)
|
|
So(err, ShouldEqual, models.ErrInvalidApiKey)
|
|
})
|
|
|
|
Convey("won't update if one handler fails", func() {
|
|
err := ss.InTransaction(context.Background(), func(ctx context.Context) error {
|
|
err := DeleteApiKeyCtx(ctx, deleteApiKeyCmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return ProvokedError
|
|
})
|
|
|
|
So(err, ShouldEqual, ProvokedError)
|
|
|
|
query := &models.GetApiKeyByIdQuery{ApiKeyId: cmd.Result.Id}
|
|
err = GetApiKeyById(query)
|
|
So(err, ShouldBeNil)
|
|
So(query.Result.Id, ShouldEqual, cmd.Result.Id)
|
|
})
|
|
})
|
|
}
|