This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from Zandrr/add-json-flag-pr
Added ability to add json flag to command to get a response in json f…
- Loading branch information
Showing
7 changed files
with
162 additions
and
45 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
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
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,89 @@ | ||
// | ||
// Copyright (c) 2015 The heketi Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package commands | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"github.com/gorilla/mux" | ||
"github.com/heketi/heketi/apps/glusterfs" | ||
"github.com/heketi/heketi/tests" | ||
"net/http/httptest" | ||
"os" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestJsonFlagsCreate(t *testing.T) { | ||
defer os.Remove("heketi.db") | ||
|
||
// Create the app | ||
app := glusterfs.NewApp() | ||
defer app.Close() | ||
router := mux.NewRouter() | ||
app.SetRoutes(router) | ||
|
||
// Setup the server | ||
ts := httptest.NewServer(router) | ||
defer ts.Close() | ||
|
||
//set options | ||
options := &Options{ | ||
Url: ts.URL, | ||
Json: true, | ||
} | ||
|
||
//create b to get values of stdout | ||
var b bytes.Buffer | ||
defer tests.Patch(&stdout, &b).Restore() | ||
|
||
//create mock cluster and mock destroy | ||
mockCluster := NewCreateNewClusterCommand(options) | ||
|
||
//create new cluster and assert json | ||
err := mockCluster.Exec([]string{}) | ||
tests.Assert(t, err == nil) | ||
var clusterInfoResCreate glusterfs.ClusterInfoResponse | ||
err = json.Unmarshal(b.Bytes(), &clusterInfoResCreate) | ||
tests.Assert(t, err == nil, err) | ||
tests.Assert(t, strings.Contains(b.String(), clusterInfoResCreate.Id), clusterInfoResCreate) | ||
b.Reset() | ||
|
||
//get cluster info and assert json | ||
clusterInfo := NewGetClusterInfoCommand(options) | ||
args := []string{clusterInfoResCreate.Id} | ||
err = clusterInfo.Exec(args) | ||
tests.Assert(t, err == nil) | ||
tests.Assert(t, strings.Contains(b.String(), clusterInfoResCreate.Id)) | ||
b.Reset() | ||
|
||
//get cluster list and assert json | ||
clusterList := NewGetClusterListCommand(options) | ||
err = clusterList.Exec([]string{}) | ||
tests.Assert(t, err == nil) | ||
var clusterListResList glusterfs.ClusterInfoResponse | ||
err = json.Unmarshal(b.Bytes(), &clusterListResList) | ||
tests.Assert(t, strings.Contains(b.String(), clusterListResList.Id)) | ||
b.Reset() | ||
|
||
//destroy cluster and assert proper json response | ||
clusterDestroy := NewDestroyClusterCommand(options) | ||
err = clusterDestroy.Exec(args) | ||
tests.Assert(t, err != nil) | ||
tests.Assert(t, strings.Contains(b.String(), "")) | ||
|
||
} |
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 |
---|---|---|
|
@@ -17,5 +17,6 @@ | |
package commands | ||
|
||
type Options struct { | ||
Url string | ||
Url string | ||
Json bool | ||
} |
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