MCPcopy
hub / github.com/iron-io/functions / Test

Function Test

api/datastore/internal/datastoretest/test.go:39–476  ·  view source on GitHub ↗
(t *testing.T, ds models.Datastore)

Source from the content-addressed store, hash-verified

37}
38
39func Test(t *testing.T, ds models.Datastore) {
40 buf := setLogBuffer()
41
42 ctx := context.Background()
43
44 t.Run("apps", func(t *testing.T) {
45 // Testing insert app
46 _, err := ds.InsertApp(ctx, nil)
47 if err != models.ErrDatastoreEmptyApp {
48 t.Log(buf.String())
49 t.Fatalf("Test InsertApp(nil): expected error `%v`, but it was `%v`", models.ErrDatastoreEmptyApp, err)
50 }
51
52 _, err = ds.InsertApp(ctx, &models.App{})
53 if err != models.ErrDatastoreEmptyAppName {
54 t.Log(buf.String())
55 t.Fatalf("Test InsertApp(&{}): expected error `%v`, but it was `%v`", models.ErrDatastoreEmptyAppName, err)
56 }
57
58 inserted, err := ds.InsertApp(ctx, testApp)
59 if err != nil {
60 t.Log(buf.String())
61 t.Fatalf("Test InsertApp: error when storing new app: %s", err)
62 }
63 if !reflect.DeepEqual(*inserted, *testApp) {
64 t.Log(buf.String())
65 t.Fatalf("Test InsertApp: expected to insert:\n%v\nbut got:\n%v", testApp, inserted)
66 }
67
68 _, err = ds.InsertApp(ctx, testApp)
69 if err != models.ErrAppsAlreadyExists {
70 t.Log(buf.String())
71 t.Fatalf("Test InsertApp duplicated: expected error `%v`, but it was `%v`", models.ErrAppsAlreadyExists, err)
72 }
73
74 {
75 // Set a config var
76 updated, err := ds.UpdateApp(ctx,
77 &models.App{Name: testApp.Name, Config: map[string]string{"TEST": "1"}})
78 if err != nil {
79 t.Log(buf.String())
80 t.Fatalf("Test UpdateApp: error when updating app: %v", err)
81 }
82 expected := &models.App{Name: testApp.Name, Config: map[string]string{"TEST": "1"}}
83 if !reflect.DeepEqual(*updated, *expected) {
84 t.Log(buf.String())
85 t.Fatalf("Test UpdateApp: expected updated `%v` but got `%v`", expected, updated)
86 }
87
88 // Set a different var (without clearing the existing)
89 updated, err = ds.UpdateApp(ctx,
90 &models.App{Name: testApp.Name, Config: map[string]string{"OTHER": "TEST"}})
91 if err != nil {
92 t.Log(buf.String())
93 t.Fatalf("Test UpdateApp: error when updating app: %v", err)
94 }
95 expected = &models.App{Name: testApp.Name, Config: map[string]string{"TEST": "1", "OTHER": "TEST"}}
96 if !reflect.DeepEqual(*updated, *expected) {

Callers

nothing calls this directly

Calls 15

RunMethod · 0.80
setLogBufferFunction · 0.70
InsertAppMethod · 0.65
LogMethod · 0.65
UpdateAppMethod · 0.65
GetAppMethod · 0.65
GetAppsMethod · 0.65
RemoveAppMethod · 0.65
InsertRouteMethod · 0.65
GetRouteMethod · 0.65
UpdateRouteMethod · 0.65
GetRoutesByAppMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…