-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix creating a project variable without a selected env
Also adds tests for creating and updating variables
- Loading branch information
1 parent
952e914
commit 06f5770
Showing
5 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package tests | ||
|
||
import ( | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/platformsh/cli/pkg/mockapi" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestVariableCreate(t *testing.T) { | ||
authServer := mockapi.NewAuthServer(t) | ||
defer authServer.Close() | ||
|
||
apiHandler := mockapi.NewHandler(t) | ||
apiServer := httptest.NewServer(apiHandler) | ||
defer apiServer.Close() | ||
|
||
projectID := "ohnguk9zeiw3b" | ||
|
||
apiHandler.SetProjects([]*mockapi.Project{{ | ||
ID: projectID, | ||
Links: mockapi.MakeHALLinks("self=/projects/"+projectID, | ||
"environments=/projects/"+projectID+"/environments"), | ||
DefaultBranch: "main", | ||
}}) | ||
main := makeEnv(projectID, "main", "production", "active", nil) | ||
main.Links["#variables"] = mockapi.HALLink{HREF: "/projects/" + projectID + "/environments/main/variables"} | ||
main.Links["#manage-variables"] = mockapi.HALLink{HREF: "/projects/" + projectID + "/environments/main/variables"} | ||
envs := []*mockapi.Environment{main} | ||
apiHandler.SetEnvironments(envs) | ||
|
||
apiHandler.SetProjectVariables(projectID, []*mockapi.Variable{ | ||
{ | ||
Name: "bar", | ||
IsSensitive: true, | ||
VisibleBuild: true, | ||
}, | ||
}) | ||
|
||
f := newCommandFactory(t, apiServer.URL, authServer.URL) | ||
|
||
_, stdErr, err := f.RunCombinedOutput("var:create", "-p", projectID, "-l", "e", "-e", "main", "env:TEST", "--value", "env-level-value") | ||
assert.NoError(t, err) | ||
assert.Contains(t, stdErr, "Creating variable env:TEST on the environment main") | ||
|
||
assertTrimmed(t, "env-level-value", f.Run("var:get", "-p", projectID, "-e", "main", "env:TEST", "-P", "value")) | ||
|
||
_, stdErr, err = f.RunCombinedOutput("var:create", "-p", projectID, "env:TEST", "-l", "p", "--value", "project-level-value") | ||
assert.NoError(t, err) | ||
assert.Contains(t, stdErr, "Creating variable env:TEST on the project "+projectID) | ||
|
||
assertTrimmed(t, "project-level-value", f.Run("var:get", "-p", projectID, "-e", "main", "env:TEST", "-P", "value", "-l", "p")) | ||
assertTrimmed(t, "env-level-value", f.Run("var:get", "-p", projectID, "-e", "main", "env:TEST", "-P", "value", "-l", "e")) | ||
|
||
_, stdErr, err = f.RunCombinedOutput("var:create", "-p", projectID, "bar", "-l", "p", "--value", "test") | ||
assert.Error(t, err) | ||
assert.Contains(t, stdErr, "The variable already exists") | ||
|
||
_, _, err = f.RunCombinedOutput("var:create", "-p", projectID, "env:TEST2", "-l", "p", "--value", "1") | ||
assert.NoError(t, err) | ||
assertTrimmed(t, "1", f.Run("var:get", "-p", projectID, "env:TEST2", "-l", "p", "-P", "value")) | ||
|
||
_, _, err = f.RunCombinedOutput("var:update", "-p", projectID, "env:TEST2", "-l", "p", "--value", "2") | ||
assert.NoError(t, err) | ||
assertTrimmed(t, "2", f.Run("var:get", "-p", projectID, "env:TEST2", "-l", "p", "-P", "value")) | ||
|
||
assertTrimmed(t, "true", f.Run("var:get", "-p", projectID, "env:TEST2", "-l", "p", "-P", "visible_runtime")) | ||
_, _, err = f.RunCombinedOutput("var:update", "-p", projectID, "env:TEST2", "-l", "p", "--visible-runtime", "false") | ||
assert.NoError(t, err) | ||
assertTrimmed(t, "false", f.Run("var:get", "-p", projectID, "env:TEST2", "-l", "p", "-P", "visible_runtime")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters