Skip to content

Commit

Permalink
Merge pull request #9 from reMarkable/fix/types/allow-fs-default
Browse files Browse the repository at this point in the history
fix(types): allow default firestore database
  • Loading branch information
Zarux authored Jun 6, 2024
2 parents 9ca6b47 + fd2ebd9 commit badde30
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
28 changes: 19 additions & 9 deletions envconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ type Specification struct {
Property string `envconfig:"inner"`
PropertyWithDefault string `envconfig:"PROPERTYWITHDEFAULT" default:"fuzzybydefault"`
} `envconfig:"outer"`
AfterNested string `envconfig:"AFTERNESTED"`
DecodeStruct HonorDecodeInStruct `envconfig:"honor"`
Datetime time.Time `envconfig:"DATETIME"`
MapField map[string]string `envconfig:"MAPFIELD" default:"one:two;three:four"`
EmptyMapField map[string]string `envconfig:"EMPTY_MAPFIELD"`
UrlValue CustomURL `envconfig:"URLVALUE"`
UrlPointer *CustomURL `envconfig:"URLPOINTER"`
GooglePubSubTopic types.GooglePubSubTopic `envconfig:"GOOGLE_PUBSUB_TOPIC"`
GoogleFirestoreDatabase types.GoogleFirestoreDatabase `envconfig:"GOOGLE_FIRESTORE_DATABASE"`
AfterNested string `envconfig:"AFTERNESTED"`
DecodeStruct HonorDecodeInStruct `envconfig:"honor"`
Datetime time.Time `envconfig:"DATETIME"`
MapField map[string]string `envconfig:"MAPFIELD" default:"one:two;three:four"`
EmptyMapField map[string]string `envconfig:"EMPTY_MAPFIELD"`
UrlValue CustomURL `envconfig:"URLVALUE"`
UrlPointer *CustomURL `envconfig:"URLPOINTER"`
GooglePubSubTopic types.GooglePubSubTopic `envconfig:"GOOGLE_PUBSUB_TOPIC"`
GoogleFirestoreDatabase types.GoogleFirestoreDatabase `envconfig:"GOOGLE_FIRESTORE_DATABASE"`
GoogleFirestoreDatabaseDefault types.GoogleFirestoreDatabase `envconfig:"GOOGLE_FIRESTORE_DATABASE_DEFAULT"`
}

type Embedded struct {
Expand Down Expand Up @@ -116,6 +117,7 @@ func TestProcess(t *testing.T) {
os.Setenv("ENV_CONFIG_URLPOINTER", "https://github.com/kelseyhightower/envconfig")
os.Setenv("ENV_CONFIG_GOOGLE_PUBSUB_TOPIC", "projects/project-id/topics/topic-id")
os.Setenv("ENV_CONFIG_GOOGLE_FIRESTORE_DATABASE", "projects/project-id/databases/db")
os.Setenv("ENV_CONFIG_GOOGLE_FIRESTORE_DATABASE_DEFAULT", "projects/project-id/databases/(default)")
err := Process("env_config", &s)
if err != nil {
t.Error(err.Error())
Expand Down Expand Up @@ -233,6 +235,14 @@ func TestProcess(t *testing.T) {
if s.GoogleFirestoreDatabase.Database != "db" {
t.Errorf("expected %s, got %s", "db", s.GoogleFirestoreDatabase.Database)
}

if s.GoogleFirestoreDatabaseDefault.ProjectID != "project-id" {
t.Errorf("expected %s, got %s", "project-id", s.GoogleFirestoreDatabaseDefault.ProjectID)
}

if s.GoogleFirestoreDatabaseDefault.Database != "(default)" {
t.Errorf("expected %s, got %s", "default", s.GoogleFirestoreDatabaseDefault.Database)
}
}

func TestParseErrorBool(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions testdata/custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ ENV_CONFIG_URLVALUE=
ENV_CONFIG_URLPOINTER=
ENV_CONFIG_GOOGLE_PUBSUB_TOPIC=
ENV_CONFIG_GOOGLE_FIRESTORE_DATABASE=
ENV_CONFIG_GOOGLE_FIRESTORE_DATABASE_DEFAULT=
5 changes: 5 additions & 0 deletions testdata/default_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,8 @@ ENV_CONFIG_GOOGLE_FIRESTORE_DATABASE
..[type]........GoogleFirestoreDatabase
..[default].....
..[required]....
ENV_CONFIG_GOOGLE_FIRESTORE_DATABASE_DEFAULT
..[description].
..[type]........GoogleFirestoreDatabase
..[default].....
..[required]....
1 change: 1 addition & 0 deletions testdata/default_table.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ ENV_CONFIG_URLVALUE..............................CustomURL......................
ENV_CONFIG_URLPOINTER............................CustomURL.............................................................................
ENV_CONFIG_GOOGLE_PUBSUB_TOPIC...................GooglePubSubTopic.....................................................................
ENV_CONFIG_GOOGLE_FIRESTORE_DATABASE.............GoogleFirestoreDatabase...............................................................
ENV_CONFIG_GOOGLE_FIRESTORE_DATABASE_DEFAULT.....GoogleFirestoreDatabase...............................................................
1 change: 1 addition & 0 deletions testdata/fault.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
{.Key}
{.Key}
{.Key}
{.Key}
2 changes: 1 addition & 1 deletion types/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
// ErrInvalidGoogleFirestoreID means the configured database id has the wrong format.
ErrInvalidGoogleFirestoreID = errors.New("firestore id is not valid format")

googleFirestoreRegexp = regexp.MustCompile(`projects\/([\w-]+)\/databases\/([\w-]+)`)
googleFirestoreRegexp = regexp.MustCompile(`projects\/([\w-]+)\/databases\/([\w-]+|\(default\))`)
)

type GoogleFirestoreDatabase struct {
Expand Down

0 comments on commit badde30

Please sign in to comment.