This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 294
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 #1239 from kjlyon/v1-api-tests
V1 Rest API Tests
- Loading branch information
Showing
8 changed files
with
1,842 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// +build legacy small medium large | ||
|
||
/* | ||
http://www.apache.org/licenses/LICENSE-2.0.txt | ||
Copyright 2016 Intel Corporation | ||
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 rest | ||
|
||
import ( | ||
"github.com/intelsdi-x/snap/control" | ||
"github.com/intelsdi-x/snap/scheduler" | ||
) | ||
|
||
// Since we do not have a global snap package that could be imported | ||
// we create a mock config struct to mock what is in snapd.go | ||
|
||
type mockConfig struct { | ||
LogLevel int `json:"-"yaml:"-"` | ||
GoMaxProcs int `json:"-"yaml:"-"` | ||
LogPath string `json:"-"yaml:"-"` | ||
Control *control.Config | ||
Scheduler *scheduler.Config `json:"-",yaml:"-"` | ||
RestAPI *Config `json:"-",yaml:"-"` | ||
} | ||
|
||
func getDefaultMockConfig() *mockConfig { | ||
return &mockConfig{ | ||
LogLevel: 3, | ||
GoMaxProcs: 1, | ||
LogPath: "", | ||
Control: control.GetDefaultConfig(), | ||
Scheduler: scheduler.GetDefaultConfig(), | ||
RestAPI: GetDefaultConfig(), | ||
} | ||
} |
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,109 @@ | ||
// +build legacy small medium large | ||
|
||
/* | ||
http://www.apache.org/licenses/LICENSE-2.0.txt | ||
Copyright 2016 Intel Corporation | ||
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 fixtures | ||
|
||
import ( | ||
"github.com/intelsdi-x/snap/core" | ||
"github.com/intelsdi-x/snap/core/cdata" | ||
"github.com/intelsdi-x/snap/core/ctypes" | ||
) | ||
|
||
var mockConfig *cdata.ConfigDataNode | ||
|
||
func init() { | ||
mockConfig = cdata.NewNode() | ||
mockConfig.AddItem("User", ctypes.ConfigValueStr{Value: "KELLY"}) | ||
mockConfig.AddItem("Port", ctypes.ConfigValueInt{Value: 2}) | ||
} | ||
|
||
type MockConfigManager struct{} | ||
|
||
func (MockConfigManager) GetPluginConfigDataNode(core.PluginType, string, int) cdata.ConfigDataNode { | ||
return *mockConfig | ||
} | ||
func (MockConfigManager) GetPluginConfigDataNodeAll() cdata.ConfigDataNode { | ||
return *mockConfig | ||
} | ||
func (MockConfigManager) MergePluginConfigDataNode( | ||
pluginType core.PluginType, name string, ver int, cdn *cdata.ConfigDataNode) cdata.ConfigDataNode { | ||
return *cdn | ||
} | ||
func (MockConfigManager) MergePluginConfigDataNodeAll(cdn *cdata.ConfigDataNode) cdata.ConfigDataNode { | ||
return cdata.ConfigDataNode{} | ||
} | ||
func (MockConfigManager) DeletePluginConfigDataNodeField( | ||
pluginType core.PluginType, name string, ver int, fields ...string) cdata.ConfigDataNode { | ||
for _, field := range fields { | ||
mockConfig.DeleteItem(field) | ||
|
||
} | ||
return *mockConfig | ||
} | ||
|
||
func (MockConfigManager) DeletePluginConfigDataNodeFieldAll(fields ...string) cdata.ConfigDataNode { | ||
for _, field := range fields { | ||
mockConfig.DeleteItem(field) | ||
|
||
} | ||
return *mockConfig | ||
} | ||
|
||
// These constants are the expected plugin config responses from running | ||
// rest_v1_test.go on the plugin config routes found in mgmt/rest/server.go | ||
const ( | ||
SET_PLUGIN_CONFIG_ITEM = `{ | ||
"meta": { | ||
"code": 200, | ||
"message": "Plugin config item(s) set", | ||
"type": "config_plugin_item_created", | ||
"version": 1 | ||
}, | ||
"body": { | ||
"user": "Jane" | ||
} | ||
}` | ||
|
||
GET_PLUGIN_CONFIG_ITEM = `{ | ||
"meta": { | ||
"code": 200, | ||
"message": "Plugin config item retrieved", | ||
"type": "config_plugin_item_returned", | ||
"version": 1 | ||
}, | ||
"body": { | ||
"Port": 2, | ||
"User": "KELLY" | ||
} | ||
}` | ||
|
||
DELETE_PLUGIN_CONFIG_ITEM = `{ | ||
"meta": { | ||
"code": 200, | ||
"message": "Plugin config item field(s) deleted", | ||
"type": "config_plugin_item_deleted", | ||
"version": 1 | ||
}, | ||
"body": { | ||
"Port": 2, | ||
"User": "KELLY" | ||
} | ||
}` | ||
) |
Oops, something went wrong.