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

Commit

Permalink
Wrote V1 Rest API Validation Tests:
Browse files Browse the repository at this point in the history
    - Wrote tests in rest_v1_tests.go that test the various routes found in the addRoutes function of server.go. Each test calls mock methods from the fixtures package and compares its response to a constant, expected response found in the mock files.
    - Added mock manager classes in the fixtures class for managing config, metric, task, and tribe routes individually. Each of these classes has a mock manager, mock objects, necessary methods for implementing those, and constants for comparing against the v1 tests.
  • Loading branch information
kjlyon committed Sep 30, 2016
1 parent cc27afd commit 2f90c2d
Show file tree
Hide file tree
Showing 8 changed files with 1,812 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 2f90c2d

Please sign in to comment.