Skip to content

Commit

Permalink
Fix #418 Added MySQL as DB storage layer. (#575)
Browse files Browse the repository at this point in the history
* Fix #418 Added MySQL as DB storage layer.

* Make the mysql stuff work

* Make the mysql stuff work

* Make the mysql stuff work

* Make the mysql stuff work

* small fixes

* Switch to Go 1.8 installation inside CI (#589)

* Switch to Go 1.8 installation inside CI

Partially Addresses: #588

* Use url.Hostname() instead of custom method

* Added PR review changes.

* Added missing check for error.

* Changed * with name, config

* Removed unused import.

* Added check for NoRows

* Merged changes with HEAD

* Added documentation to mysql.go

* update mysql to be on par with postgres
  • Loading branch information
martinpinto authored and seiflotfy committed Mar 21, 2017
1 parent 353a144 commit e4b3105
Show file tree
Hide file tree
Showing 6 changed files with 757 additions and 17 deletions.
3 changes: 3 additions & 0 deletions api/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/Sirupsen/logrus"
"github.com/iron-io/functions/api/datastore/bolt"
"github.com/iron-io/functions/api/datastore/mysql"
"github.com/iron-io/functions/api/datastore/postgres"
"github.com/iron-io/functions/api/datastore/redis"
"github.com/iron-io/functions/api/models"
Expand All @@ -22,6 +23,8 @@ func New(dbURL string) (models.Datastore, error) {
return bolt.New(u)
case "postgres":
return postgres.New(u)
case "mysql":
return mysql.New(u)
case "redis":
return redis.New(u)
default:
Expand Down
24 changes: 12 additions & 12 deletions api/datastore/internal/datastoretest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (

"github.com/iron-io/functions/api/models"

"github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
"reflect"
"net/http"
"os"
"net/url"
"os"
"reflect"

"github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
)

func setLogBuffer() *bytes.Buffer {
Expand Down Expand Up @@ -73,38 +74,38 @@ func Test(t *testing.T, ds models.Datastore) {
{
// Set a config var
updated, err := ds.UpdateApp(ctx,
&models.App{Name: testApp.Name, Config: map[string]string{"TEST":"1"}})
&models.App{Name: testApp.Name, Config: map[string]string{"TEST": "1"}})
if err != nil {
t.Log(buf.String())
t.Fatalf("Test UpdateApp: error when updating app: %v", err)
}
expected := &models.App{Name: testApp.Name, Config: map[string]string{"TEST":"1"}}
expected := &models.App{Name: testApp.Name, Config: map[string]string{"TEST": "1"}}
if !reflect.DeepEqual(*updated, *expected) {
t.Log(buf.String())
t.Fatalf("Test UpdateApp: expected updated `%v` but got `%v`", expected, updated)
}

// Set a different var (without clearing the existing)
updated, err = ds.UpdateApp(ctx,
&models.App{Name: testApp.Name, Config: map[string]string{"OTHER":"TEST"}})
&models.App{Name: testApp.Name, Config: map[string]string{"OTHER": "TEST"}})
if err != nil {
t.Log(buf.String())
t.Fatalf("Test UpdateApp: error when updating app: %v", err)
}
expected = &models.App{Name: testApp.Name, Config: map[string]string{"TEST":"1","OTHER":"TEST"}}
expected = &models.App{Name: testApp.Name, Config: map[string]string{"TEST": "1", "OTHER": "TEST"}}
if !reflect.DeepEqual(*updated, *expected) {
t.Log(buf.String())
t.Fatalf("Test UpdateApp: expected updated `%v` but got `%v`", expected, updated)
}

// Delete a var
updated, err = ds.UpdateApp(ctx,
&models.App{Name: testApp.Name, Config: map[string]string{"TEST":""}})
&models.App{Name: testApp.Name, Config: map[string]string{"TEST": ""}})
if err != nil {
t.Log(buf.String())
t.Fatalf("Test UpdateApp: error when updating app: %v", err)
}
expected = &models.App{Name: testApp.Name, Config: map[string]string{"OTHER":"TEST"}}
expected = &models.App{Name: testApp.Name, Config: map[string]string{"OTHER": "TEST"}}
if !reflect.DeepEqual(*updated, *expected) {
t.Log(buf.String())
t.Fatalf("Test UpdateApp: expected updated `%v` but got `%v`", expected, updated)
Expand Down Expand Up @@ -247,7 +248,6 @@ func Test(t *testing.T, ds models.Datastore) {
}
}


// Testing update
{
// Update some fields, and add 3 configs and 3 headers.
Expand Down Expand Up @@ -485,4 +485,4 @@ var testRoute = &models.Route{
Image: "iron/hello",
Type: "sync",
Format: "http",
}
}
Loading

0 comments on commit e4b3105

Please sign in to comment.