Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1239 from kjlyon/v1-api-tests
Browse files Browse the repository at this point in the history
V1 Rest API Tests
  • Loading branch information
IRCody authored Oct 4, 2016
2 parents a564968 + 54afc0e commit 87ab47c
Show file tree
Hide file tree
Showing 8 changed files with 1,842 additions and 98 deletions.
49 changes: 49 additions & 0 deletions mgmt/rest/config_test.go
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(),
}
}
109 changes: 109 additions & 0 deletions mgmt/rest/fixtures/mock_config_manager.go
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"
}
}`
)
Loading

0 comments on commit 87ab47c

Please sign in to comment.