-
Notifications
You must be signed in to change notification settings - Fork 0
/
specialized_loader.go
52 lines (41 loc) · 1.64 KB
/
specialized_loader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package fixtures
import (
"fmt"
"github.com/elmagician/kactus/internal/databases/postgres"
"github.com/elmagician/kactus/internal/picker"
"github.com/elmagician/kactus/internal/pubsub/google"
)
// LoadPostgres applies sql seed fixtures to picked database name.
func (fix Fixtures) LoadPostgres(db, fixturePath string) error {
kind, pgDb, exists := fix.store.GetInstance(db)
if !exists {
return fmt.Errorf("%w: expected database: %s to be known", ErrUnknown, db)
}
if kind != picker.Postgres {
return fmt.Errorf("%w: expected: %T does not match: %T", ErrInvalidInstance, postgres.DB{}, pgDb)
}
postgresLoader, ok := pgDb.(postgres.DB)
if !ok {
postgresLoaderPointer, ok := pgDb.(*postgres.DB)
if !ok {
return fmt.Errorf("%w: expected: %T does not match: %T", ErrInvalidInstance, postgres.DB{}, pgDb)
}
postgresLoader = *postgresLoaderPointer
}
return postgresLoader.SeedFromFile(fix.getPath(fixturePath), fix.store)
}
// LoadGooglePubsub applies yaml pubsub manifest seed fixtures to picked google instance name.
func (fix Fixtures) LoadGooglePubsub(gcp, fixturePath string) error {
kind, googlePubsub, exists := fix.store.GetInstance(gcp)
if !exists {
return fmt.Errorf("%w: expected google pubsub: %s to be known", ErrUnknown, gcp)
}
if kind != picker.GCP {
return fmt.Errorf("%w: expected: %T does not match: %T", ErrInvalidInstance, google.Client{}, googlePubsub)
}
googlePubsubLoader, ok := googlePubsub.(*google.Client)
if !ok {
return fmt.Errorf("%w: expected: %T does not match: %T", ErrInvalidInstance, google.Client{}, googlePubsub)
}
return googlePubsubLoader.SeedFromFile(fix.getPath(fixturePath), fix.store)
}