Skip to content

Commit

Permalink
fix: error out if cli config doesn't exist, fixes #1347 (#1517)
Browse files Browse the repository at this point in the history
This reverts commit 4a2902d
Integration tests now run successfully after #1514
  • Loading branch information
safeer authored May 17, 2024
1 parent 9d46ee1 commit 80c00ab
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
3 changes: 1 addition & 2 deletions cmd/ftl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"errors"
"net/url"
"os"
"os/signal"
Expand Down Expand Up @@ -81,7 +80,7 @@ func main() {
ctx = log.ContextWithLogger(ctx, logger)

config, err := projectconfig.LoadConfig(ctx, cli.ConfigFlag)
if err != nil && !errors.Is(err, os.ErrNotExist) {
if err != nil {
kctx.Fatalf(err.Error())
}
kctx.Bind(config)
Expand Down
4 changes: 0 additions & 4 deletions common/projectconfig/projectconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package projectconfig

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -85,9 +84,6 @@ func loadFile(path string) (Config, error) {
config := Config{}
md, err := toml.DecodeFile(path, &config)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return Config{}, nil
}
return Config{}, err
}
if len(md.Undecoded()) > 0 {
Expand Down
23 changes: 23 additions & 0 deletions common/projectconfig/projectconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ func TestProjectConfig(t *testing.T) {
assert.Equal(t, expected, actual)
}

func TestProjectLoadConfig(t *testing.T) {
tests := []struct {
name string
paths []string
err string
}{
{name: "AllValid", paths: []string{"testdata/ftl-project.toml"}},
{name: "IsNonExistent", paths: []string{"testdata/ftl-project-nonexistent.toml"}, err: "no such file or directory"},
{name: "ContainsNonExistent", paths: []string{"testdata/ftl-project.toml", "testdata/ftl-project-nonexistent.toml"}, err: "no such file or directory"},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, err := LoadConfig(log.ContextWithNewDefaultLogger(context.Background()), test.paths)
if test.err != "" {
assert.Contains(t, err.Error(), test.err)
} else {
assert.NoError(t, err)
}
})
}
}

func TestProjectConfigChecksMinVersion(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit 80c00ab

Please sign in to comment.