|
16 | 16 | package commands
|
17 | 17 |
|
18 | 18 | import (
|
| 19 | + "odfe-cli/entity" |
19 | 20 | "os"
|
20 | 21 | "testing"
|
21 | 22 |
|
@@ -45,8 +46,51 @@ func TestGetRoot(t *testing.T) {
|
45 | 46 | root.SetArgs([]string{"--config", "test/config.yml"})
|
46 | 47 | cmd, err := root.ExecuteC()
|
47 | 48 | assert.NoError(t, err)
|
48 |
| - expected, err := cmd.Flags().GetString(flagConfig) |
| 49 | + actual, err := cmd.Flags().GetString(flagConfig) |
49 | 50 | assert.NoError(t, err)
|
50 |
| - assert.EqualValues(t, expected, "test/config.yml") |
| 51 | + assert.EqualValues(t, "test/config.yml", actual) |
| 52 | + }) |
| 53 | +} |
| 54 | + |
| 55 | +func TestGetProfile(t *testing.T) { |
| 56 | + t.Run("get default profile", func(t *testing.T) { |
| 57 | + root := GetRoot() |
| 58 | + assert.NotNil(t, root) |
| 59 | + root.SetArgs([]string{"--config", "testdata/config.yaml"}) |
| 60 | + _, err := root.ExecuteC() |
| 61 | + assert.NoError(t, err) |
| 62 | + actual, err := GetProfile() |
| 63 | + assert.NoError(t, err) |
| 64 | + expectedProfile := entity.Profile{Name: "default", Endpoint: "http://localhost:9200", UserName: "default", Password: "admin"} |
| 65 | + assert.EqualValues(t, expectedProfile, *actual) |
| 66 | + }) |
| 67 | + t.Run("test get profile", func(t *testing.T) { |
| 68 | + root := GetRoot() |
| 69 | + assert.NotNil(t, root) |
| 70 | + root.SetArgs([]string{"--config", "testdata/config.yaml", "--profile", "test"}) |
| 71 | + _, err := root.ExecuteC() |
| 72 | + assert.NoError(t, err) |
| 73 | + actual, err := GetProfile() |
| 74 | + assert.NoError(t, err) |
| 75 | + expectedProfile := entity.Profile{Name: "test", Endpoint: "https://localhost:9200", UserName: "admin", Password: "admin"} |
| 76 | + assert.EqualValues(t, expectedProfile, *actual) |
| 77 | + }) |
| 78 | + t.Run("Profile mismatch", func(t *testing.T) { |
| 79 | + root := GetRoot() |
| 80 | + assert.NotNil(t, root) |
| 81 | + root.SetArgs([]string{"--config", "testdata/config.yaml", "--profile", "test1"}) |
| 82 | + _, err := root.ExecuteC() |
| 83 | + assert.NoError(t, err) |
| 84 | + _, err = GetProfile() |
| 85 | + assert.EqualError(t, err, "No profile found for execution. Try odfe-cli profile --help for more information.") |
| 86 | + }) |
| 87 | + t.Run("no config file found", func(t *testing.T) { |
| 88 | + root := GetRoot() |
| 89 | + assert.NotNil(t, root) |
| 90 | + root.SetArgs([]string{"--config", "testdata/config1.yaml", "--profile", "test1"}) |
| 91 | + _, err := root.ExecuteC() |
| 92 | + assert.NoError(t, err) |
| 93 | + _, err = GetProfile() |
| 94 | + assert.EqualError(t, err, "open testdata/config1.yaml: no such file or directory") |
51 | 95 | })
|
52 | 96 | }
|
0 commit comments